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

Olle Jonsson http://blog.olle.ter.dk

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

Add multiple models to the Rails app

// Add several models -- isn't this already done in script/generate model?

for newmodel in foo bar quux ook blort fnort
do 
	script/generate model $newmodel
done

Simple XML-RPC in Ruby

Example lifted from the standard library docs. Illustrative!

#!c:\ruby\bin\ruby.exe
require 'xmlrpc/client'
require 'pp'

server = XMLRPC::Client.new2("http://rpc.technorati.com/rpc/ping")
result = server.call("weblogUpdates.ping", "Copenhagen.rb", "http://www.copenhagenrb.dk/")
pp result

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;

Remove all .svn folders in a directory tree

// You did a checkout when you really wanted to do an export.
// Now there are tons of .svn folders in your project, and you need them to go away.
// Shell scripting to the rescue.

// Credit: Zed Shaw, at the Mongrel mailing list.

find . -name ".svn" -exec rm -rf {} \;
« Newer Snippets
Older Snippets »
Showing 1-4 of 4 total  RSS