<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: post code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Thu, 24 Jul 2008 06:30:10 GMT</pubDate>
    <description>DZone Snippets: post code</description>
    <item>
      <title>Make your own IM bot in Ruby</title>
      <link>http://snippets.dzone.com/posts/show/5710</link>
      <description>The following code was copied from the article &lt;a href="http://rubypond.com/articles/2008/06/26/make-your-own-im-bot-in-ruby-and-interface-it-with-your-rails-app"&gt;'Make your own IM bot in Ruby, and interface it with your Rails app'&lt;/a&gt; [rubypond.com].&lt;br /&gt;&lt;br /&gt;installation:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;git clone git://github.com/ln/xmpp4r.git xmpp4r&lt;br /&gt;cd xmpp4r&lt;br /&gt;rake gem:install&lt;br /&gt;sudo gem install xmpp4r-simple&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;connect:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;require 'rubygems'  &lt;br /&gt;require 'xmpp4r-simple'&lt;br /&gt;messenger = Jabber::Simple.new('my-bot@gmail.com', "bot-password")&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;send:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;messenger.deliver("a-real-person@gmail.com", "Why hello there Mr. Person, your bot is here now!") &lt;br /&gt;&lt;/code&gt;&lt;br /&gt;listen:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;while true&lt;br /&gt;  messenger.received_messages do |msg|  &lt;br /&gt;    puts msg.body  &lt;br /&gt;    messenger.deliver("a-real-person@gmail.com", "Got your message, thanks!")  &lt;br /&gt;  end  &lt;br /&gt;  sleep 2  &lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;at your service:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;require 'rubygems'  &lt;br /&gt;require 'xmpp4r-simple'&lt;br /&gt;messenger = Jabber::Simple.new('my-bot@gmail.com', "bot-password")&lt;br /&gt;while true&lt;br /&gt;  messenger.received_messages do |msg|&lt;br /&gt;    user = User.find_by_im_name(msg.from)&lt;br /&gt;    if user&lt;br /&gt;      case msg.body&lt;br /&gt;      when /^help /i&lt;br /&gt;        messenger.deliver(msg.from, "Valid commands are......")  &lt;br /&gt;      when /^status /i&lt;br /&gt;        user.status = msg.body.sub(/^status /i)&lt;br /&gt;        user.save&lt;br /&gt;        messenger.deliver(msg.from, "Thanks #{user.first_name}, your status has been updated")  &lt;br /&gt;      when /^balance\?/i&lt;br /&gt;        messenger.deliver(msg.from, "#{user.first_name}, your current remaining balance is #{user.remaining_balance}")  &lt;br /&gt;      else&lt;br /&gt;        messenger.deliver(msg.from, "Sorry #{user.first_name}, I didn't understand that. Message me with 'help' for a list of commands")  &lt;br /&gt;      end&lt;br /&gt;    else&lt;br /&gt;      messenger.deliver(msg.from, "Sorry, but we've not got this account registered on our system. Sign-up or update your details at http://www.mysite.com/")  &lt;br /&gt;    end    &lt;br /&gt;  end  &lt;br /&gt;  sleep 2  &lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sun, 29 Jun 2008 18:42:39 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5710</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
    <item>
      <title>A simple XHTML submit form for ProjectX</title>
      <link>http://snippets.dzone.com/posts/show/5354</link>
      <description>Preparing ProjectX API requests through the browser's address bar  can get quite messy, however inputting the request through a simple form makes it much easier to read.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"&lt;br /&gt;  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;&lt;br /&gt;&lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"&gt;&lt;br /&gt;  &lt;head&gt;&lt;br /&gt;    &lt;title&gt;ProjectX API&lt;/title&gt;&lt;br /&gt;    &lt;meta http-equiv="Content-Type" content="text/html;charset=utf-8"/&gt;&lt;br /&gt;  &lt;/head&gt;&lt;br /&gt;  &lt;body&gt;&lt;br /&gt;    &lt;h1&gt;ProjectX API form&lt;/h1&gt;&lt;br /&gt;    &lt;p&gt;Enter the Project API XML to send a request to the server.&lt;/p&gt;&lt;br /&gt;    &lt;form action="http://rorbuilder.info/api/projectx.cgi" method="post" id="projectx_form"&gt;&lt;br /&gt;    &lt;fieldset&gt;&lt;legend&gt;xml_project&lt;/legend&gt;&lt;textarea id="xml_project" name="xml_project" cols="104" rows="20"&gt;&lt;/textarea&gt;&lt;/fieldset&gt;&lt;br /&gt;    &lt;div&gt;&lt;button type="submit"&gt;Submit&lt;/button&gt;&lt;/div&gt;&lt;br /&gt;    &lt;/form&gt;&lt;br /&gt;  &lt;p&gt;&lt;br /&gt;    &lt;a href="http://validator.w3.org/check?uri=referer"&gt;&lt;img&lt;br /&gt;        src="http://www.w3.org/Icons/valid-xhtml10"&lt;br /&gt;        alt="Valid XHTML 1.0 Strict" height="31" width="88" style="float:right;  border:0 "/&gt;&lt;/a&gt;&lt;br /&gt;  &lt;/p&gt;&lt;br /&gt;  &lt;p style="clear:float"&gt;last updated: 13th April 2008&lt;/p&gt;&lt;br /&gt;  &lt;br /&gt;  &lt;/body&gt;&lt;br /&gt;&lt;/html&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;The web page can be seen at http://rorbuilder.info/r/projectx-api/index.html&lt;br /&gt;The following XML request value when submitted should return an XML result containing the results and the method executed.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;project name='whiteboardqueue'&gt;&lt;br /&gt;  &lt;methods&gt;&lt;br /&gt;    &lt;method name='get_user_id'&gt;&lt;br /&gt;      &lt;params/&gt;&lt;br /&gt;    &lt;/method&gt;&lt;br /&gt;  &lt;/methods&gt;&lt;br /&gt;&lt;/project&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;eg.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;result method="rtn_get_user_id"&gt;&lt;br /&gt;  &lt;get_user_id&gt;36539&lt;/get_user_id&gt;&lt;br /&gt;&lt;/result&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sun, 13 Apr 2008 22:32:48 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5354</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
    <item>
      <title>Easiest way to do a POST test from Java</title>
      <link>http://snippets.dzone.com/posts/show/5213</link>
      <description>I need to test services with POST transactions.  Using HTML to do it is the easiest way, constructed in Java (that part isn't necessary unless the args are somehow cooked or just too complex to trust hand-crafted HTML).&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;// write the HTML code out to stdout -- leave it to the user to redirect&lt;br /&gt;System.out.print( "&lt;html&gt;&lt;body&gt;&lt;form id='test' name='test' action='" );&lt;br /&gt;System.out.print( url );&lt;br /&gt;System.out.print( "/getStuff' method='POST'&gt;&lt;input type='hidden' id='cid' name='cid' value=\"" );&lt;br /&gt;System.out.print(  compId );&lt;br /&gt;System.out.print( "\"/&gt;&lt;input type='hidden' id='ids' name='ids' value=\"" );&lt;br /&gt;System.out.print( ids );&lt;br /&gt;System.out.print( "\"/&gt;" );&lt;br /&gt;System.out.print( "&lt;input type='submit' name='Submit' value='Submit'&gt;&lt;/form&gt;&lt;/body&gt;&lt;/html&gt;" );&lt;br /&gt;System.out.println();&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 12 Mar 2008 00:05:42 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5213</guid>
      <author>frost137 (Douglas Wyatt)</author>
    </item>
    <item>
      <title>'Delete a Twitter entry' dissected</title>
      <link>http://snippets.dzone.com/posts/show/5145</link>
      <description>The following code was copied from my Twitter home page, it shows how to delete a twitter entry on the server.&lt;br /&gt;&lt;br /&gt;raw HTML code with embedded JavaScript code.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="/status/destroy/719423092" onclick="if (confirm('Sure you want to delete this update? There is NO undo!')) &lt;br /&gt;{var f = document.createElement('form'); f.style.display = 'none'; this.parentNode.appendChild(f); f.method = &lt;br /&gt;'POST'; f.action = this.href;var m = document.createElement('input'); m.setAttribute('type', 'hidden'); &lt;br /&gt;m.setAttribute('name', '_method'); m.setAttribute('value', 'delete'); f.appendChild(m);var s = &lt;br /&gt;document.createElement('input'); s.setAttribute('type', 'hidden'); s.setAttribute('name', 'authenticity_token'); &lt;br /&gt;s.setAttribute('value', 'd0057265c3784d2a6dc6cdb2c26083f638152151'); f.appendChild(s);f.submit(); };return false;" &lt;br /&gt;title="Delete this update?"&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;same code as above but with comments.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;a href="/status/destroy/719423092" onclick="&lt;br /&gt;&lt;br /&gt;                     // if the user clicks the 'OK' button the confirm function will return true&lt;br /&gt;if (confirm('Sure you want to delete this update? There is NO undo!')) { &lt;br /&gt;&lt;br /&gt;  // -- dhtml: creating html elements on-the-fly -------------------------------&lt;br /&gt;  var f = document.createElement('form'); // create the dhtml 'form' (&lt;form/&gt;) element&lt;br /&gt;  f.style.display = 'none';               // hide the form&lt;br /&gt;  this.parentNode.appendChild(f);         // append the form element to the parent of the current node (&lt;a/&gt;)&lt;br /&gt;  f.method = 'POST';                      // add the method to the form&lt;br /&gt;  f.action = this.href;                   // add the action using the href of the current node (&lt;a/&gt;)&lt;br /&gt;    &lt;br /&gt;  var m = document.createElement('input');   // create the input (&lt;input/&gt;) 'element' &lt;br /&gt;  m.setAttribute('type', 'hidden');          // set the input type to 'hidden'&lt;br /&gt;  m.setAttribute('name', '_method');         // set the input name to '_method'&lt;br /&gt;  m.setAttribute('value', 'delete');         // set the input value to 'delete'&lt;br /&gt;  f.appendChild(m);                          // append the input element to the form element&lt;br /&gt;  &lt;br /&gt;  var s = document.createElement('input');   // create another input element&lt;br /&gt;  s.setAttribute('type', 'hidden');          // set the type to 'hidden'&lt;br /&gt;  s.setAttribute('name', 'authenticity_token'); // set the name to 'authenticity_token'&lt;br /&gt;  &lt;br /&gt;                                     // set the input element's value using a unique id.&lt;br /&gt;  s.setAttribute('value', 'd0057265c3784d2a6dc6cdb2c26083f638152151'); &lt;br /&gt;  &lt;br /&gt;  f.appendChild(s);                  // apend the input element to the form element&lt;br /&gt;  // -- end of dhtml: creating html elements on-the-fly -------------------------------&lt;br /&gt;  &lt;br /&gt;  f.submit(); // post the form data back to the server to delete the record, &lt;br /&gt;              // just as if the user had pressed the submit button.&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;  return false; // returning false cancels the default &lt;a href="..."&gt; request. &lt;br /&gt;                 // However if JavaScript had been disabled for some reason the &lt;br /&gt;                 // &lt;a href="..."&gt; would have acted normally, meaning the record &lt;br /&gt;                 // would have been deleted from following the URL request directly.&lt;br /&gt; "&lt;br /&gt;&lt;/code&gt; &lt;br /&gt;Note: Twitter needs JavaScript for the web page to work properly, I've tried and it is not possible to delete a record without JavaScript.  The authenticity_token has been altered by me to prevent any malicious activity on my Twitter account.&lt;br /&gt;</description>
      <pubDate>Sat, 16 Feb 2008 13:17:07 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5145</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
    <item>
      <title>PHP: Email All Form Values</title>
      <link>http://snippets.dzone.com/posts/show/4338</link>
      <description>If you need a very basic contact form and don't want to write extra code for putting the value of each field into the email, you can use this basic email. It works best if you name your form fields something legible, such as First_Name&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;if (isset($_POST['Submit'])) {&lt;br /&gt;	// Prepare message&lt;br /&gt;	$msg = "Time: " . date("m/d/y g:ia", time()) . "\n";&lt;br /&gt;	foreach ($_POST as $field=&gt;$value) {&lt;br /&gt;		if ($field != "submit") $msg .= $field . ": " . $value . "\n";&lt;br /&gt;	}&lt;br /&gt;	&lt;br /&gt;	if (mail("TOEMAIL", "SUBJECT", $msg, "From: FROM_NAME &lt;FROM@ADDRESS.com&gt;")) {&lt;br /&gt;		// Email was sent&lt;br /&gt;	} else {&lt;br /&gt;		// Erro sending email&lt;br /&gt;	}&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 19 Jul 2007 23:09:40 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4338</guid>
      <author>cornerblue (CornerBLUE, Inc.)</author>
    </item>
    <item>
      <title>PHP: Pass On Values For A Multi-Page Form</title>
      <link>http://snippets.dzone.com/posts/show/4337</link>
      <description>While the best way to do this involves saving the data into a database and passing an encrypted reference to the next page, this method will suffice for non-critical uses.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;foreach ($_POST as $field=&gt;$value) {&lt;br /&gt;	echo "&lt;input type=\"hidden\" name=\"" . $field . "\" value=\"" . $value . "\" /&gt;";&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 19 Jul 2007 23:03:48 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4337</guid>
      <author>cornerblue (CornerBLUE, Inc.)</author>
    </item>
    <item>
      <title>Encoding trouble with JQuery #1</title>
      <link>http://snippets.dzone.com/posts/show/3635</link>
      <description>// description of your code here&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;[["li01_tx_cl_c3l1_1","Salaire fixe brut mensuel hors primes : "],["li01_tx_cl_c3l1_2"," "],["li01_is_c3is1","Se calcule sur la base suivante: Salaire mensuel brut n&#233;goci&#233; divis&#233; par 1.01"],["li02_tx_cl_c3l1_1","Prime de vacances: "],["li02_tx_cl_c3l1_2"," "],["li02_is_c3is2","Correspond &#224; 1% du Salaire fixe brut mensuel hors primes"],["es_cl_c3l1","default_list"]]&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 06 Mar 2007 10:06:59 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3635</guid>
      <author>SoftExpert (Marian)</author>
    </item>
    <item>
      <title>Encoding trouble with JQuery #1</title>
      <link>http://snippets.dzone.com/posts/show/3634</link>
      <description>// description of your code here&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;[["li01_tx_cl_c3l1_1","Salaire fixe brut mensuel hors primes : "],["li01_tx_cl_c3l1_2"," "],["li01_is_c3is1","Se calcule sur la base suivante: Salaire mensuel brut n&#233;goci&#233; divis&#233; par 1.01"],["li02_tx_cl_c3l1_1","Prime de vacances: "],["li02_tx_cl_c3l1_2"," "],["li02_is_c3is2","Correspond &#224; 1% du Salaire fixe brut mensuel hors primes"],["es_cl_c3l1","default_list"]]&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 06 Mar 2007 10:06:26 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3634</guid>
      <author>SoftExpert (Marian)</author>
    </item>
    <item>
      <title>Perl - send form POST</title>
      <link>http://snippets.dzone.com/posts/show/3163</link>
      <description>// Manda le informazioni per il login ad un determinato sito&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;use HTTP::Request::Common qw(POST);&lt;br /&gt;use LWP::UserAgent;&lt;br /&gt;&lt;br /&gt;my $user = "user";&lt;br /&gt;my $pass = "pass";&lt;br /&gt;&lt;br /&gt;my $browser = LWP::UserAgent-&gt;new();&lt;br /&gt;&lt;br /&gt;my $responde = HTTP::Request-&gt;new(POST =&gt; "http://www.sito.com/index.php");&lt;br /&gt;$responde-&gt;content_type("application/x-www-form-urlencoded");&lt;br /&gt;$responde-&gt;content("user=" . $user . "&amp;pass=" . $pass);&lt;br /&gt;&lt;br /&gt;$browser-&gt;request($responde)-&gt;as_string&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 18 Dec 2006 23:57:55 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3163</guid>
      <author>whitetiger ()</author>
    </item>
    <item>
      <title>Python - Query BabelFish</title>
      <link>http://snippets.dzone.com/posts/show/2933</link>
      <description>//Example di POST HTTP&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#!/usr/bin/python&lt;br /&gt;&lt;br /&gt;import urllib&lt;br /&gt;&lt;br /&gt;def translate(lang='it_en', text='ciao'):&lt;br /&gt;	&lt;br /&gt;	'''Converte delle frasi da una lingua sorgente ad una lingua destinazione'''&lt;br /&gt;&lt;br /&gt;	url = urllib.URLopener()&lt;br /&gt;	&lt;br /&gt;	query = urllib.urlencode({'doit':'done', 'intl':'1', 'lp':lang, 'tt':'urltext', 'urltext':text})&lt;br /&gt;	&lt;br /&gt;	responde = url.open('http://babelfish.altavista.com/tr', query).read()&lt;br /&gt;&lt;br /&gt;	start = responde.find('&lt;div style=padding:10px;&gt;') + 25&lt;br /&gt;	stop = responde.find('&lt;/div&gt;', start)&lt;br /&gt;&lt;br /&gt;	print responde[start:stop]&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 31 Oct 2006 04:18:48 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2933</guid>
      <author>whitetiger ()</author>
    </item>
  </channel>
</rss>
