<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Tommy Chheng &#187; tommy</title>
	<atom:link href="http://tommy.chheng.com/index.php/author/tommy/feed/" rel="self" type="application/rss+xml" />
	<link>http://tommy.chheng.com</link>
	<description>All Things Programming!</description>
	<lastBuildDate>Sat, 24 Jul 2010 17:34:27 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Call a JRuby method from Java</title>
		<link>http://tommy.chheng.com/index.php/2010/06/call-a-jruby-method-from-java/</link>
		<comments>http://tommy.chheng.com/index.php/2010/06/call-a-jruby-method-from-java/#comments</comments>
		<pubDate>Sun, 20 Jun 2010 19:26:23 +0000</pubDate>
		<dc:creator>tommy</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[jruby]]></category>

		<guid isPermaLink="false">http://tommy.chheng.com/?p=315</guid>
		<description><![CDATA[JRuby is a great way of reducing verbose Java code. Here&#8217;s a way of implementing a Java interface in JRuby and calling the method from Java. Java Interface We&#8217;ll start with a simple Java interface: interface JavaInterfaceExample{ int add(int a, int b); } Compile it using javac JavaInterfaceExample.java Implement the Java Interface in JRuby We [...]]]></description>
			<content:encoded><![CDATA[<p>JRuby is a great way of reducing verbose Java code. Here&#8217;s a way of implementing a Java interface in JRuby and calling the method from Java.</p>
<h3>Java Interface</h3>
<p>We&#8217;ll start with a simple Java interface:</p>
<pre>
<code>
interface JavaInterfaceExample{
  int add(int a, int b);
}
</code>
</pre>
<p>Compile it using<br />
<code><br />
javac JavaInterfaceExample.java<br />
</code></p>
<h3>Implement the Java Interface in JRuby</h3>
<p>We will implement this method in JRuby. When importing interfaces from Java code, you should use the Java namespace as in include Java::JavaInterfaceExample. The signature is important since JRuby is dynamically typed. If it isn&#8217;t specified, the parameters will be a Java Object.</p>
<pre>
<code>
require 'java'
class JrubyAdderImpl
  include Java::JavaInterfaceExample
  java_signature 'int add(int, int)'
	def add(a, b)
		a+b
	end
end
</code>
</pre>
<p>Compile it using:<br />
<code><br />
jrubyc --javac -cp . JrubyAdderImpl.rb<br />
</code></p>
<h3>Creating a Java class calling a JRuby method</h3>
<p>Then let&#8217;s create a Java class which calls the jruby method:</p>
<pre>
<code>
class JavaCallerApp {
    public static void main(String[] args) {
	    JrubyAdderImpl jrubyImpl = new JrubyAdderImpl();
	    System.out.println("Adding 3+5=" + jrubyImpl.add(3,5)); // Display the string.
    }
}
</code>
</pre>
<p>Compile it:<br />
<code><br />
javac -cp /usr/local/jruby/lib/jruby.jar:. JavaCallerApp.java<br />
</code></p>
<p>and run it:<br />
<code><br />
java -cp /usr/local/jruby/lib/jruby.jar:. JavaCallerApp<br />
</code></p>
<p>Output:<br />
<code><br />
Adding 3+5=8<br />
</code></p>
<h3>Downside</h3>
<p>While this works, it&#8217;s not a very optimally solution for calling JRuby code from Java. When you compiled JrubyAdderImpl.rb, it created a JrubyAdderImpl.java file which runs a JRuby runtime layer against the JRuby script file. I imagine this isn&#8217;t very performant. </p>
<p>I recommend using <a href="http://kenai.com/projects/duby">Duby</a> or <a href="http://www.scala-lang.org/">Scala</a> as alternative JVM languages for greater interoperability with Java.</p>
<p>I placed the code on a <a href="http://github.com/tc/call-jruby-from-java-example">github repo</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://tommy.chheng.com/index.php/2010/06/call-a-jruby-method-from-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Android And iPhone Development Thoughts</title>
		<link>http://tommy.chheng.com/index.php/2010/05/android-and-iphone-development-thoughts/</link>
		<comments>http://tommy.chheng.com/index.php/2010/05/android-and-iphone-development-thoughts/#comments</comments>
		<pubDate>Mon, 03 May 2010 15:18:43 +0000</pubDate>
		<dc:creator>tommy</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[iphone]]></category>

		<guid isPermaLink="false">http://tommy.chheng.com/?p=292</guid>
		<description><![CDATA[I recently received a Motorola Droid from Google for signing up for Google IO 2010. Unfortunately not the incredible, but the droid is actually a nice phone. The screen is really sharp. The physically keyboard lets you type faster. It&#8217;s a little too early to say, but I might keep this phone over my iPhone [...]]]></description>
			<content:encoded><![CDATA[<p>I recently received a Motorola Droid from Google for signing up for <a href="http://code.google.com/events/io/2010/">Google IO 2010</a>. Unfortunately not the incredible, but the droid is actually a nice phone. The screen is really sharp. The physically keyboard lets you type faster. It&#8217;s a little too early to say, but I might keep this phone over my iPhone 3g. Anyhow, I thought Android will become more common in devices other than phones, why not make a quick app to learn a useful skill? Since I have previous iPhone development experiment, I&#8217;ll give a brief comparison of different areas i prefer in developing native iPhone and Android apps.</p>
<p><img src="http://upload.wikimedia.org/wikipedia/en/thumb/3/32/Motorola-milestone-wikipedia.jpg/200px-Motorola-milestone-wikipedia.jpg"/><img src="http://upload.wikimedia.org/wikipedia/en/thumb/8/88/IPhone_3GS_with_home_screen.png/150px-IPhone_3GS_with_home_screen.png" /></p>
<h3>Apps</h3>
<p>I created two native iPhone apps(<a href="http://yummylaser.com/voodoodoll">voodoo doll</a> and <a href="http://yummylaser.com/tweetshow">tweet show</a>) with a few friends a year ago. Both are free and relatively simple. TweetShow actually hit the &#8220;Featured&#8221; page when it was named &#8220;TwitterTime.&#8221; It lets you watch tweets hands-free(ie. if you are eating).</p>
<p>For Android development, i used the Android 2.1 sdk with Eclipse. Android lets you use any IDE or even develop in the console as all of the build tools are command line-based. I made a useful Android app called Pastedroid which allows you to copy a piece of text(address, phone number, etc) to your phone. With the Pastedroid app installed, users go to pastedroid.com or use the javascript bookmarklet, copy text there and it&#8217;ll appear in the pastedroid Android app. It&#8217;s more similar to <a href="http://pastefire.com">pastefire</a> on the iPhone rather than tapbot&#8217;s awesome and more full featured paste helper, <a href="http://tapbots.com/pastebot">Pastebot</a>. </p>
<h2>Development Comparison</h2>
<h3>UI: iPhone</h3>
<p>iPhone&#8217;s built-in UI makes it really easy to make an app good looking and consistent. Android on the other hand makes it really easy to make a horrible looking app. The iPhone interface builder even lets you drag/drop elements whereas the Android doesn&#8217;t.<br />
Android Eclipse has a strange interface builder. It&#8217;s easier to edit the XML directly but making it look nice is difficult. Editing Android UI feels like the pre-css HTML days where table tags ruled. </p>
<h3>UI Interaction: Android</h3>
<p>To connect a ui button to your code, it&#8217;s a multi-step process in the iPhone sdk.<br />
In the interface builder, click and drag an outlet to its file owner.<br />
Then in the header file, define the outlet:<br />
<code><br />
@property (nonatomic, retain) IBOutlet UISearchBar* tweetSearchBar;<br />
</code><br />
Then in the code file, i can use the object.</p>
<p>Developing interactions is easier on Android. Just name the button in the UI xml file and you can access it in the code using:<br />
<code><br />
refreshButton = (ImageButton) findViewById(R.id.refreshButton);<br />
</code><br />
To make an event call a method, just set the method handler in the XML UI file.</p>
<h3>Documentation: iPhone</h3>
<p>I tend to learn by examples and it was definitely an easier time to find iPhone help and code examples. For Android code samples, beware of which version the help/code examples are targeted for. Not sure how true this is, but it felt the iPhone API changes were more stable than Android over the different versions.</p>
<h3>Publishing: Android</h3>
<p>Wow. I cannot believe how easy it is to publish an app on Android compared to iPhone. It literally took 5 minutes to get an app signed and published on the Android. I remember the first time I published an iPhone app, it took at least 5 hours of debugging various problems in the signing and build configuration. </p>
]]></content:encoded>
			<wfw:commentRss>http://tommy.chheng.com/index.php/2010/05/android-and-iphone-development-thoughts/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Partial functions in Scala</title>
		<link>http://tommy.chheng.com/index.php/2010/04/partial-functions-in-scala/</link>
		<comments>http://tommy.chheng.com/index.php/2010/04/partial-functions-in-scala/#comments</comments>
		<pubDate>Fri, 23 Apr 2010 18:29:25 +0000</pubDate>
		<dc:creator>tommy</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Scala]]></category>

		<guid isPermaLink="false">http://tommy.chheng.com/?p=279</guid>
		<description><![CDATA[I ran into a problem where i wanted to get a formatted string for each tuple in a list but ended on a detour to learning about partial functions. Consider this simple case: scala&#62; val wordCount = List(("a",1),("b",2)) wordCount: List[(java.lang.String, Int)] = List((a,1), (b,2)) I can just use ._1 and ._2 on each tuple but [...]]]></description>
			<content:encoded><![CDATA[<p>I ran into a problem where i wanted to get a formatted string for each tuple in a list but ended on a detour to learning about partial functions. Consider this simple case:<br />
<code><br />
scala&gt; val wordCount = List(("a",1),("b",2))<br />
wordCount: List[(java.lang.String, Int)] = List((a,1), (b,2))<br />
</code></p>
<p>I can just use ._1 and ._2 on each tuple but it isn&#8217;t very readable. If someone else is reading the code, will they know what ._1 is for?<br />
<code><br />
scala&gt; wordCount.map(wc =&gt; wc._1+":"+wc._2)<br />
res4: List[java.lang.String] = List(a:1, b:2)<br />
</code><br />
We can use case classes to the rescue:<br />
<code><br />
scala&gt; wordCount.map(case(word,count) =&gt; word+":"+count)<br />
:1: error: illegal start of simple expression<br />
wordCount.map(case(word,count) =&gt; word+":"+count)<br />
^<br />
</code><br />
Opps, as dpp mentioned on the scala mailing list, case is a partial function so this syntax won&#8217;t work.</p>
<h3>What is a partial function you ask?</h3>
<p>Partial functions allow you to specify a subset of the parameters in a function. Imagine this trivial case where you have an add function.<br />
<code><br />
scala&gt; def add(t1:Int,t2:Int) = t1+t2<br />
add: (t1: Int,t2: Int)Int<br />
</code><br />
You can create a partial function addByOne which will have one parameter bounded and another unbounded.<br />
<code><br />
scala&gt; val addByOne = add(1,_:Int)<br />
addByOne: (Int) =&gt; Int =&lt;function1&gt;<br />
</code></p>
<p>Then you can evaluate addByOne by specifying the unbounded parameter:<br />
<code><br />
scala&gt; addByOne(10)<br />
res5: Int = 11<br />
</code></p>
<h3>case: a Partial Function</h3>
<p>Back to our original example why calling map with parentheses doesn&#8217;t work.<br />
case is a partial function which will only be called if the isDefinedAt method is true. If it was a Function, it would throw a MatchError when no case matches are found.</p>
<p><code><br />
scala&gt; val myPartial:PartialFunction[Any,String]= {case(word,count) =&gt; word+":"+count}<br />
myPartial: PartialFunction[Any,String] = &lt;function1&gt;<br />
</code></p>
<p>We can apply the partial function to each tuple explicitly:<br />
<code><br />
scala&gt; wordCount.map(x =&gt; myPartial(x))<br />
res14: List[String] = List(a:1, b:2)<br />
</code><br />
or with the implied argument:<br />
<code><br />
scala&gt; wordCount.map(myPartial)<br />
res15: List[String] = List(a:1, b:2)<br />
</code><br />
We can also pass the partial function as an anonymous function(or closure):<br />
<code><br />
scala&gt; wordCount.map({case(word,count) =&gt; word+":"+count})<br />
res16: List[java.lang.String] = List(a:1, b:2)<br />
</code><br />
and remove the the extra parentheses:<br />
<code><br />
scala&gt; wordCount.map {case(word,count) =&gt; word+":"+count}<br />
res17: List[java.lang.String] = List(a:1, b:2)<br />
</code><br />
Thanks to dpp for bringing partial functions to my attention.</p>
]]></content:encoded>
			<wfw:commentRss>http://tommy.chheng.com/index.php/2010/04/partial-functions-in-scala/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>A Better Search Engine for Research Grants</title>
		<link>http://tommy.chheng.com/index.php/2010/04/a-better-search-forresearch-grants/</link>
		<comments>http://tommy.chheng.com/index.php/2010/04/a-better-search-forresearch-grants/#comments</comments>
		<pubDate>Sat, 10 Apr 2010 17:24:26 +0000</pubDate>
		<dc:creator>tommy</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://tommy.chheng.com/?p=271</guid>
		<description><![CDATA[I have been working ResearchWatch, a search engine for US federal research grants. It&#8217;s ideal for scientists, researchers and government officials who need to know where research trends/money are being invested. You can perform queries like: Grants at University of Washington involving solar: You&#8217;ll get a a break down of the grants per year, awarded [...]]]></description>
			<content:encoded><![CDATA[<p>I have been working ResearchWatch, a <a href="http://researchwatch.net">search engine for US federal research grants</a>. It&#8217;s ideal for scientists, researchers and government officials who need to know where research trends/money are being invested.</p>
<p>You can perform queries like:</p>
<li><a href="http://researchwatch.net/find?q=solar+university+of+washington&#038;facet_tag=on">Grants at University of Washington involving solar</a>: You&#8217;ll get a a break down of the grants per year, awarded amount and investigators.</li>
<li><a href="http://researchwatch.net/find?q=fuel+cell+university+of+california&#038;facet_tag=on">Grants at all University of California involving fuel cell</a></li>
<div id="attachment_274" class="wp-caption alignnone" style="width: 495px"><a href="http://researchwatch.net"><img src="http://tommy.chheng.com/wp-content/uploads/2010/04/science_research_grants.png" alt="" title="science_research_grants" width="485" height="601" class="size-full wp-image-274" /></a><p class="wp-caption-text">science research grants</p></div>
<p>It&#8217;s still a rough prototype right now. It only has the NSF grants but I think even the current incarnation is doing a better job than the <a href="http://www.research.gov/rgov/anonymous.portal?_nfpb=true&#038;_pageLabel=page_research_funding_search&#038;_nfls=false">&#8216;official site.&#8217;</a></p>
<p>ResearchWatch provides faceted search interface and content aggregation. The content aggregation can quickly tell you the distribution of funds and location. </p>
<p>I&#8217;ll be using it to implement some search ideas, mainly query segmentation and entity recognition. Let me know if you have any suggestions to improve the system!</p>
]]></content:encoded>
			<wfw:commentRss>http://tommy.chheng.com/index.php/2010/04/a-better-search-forresearch-grants/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>When to call methods with or without parentheses () in Scala</title>
		<link>http://tommy.chheng.com/index.php/2010/03/when-to-call-methods-with-or-without-parentheses-in-scala/</link>
		<comments>http://tommy.chheng.com/index.php/2010/03/when-to-call-methods-with-or-without-parentheses-in-scala/#comments</comments>
		<pubDate>Sat, 13 Mar 2010 22:22:28 +0000</pubDate>
		<dc:creator>tommy</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Scala]]></category>

		<guid isPermaLink="false">http://tommy.chheng.com/?p=262</guid>
		<description><![CDATA[I ran into this method call quirk in Scala: If the method has no parameters, you must call it without the parentheses unless the method declaration was defined with empty parentheses. If you are new to Scala, you&#8217;ll probably see this manifest when using iterators. scala> val wordListIter = wordList.iterator() :9: error: wordList.iterator of type [...]]]></description>
			<content:encoded><![CDATA[<p>I ran into this method call quirk in Scala:</p>
<blockquote><p>If the method has no parameters, you must call it without the parentheses <em>unless</em> the method declaration was defined with empty parentheses.</p></blockquote>
<p>If you are new to Scala, you&#8217;ll probably see this manifest when using iterators.<br />
<code><br />
scala>     val wordListIter = wordList.iterator()<br />
<console>:9: error: wordList.iterator of type Iterator[(java.lang.String, java.lang.String)] does not take parameters<br />
scala>     val wordListIter = wordList.iterator<br />
wordListIter: Iterator[(java.lang.String, java.lang.String)] = non-empty iterator<br />
scala> val lines= Source.fromPath(filename).getLines<br />
<console>:6: error: missing arguments for method getLines in class Source;<br />
follow this method with `_' if you want to treat it as a partially applied function<br />
Error occured in an application involving default arguments.<br />
       val lines= Source.fromPath(filename).getLines<br />
scala> val lines= Source.fromPath(filename).getLines()<br />
lines: Iterator[String] = non-empty iterator<br />
</code><br />
 It would have been helpful if the empty parens are listed for the <a href="http://www.scala-lang.org/docu/files/api/scala/io/Source.html#getLines">getLines scalaDocs</a> </p>
<p>The convention ensures the uniform access principle. This convention is unlike languages like Ruby where you can call parameter-less methods with or without parentheses. </p>
<p>This except from page 212 of  <a href="http://www.amazon.com/gp/product/0981531601?ie=UTF8&#038;tag=tomchhsblo-20&#038;linkCode=as2&#038;camp=1789&#038;creative=390957&#038;creativeASIN=0981531601">Programming in Scala</a><img src="http://www.assoc-amazon.com/e/ir?t=tomchhsblo-20&#038;l=as2&#038;o=1&#038;a=0981531601" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /> explains the rationale: </p>
<p>instead of:<br />
<code>def width(): Int</code><br />
the method is defined without parentheses:<br />
<code>def width: Int</code></p>
<blockquote><p>Such parameterless methods are quite common in Scala. By contrast, methods defined with empty parentheses, such as def height(): Int, are called empty-paren methods. The recommended convention is to use a parameterless method whenever there are no parameters and the method accesses mutable state only by reading fields of the containing object (in particular, it does not change mutable state). This convention supports the uniform access principle which says that client code should not be affected by a decision to implement an attribute as a field or method.</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://tommy.chheng.com/index.php/2010/03/when-to-call-methods-with-or-without-parentheses-in-scala/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Processing in Scala!</title>
		<link>http://tommy.chheng.com/index.php/2010/03/processing-in-scala/</link>
		<comments>http://tommy.chheng.com/index.php/2010/03/processing-in-scala/#comments</comments>
		<pubDate>Sun, 07 Mar 2010 18:28:40 +0000</pubDate>
		<dc:creator>tommy</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[processing]]></category>
		<category><![CDATA[Scala]]></category>

		<guid isPermaLink="false">http://tommy.chheng.com/?p=248</guid>
		<description><![CDATA[One of the great things about scala is that it inter-operate with any existing Java library. Both ways, use scala classes from java and java from scala. Here&#8217;s an quick example of using Processing in Scala. I&#8217;m using IntelliJ IDEA 9.0.1 with the Scala plugin. To get Processing working in IntelliJ: Download the processing.org jars [...]]]></description>
			<content:encoded><![CDATA[<p>One of the great things about scala is that it inter-operate with any existing Java library. Both ways, use scala classes from java and java from scala.  Here&#8217;s an quick example of using Processing in Scala. </p>
<p><a href="http://tommy.chheng.com/wp-content/uploads/2010/03/processing-in-scala1.png"><img src="http://tommy.chheng.com/wp-content/uploads/2010/03/processing-in-scala1.png" alt="" title="processing in scala" width="686" height="561" class="alignnone size-full wp-image-252" /></a></p>
<p>I&#8217;m using IntelliJ IDEA 9.0.1 with the Scala plugin.<br />
To get Processing working in IntelliJ:</p>
<ol>
<li>Download the <a href="http://processing.org">processing.org</a> jars</li>
<li>Create a Scala project.</li>
<li>Add them to your libraries list in the modules setting.</li>
<li>Create a new scala object example below.</li>
</ol>
<p>How is this useful? Scala&#8217;s syntax and its core data structures allow processing of data in a much more concise and understandable manner. Imagine you want to visualize xml or csv files with the Processing/Scala combo. Scala makes this easy with its xml and string manipulation libraries.</p>
<p> This example code is from Ben Fry&#8217;s <a href="http://www.amazon.com/gp/product/0596514557?ie=UTF8&#038;tag=tomchhsblo-20&#038;linkCode=as2&#038;camp=1789&#038;creative=9325&#038;creativeASIN=0596514557">Visualizing Data Book</a><img src="http://www.assoc-amazon.com/e/ir?t=tomchhsblo-20&#038;l=as2&#038;o=1&#038;a=0596514557" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /></p>
<p><code></p>
<pre>
import processing.core._
object Draw extends processing.core.PApplet {

  override def setup() {
    size(200, 200)
    noStroke( )
    fill(0, 102, 153, 204)
  }

  override def draw() {
    background(255)
    rect(width-mouseX, height-mouseY, 50, 50)
    rect(mouseX, mouseY, 50, 50)
  }

  def main(args: Array[String]) {
    val frame = new javax.swing.JFrame("Draw")
    frame.getContentPane().add(Draw)
    Draw.init

    frame.pack
    frame.setVisible(true)
  }
}
</pre>
<p></code></p>
]]></content:encoded>
			<wfw:commentRss>http://tommy.chheng.com/index.php/2010/03/processing-in-scala/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to make a Javascript Bookmarklet</title>
		<link>http://tommy.chheng.com/index.php/2010/03/javascript-bookmarklet/</link>
		<comments>http://tommy.chheng.com/index.php/2010/03/javascript-bookmarklet/#comments</comments>
		<pubDate>Mon, 01 Mar 2010 23:22:23 +0000</pubDate>
		<dc:creator>tommy</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://tommy.chheng.com/?p=240</guid>
		<description><![CDATA[There&#8217;s a niffy trick in browsers that you you execute Javascript code in the url location bar. (This is how a lot of security holes are created too!) Try typing the below into your browser url bar: javascript:alert('look how cool this is') Cool, it runs javascript! You may have noticed a lot of websites take [...]]]></description>
			<content:encoded><![CDATA[<p>There&#8217;s a niffy trick in browsers that you you execute Javascript code in the url location bar. (This is how a lot of security holes are created too!)<br />
Try typing the below into your browser url bar:<br />
<code><br />
javascript:alert('look how cool this is')<br />
</code><br />
Cool, it runs javascript!</p>
<p>You may have noticed a lot of websites take advantage of this to enhance a service. Instapaper&#8217;s &#8220;Read Later&#8221; saves the current page and Pastefire&#8217;s &#8220;Pastefire this&#8221; saves the selected text.</p>
<p>To make your own, just write javascript inside a link tag as a one liner.  Then just ask users to click and drag the link to the bookmark toolbar.<br />
<img src="http://tommy.chheng.com/wp-content/uploads/2010/03/sprocketit_bookmarklet.png" alt="" title="sprocketit_bookmarklet" width="418" height="85" class="alignnone size-full wp-image-243" /></p>
<p>Here&#8217;s an example for my Next Sprocket site which will start you on a new open source task with the title and description partially filled out:<br />
<a href="javascript:(function(){location.href='http://nextsprocket.com/tasks/new?task[title]='+encodeURIComponent(document.title)+'&amp;task[description]=More details at '+encodeURIComponent(window.location.href)})()">Sprocket it!</a></p>
<p><code><br />
&lt;a href="javascript:(function(){location.href='http://nextsprocket.com/tasks/new?task[title]='+encodeURIComponent(document.title)+'&amp;task[description]=More details at '+encodeURIComponent(window.location.href)})()"&gt;Sprocket it!&lt;/a&gt;<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://tommy.chheng.com/index.php/2010/03/javascript-bookmarklet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Gettext On Rails 3.0.0.beta: first open source task accomplished via Next Sprocket!</title>
		<link>http://tommy.chheng.com/index.php/2010/03/gettext-on-rails-3-0-0-beta-first-open-source-task-accomplished-via-next-sprocket/</link>
		<comments>http://tommy.chheng.com/index.php/2010/03/gettext-on-rails-3-0-0-beta-first-open-source-task-accomplished-via-next-sprocket/#comments</comments>
		<pubDate>Mon, 01 Mar 2010 17:01:42 +0000</pubDate>
		<dc:creator>tommy</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[gettext]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://tommy.chheng.com/?p=236</guid>
		<description><![CDATA[Great to wake up on Monday morning to see that someone has accepted and paid for the first open source task on our website Next Sprocket! Very happy to see our concept working. The task was for making gettext rails 3.0 compatibility and providing a sample Rails 3.0 app. Check out the solution here. If [...]]]></description>
			<content:encoded><![CDATA[<p>Great to wake up on Monday morning to see that someone has accepted and paid for the first open source task on our website Next Sprocket! Very happy to see our concept working.</p>
<p>The task was for making gettext rails 3.0 compatibility and providing a sample Rails 3.0 app. <a href="http://nextsprocket.com/tasks/gettext-on-rails-3-0-0-beta">Check out the solution here</a>.</p>
<p>If you have a gem that you need upgraded or any open source problem, please post the task on <a href="http://nextsprocket.com">Next Sprocket</a>. Someone will get it done and it will be an open source benefit.</p>
]]></content:encoded>
			<wfw:commentRss>http://tommy.chheng.com/index.php/2010/03/gettext-on-rails-3-0-0-beta-first-open-source-task-accomplished-via-next-sprocket/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MongoDB For Natural Development</title>
		<link>http://tommy.chheng.com/index.php/2010/02/mongodb-for-natural-development/</link>
		<comments>http://tommy.chheng.com/index.php/2010/02/mongodb-for-natural-development/#comments</comments>
		<pubDate>Fri, 26 Feb 2010 17:41:50 +0000</pubDate>
		<dc:creator>tommy</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[mongodb]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://tommy.chheng.com/?p=229</guid>
		<description><![CDATA[Here&#8217;s the slides from a talk about MongoDB at the feb OC Ruby meetup. MongoDB For Natural Development There were a few examples from Tim Morgan&#8217;s presentation at the LaRubyConf2010 that resonated how ActiveRecord can be a source of many headaches. I wager this is because the ActiveRecord ORM adds complexity to mapping from ruby [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s the slides from a talk about MongoDB at the feb <a href="http://ocruby.com">OC Ruby meetup</a>. </p>
<p><a title="View MongoDB For Natural Development on Scribd" href="http://www.scribd.com/doc/27488895/MongoDB-For-Natural-Development" style="margin: 12px auto 6px auto; font-family: Helvetica,Arial,Sans-serif; font-style: normal; font-variant: normal; font-weight: normal; font-size: 14px; line-height: normal; font-size-adjust: none; font-stretch: normal; -x-system-font: none; display: block; text-decoration: underline;">MongoDB For Natural Development</a> <object id="doc_866619320309658" name="doc_866619320309658" height="600" width="100%" type="application/x-shockwave-flash" data="http://d1.scribdassets.com/ScribdViewer.swf" style="outline:none;" ><param name="movie" value="http://d1.scribdassets.com/ScribdViewer.swf"><param name="wmode" value="opaque"><param name="bgcolor" value="#ffffff"><param name="allowFullScreen" value="true"><param name="allowScriptAccess" value="always"><param name="FlashVars" value="document_id=27488895&#038;access_key=key-2e44oc8mh1x18iiuxdfk&#038;page=1&#038;viewMode=slideshow"><embed id="doc_866619320309658" name="doc_866619320309658" src="http://d1.scribdassets.com/ScribdViewer.swf?document_id=27488895&#038;access_key=key-2e44oc8mh1x18iiuxdfk&#038;page=1&#038;viewMode=slideshow" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" height="600" width="100%" wmode="opaque" bgcolor="#ffffff"></embed></object></p>
<p>There were a few examples from <a href="http://www.scribd.com/doc/27168812/Oh-Shit-How-to-Break-a-Large-Website-and-how-not-to-PDF-version">Tim Morgan&#8217;s presentation</a> at the LaRubyConf2010 that resonated how ActiveRecord can be a source of many headaches.  I wager this is because the ActiveRecord ORM adds complexity to mapping from ruby objects to SQL world. The mapping isn&#8217;t one to one and complexity is the unfortunate byproduct. </p>
<p>On the other hand, MongoDB&#8217;s data modeling naturally maps to today&#8217;s popular programming languages.  Essentially, most data are hashes(or associative arrays/dictionaries) and hashes are the basic data model for MongoDB. By having such a similar data representation, the ORM complexity level is extremely minimal compared to a typical ORM designed for SQL.</p>
<p>So use MongoDB because it can reduce the amount of complexity and bugs in your system.</p>
]]></content:encoded>
			<wfw:commentRss>http://tommy.chheng.com/index.php/2010/02/mongodb-for-natural-development/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Next Sprocket: The Open Source Developer&#8217;s Marketplace</title>
		<link>http://tommy.chheng.com/index.php/2010/02/next-sprocket-the-open-source-developers-marketplace/</link>
		<comments>http://tommy.chheng.com/index.php/2010/02/next-sprocket-the-open-source-developers-marketplace/#comments</comments>
		<pubDate>Thu, 25 Feb 2010 01:54:25 +0000</pubDate>
		<dc:creator>tommy</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[open source]]></category>

		<guid isPermaLink="false">http://tommy.chheng.com/?p=218</guid>
		<description><![CDATA[As a developer, I have come to appreciate how useful open source technologies is for me and everyone. Occasionally I come across a problem in an open source project that I can&#8217;t fix myself but willing to contribute some money to have it fixed. I am positive many other developers would too. So I started [...]]]></description>
			<content:encoded><![CDATA[<p>As a developer, I have come to appreciate how useful open source technologies is for me and everyone.  Occasionally I come across a problem in an open source project that I can&#8217;t fix myself but willing to contribute some money to have it fixed. I am positive many other developers would too.</p>
<p><a href="http://nextsprocket.com"><img src="http://tommy.chheng.com/wp-content/uploads/2010/02/ns.png" alt="" title="ns" width="555" height="345" class="alignnone size-full wp-image-225" /></a></p>
<p>So I started <a href="http://nextsprocket.com">Next Sprocket</a> with my buddy Nitin. Next Sprocket is the Open Source Developer&#8217;s Marketplace.</p>
<p>The basic idea is for any developer to post a task for a reward, let others contribute to the money pot and allow other developers to solve the problem. All the transactions are done via Paypal&#8217;s Adaptive Payments API.</p>
<p>You can help by <a href="http://nextsprocket.com/tasks/new">posting a task</a> up or you can vote for us in the <a href="https://www.x.com/community/ppx/devchallenge/lp">Paypal Developer Challenge</a>. The PayPal Developer Challenge voting ends on March 5. The top 10 will be judged by the likes of Marc Andreessen, Scott Cook and many others for the winner. </p>
]]></content:encoded>
			<wfw:commentRss>http://tommy.chheng.com/index.php/2010/02/next-sprocket-the-open-source-developers-marketplace/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
