Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Andrea Fiore http://pzwart2.wdka.hro.nl/~afiore

« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS 

snippets.sh

//How to post code snippets from the command line (contributes are welcome!)
   1  
   2  #(CC) Andrea Fiore,
   3  # Creative Commons, by Attribution Share Alike 2.0
   4  # http://creativecommons.org/licenses/by-sa/2.0/
   5  # and<AT>inventati.org 
   6  
   7  #debug:
   8  #set -x
   9  
  10  #todo: 1.Add a proper password field
  11  #      2.Add options: description, tag lists, snippet name as options 
  12  #      3.improve options..
  13  #      4.Add funky ansi colors
  14  
  15  function help () {
  16  	echo "Usage: "`basename $0`" -u <username> [-P, -D ]";
  17  }
  18  while getopts "u:p:PdhH" opt;
  19  do
  20    case $opt in
  21    u ) user=$OPTARG;;
  22    p ) pass=$OPTARG ;;
  23    P ) private=1;;
  24    'h' | 'H' ) help ;;
  25    * ) help ;;
  26    esac
  27  done
  28  
  29  shift $(($OPTIND-1))
  30  
  31  if [ -z $1 ]
  32  then echo -e "What I am supposed to upload?\n missing filename... exiting"; exit 1 
  33  fi
  34  if [ -z $user ]
  35  then 
  36      echo -e "How am I supposed to log-in without your user name?\n";help
  37      exit 1
  38  fi
  39  if [ -z $pass ]
  40      then read -p "password: " pass
  41      #how can I have a proper password field?
  42  fi
  43  if [ -z $1 ] 
  44     then echo "Missing file to upload; exiting";exit 1
  45  fi
  46  if [ -z $private ];then private=1 
  47  fi
  48  
  49  # get the autentication cookie and put it in the /tmp dir
  50  curl -v -D /tmp/header -F "username=$user" -F "password=$pass" -l "http://www.bigbold.com/snippets/account/login" &> /dev/null
  51  #grab the userid
  52  userid=$(curl -b /tmp/header -l http://www.bigbold.com/snippets/ 2> /dev/null |grep -Eo 'post\[user_id\]\" value\=\"[0-9]{1,9}"' | sed -r 's/post\[user_id\]" value="([0-9]{1,9})"/\1/')
  53  
  54  if [ $? = 1 ]
  55  	then echo -e "autentication failture, or unable to get userid!\n Exiting"; exit 1
  56  fi
  57  #snip_cont=$(cat $1 | urlencode) 
  58  read -p "snippet title: " snip_title
  59  read -p "description: " snip_desc
  60  read -p "tags:" tags
  61  
  62  snip='//'${snip_desc}'code'`cat $1`'/code'#WARNIG: Code tags here are escaped... 
  63  #echo -e $content
  64  curl -b /tmp/header.txt -F "post[id]= " -F "post[user_id]=$userid" -F "post[title]=$snip_title" -F "post[content]=$snip" -F "post[tag_list]=$tags" -F "post[private]=1" http://www.bigbold.com/snippets/posts/create/ &> /dev/null
  65  #log-out
  66  curl -b /tmp/header "http://www.bigbold.com/snippets/logout" &> /dev/null

nopaste.sh: post to http://rafb.net/paste/ from the commandline

// shell based post to source code pasting utility http://rafb.net/paste/

   1  
   2  #! /bin/sh
   3  #
   4  # nopaste.sh, 
   5  # 
   6  # Andrea Fiore, and(at)inventati.org
   7  
   8  # Creative Commons, by Attribution, Share Alike
   9  # http://creativecommons.org/licenses/by-sa/2.0/
  10  #
  11  # shell interface to http://rafb.net/paste/
  12  # this suppose you have python and curl installed 
  13  #
  14  
  15  function help () {
  16     echo "Usage: nopaste.sh [-n nikname] [-d description] file "
  17  }
  18  
  19  nick="${USER}@${HOSTNAME}"
  20  desc=""
  21  
  22  while getopts "n:d:" opt;
  23  do
  24   case $opt in 
  25   n ) nick=$OPTARG;;
  26   d ) desc=$OPTARG;;
  27   : ) echo "Missing argument for option \"$OPTARG\".";;
  28  \? ) help ;; 
  29    esac
  30  done
  31  
  32  shift $(($OPTIND-1))
  33  if [ -z "$1" ]; then echo "Missing filename argument!"
  34     else 
  35         txt=`urlencode $1`
  36         pastedtxt=`curl -d "lang=Plain%20Text&nick=$nick&desc=$desc&text=$txt&tabs=no" -L http://rafb.net/paste/paste.php 2> /dev/null|egrep -o  -e '\/results\/.*\.html'`
  37         echo "http://rafb.net/paste$pastedtxt"
  38         
  39         fi
  40  
  41  //end nopaste.sh
  42  
  43  //simple python urlencode..
  44  
  45  #! /usr/bin/env python
  46  # -*- coding: iso-8859-15 -*-
  47  import sys, urllib
  48  try:
  49      f=open(sys.argv[1],'r')
  50      txt=urllib.urlencode({'t':f.read()})
  51      f.close()
  52      print txt[2:]
  53  except:
  54      print "no such file..."
  55  

« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS