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

« Newer Snippets
Older Snippets »
Showing 11-14 of 14 total

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

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

#! /bin/sh
#
# nopaste.sh, 
# 
# Andrea Fiore, and(at)inventati.org

# Creative Commons, by Attribution, Share Alike
# http://creativecommons.org/licenses/by-sa/2.0/
#
# shell interface to http://rafb.net/paste/
# this suppose you have python and curl installed 
#

function help () {
   echo "Usage: nopaste.sh [-n nikname] [-d description] file "
}

nick="${USER}@${HOSTNAME}"
desc=""

while getopts "n:d:" opt;
do
 case $opt in 
 n ) nick=$OPTARG;;
 d ) desc=$OPTARG;;
 : ) echo "Missing argument for option \"$OPTARG\".";;
\? ) help ;; 
  esac
done

shift $(($OPTIND-1))
if [ -z "$1" ]; then echo "Missing filename argument!"
   else 
       txt=`urlencode $1`
       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'`
       echo "http://rafb.net/paste$pastedtxt"
       
       fi

//end nopaste.sh

//simple python urlencode..

#! /usr/bin/env python
# -*- coding: iso-8859-15 -*-
import sys, urllib
try:
    f=open(sys.argv[1],'r')
    txt=urllib.urlencode({'t':f.read()})
    f.close()
    print txt[2:]
except:
    print "no such file..."


Simple XML-RPC in PHP (using cURL)

Ping Technorati using cURL and XMLRPC extensions.

# Using the XML-RPC extension to format the XML package
$request = xmlrpc_encode_request("weblogUpdates.ping", array("Copenhagen Ruby Brigade", "http://copenhagenrb.dk/") );

# Using the cURL extension to send it off, 
# first creating a custom header block
$header[] = "Host: rpc.technorati.com";
$header[] = "Content-type: text/xml";
$header[] = "Content-length: ".strlen($request) . "\r\n";
$header[] = $request;

$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, "http://rpc.technorati.com/rpc/ping"); # URL to post to
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 ); # return into a variable
curl_setopt( $ch, CURLOPT_HTTPHEADER, $header ); # custom headers, see above
curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, 'POST' ); # This POST is special, and uses its specified Content-type
$result = curl_exec( $ch ); # run!
curl_close($ch); 

echo $result;

View returned HTTP header on a request

curl -I http://www.google.com/

Post XML using curl

You can use curl on the command line to do a POST to an endpoint.

echo '<doc><item>Some content.</item></doc>' | curl -X POST -H 'Content-type: text/xml' -d @- http://example.com/restapi


This is handy for adding web services to applications that do not do web services but can do command lines--FileMaker for example.
« Newer Snippets
Older Snippets »
Showing 11-14 of 14 total