<?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>CodeBudo</title>
	<atom:link href="http://www.codebudo.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.codebudo.com</link>
	<description>The Way of the Software Engineer</description>
	<lastBuildDate>Thu, 17 May 2012 17:39:53 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Nodejitsu vs. Heroku for node.js Hosting</title>
		<link>http://www.codebudo.com/2012/05/nodejitsu-vs-heroku-for-node-js-hosting/</link>
		<comments>http://www.codebudo.com/2012/05/nodejitsu-vs-heroku-for-node-js-hosting/#comments</comments>
		<pubDate>Thu, 17 May 2012 17:39:53 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[cloud]]></category>
		<category><![CDATA[heroku]]></category>
		<category><![CDATA[node.js]]></category>
		<category><![CDATA[nodejitsu]]></category>

		<guid isPermaLink="false">http://www.codebudo.com/?p=149</guid>
		<description><![CDATA[I&#8217;ve been playing with Heroku for rails hosting so I started looking for similar ways to host my node.js projects. I had seen a preview of Joyent&#8217;s cloud hosting service at Node Camp a while back and found that Nodejitsu is really the modern incarnation of that service. So it seemed time to compare Heroku [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been playing with <a href="http://www.heroku.com/">Heroku</a> for rails hosting so I started looking for similar ways to host my node.js projects. I had seen a preview of Joyent&#8217;s cloud hosting service at <a href="http://camp.nodejs.org/">Node Camp</a> a while back and found that <a href="http://nodejitsu.com/">Nodejitsu</a> is really the modern incarnation of that service. So it seemed time to compare Heroku and Nodejitsu.</p>
<p>A couple weeks ago I was looking at file uploads with Node, so I had a small test app lying around that seemed perfect for a comparison test. Here&#8217;s the code on <a href="https://github.com/codebudo/node_http">GitHub</a>. The instructions I used for Heroku are <a href="https://devcenter.heroku.com/articles/nodejs">here</a>, and the steps I followed for Nodejitsu are <a href="http://nodejitsu.com/#/paas/getting-started">here</a>.</p>
<p>Generally, the process for deploying your app on either platform looks like this:<br />
1. User pushes code to cloud<br />
2. Cloud service reads package.json file<br />
3. Dependancies are managed (`npm install` step)<br />
4. Environment is set up<br />
5. App is started</p>
<p><strong>Push</strong><br />
Just like their Rails deployments, Heroku requires that you have your code commit-ed to a local repo and then you push changes to Heroku (`git push heroku master`). Nodejitsu does this slightly differently and requires that you install their &#8216;jitsu&#8217; app (`npm install jitsu -g`), but this means you don&#8217;t have to commit before deploying. At any time in your development you can just type `jitsu deploy` and expect your app to be pushed to the cloud. Jitsu also modifies your package.json with every deployment so they can do snapshotting. This is kind of annoying, but I think there&#8217;s a way to turn it off.</p>
<p><strong>package.json</strong><br />
There are slight differences in how the package.json is used on the two platforms. Nodejitsu uses the package.json in the <a href="http://npmjs.org/doc/json.html">npm standard way</a> allowing you to specify dependencies, bundledDependencies, and the start script. You can use it to select node version to run by adding an &#8216;engine&#8217; block but you can&#8217;t specify which version of npm to use, which has some importance. </p>
<p><strong>Dependencies</strong><br />
I had some trouble with dependencies on Nodejitsu. Their engine couldn&#8217;t find one of the modules in my test project. I got some really great support from #nodejitsu on IRC and one of their support engineers figured out the problem for me. It turns out the latest version of npm doesn&#8217;t like symlinks in modules so the index.js file had to be copied in place. You&#8217;ll notice in the github repo that the node_modules directory is uncharacteristically checked in. This is because I had to make this unfortunate change to the connect-form module. I happened to be running a slightly older version of npm on my dev boxes so things worked fine, but Nodejitsu is cutting edge and the workaround was necessary. This all worked fine on Heroku, so either they&#8217;re running an older version of npm like I am, or they have some other workaround.</p>
<p><strong>Environment</strong><br />
Heroku only lets your app run on one port specified in their environment. To listen to the port, you have to do something like this : &#8220;var port = process.env.PORT || 4000;&#8221;. This is probably something you should be doing anyway, but one of node.js&#8217;s greatest features is listening to several ports and piping data between them. Being limited to one port does limit the type of apps that can be deployed there. Nodejitsu lets you listen to any number of ports you like and you can happily hard-code them into your application without trouble. Also, Nodejitu has support for websockets, which is missing from Heroku and critical for me. Since most apps that use websockets with node are using more than one port as a workaround for nginx&#8217;s missing websocket support, these apps will need some minor refactoring to be done to deploy on Heroku (that is, when Heroku supports websockets). </p>
<p><strong>Startup</strong><br />
The script startup is where I like Nodejitsu a bit better. Just run `npm start` and the script will start as you expect. Heroku requires that you use the Foreman gem (`gem install foreman`) which seems out of place for node.js development. You then create a file named &#8220;Procfile&#8221; and specify your startup script there &#8220;web: node foo.js&#8221;. Unless you are doing ruby development in parallel with node.js, you may not have gem installed (and correctly configured using RVM or rbenv like you should). There&#8217;s a node version of Foreman called Forewoman that might be a better choice, but just using the standard npm &#8220;script&#8221;:{&#8220;start&#8221;:&#8221;node foo.js&#8221;} block would be my first choice.</p>
<p><strong>Overall</strong><br />
This sample app was deployed to Heroku in less than 5 minutes. I&#8217;m clearly more familiar with Heroku than I am with Nodejitsu, but it took me several hours to work through my dependency troubles on Nodejitsu and that was with professional help. Even so, I think Nodejitsu is the way to go. They are clearly dedicated to the node.js community, provided fantastic support, and offer the best features.</p>
<p><strong>Forward</strong><br />
Now, there is a new player that should be considered. RedHat&#8217;s new <a href="https://openshift.redhat.com/app/platform#open">OpenShift</a> platform is another option that deserves some further reading. The advantage of being able to run a bunch of different stacks all in one place might make it the choice for legacy apps deployed in the cloud.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codebudo.com/2012/05/nodejitsu-vs-heroku-for-node-js-hosting/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>M300</title>
		<link>http://www.codebudo.com/2011/07/m300/</link>
		<comments>http://www.codebudo.com/2011/07/m300/#comments</comments>
		<pubDate>Thu, 14 Jul 2011 19:05:51 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.codebudo.com/?p=146</guid>
		<description><![CDATA[So, the new company I&#8217;m working for just released this product called the M300. I don&#8217;t work on this team, but they&#8217;re a very smart group of people. It does some neat network scanning stuff to detect machines, and there&#8217;s an agent that lets you keep track of and install software on different assets. The [...]]]></description>
			<content:encoded><![CDATA[<p>So, the new <a href="http://www.kace.com/">company</a> I&#8217;m working for just released this product called the <a href="http://www.dell.com/us/business/p/kace-m300/pd">M300</a>.  I don&#8217;t work on this team, but they&#8217;re a very smart group of people.  It does some neat network scanning stuff to detect machines, and there&#8217;s an agent that lets you keep track of and install software on different assets.  The UI is slick, and the unit itself is quite fetching.  It doesn&#8217;t require a fan so it can sit dead silent under your desk.  Some of the smaller companies I&#8217;ve worked for could totally have used one of these.  These <a href="http://www.kace.com/products/asset-management-appliance/videos.php#video-m300-product-overview">videos</a> say it all.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codebudo.com/2011/07/m300/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Application Configuration for Node.js</title>
		<link>http://www.codebudo.com/2011/04/application-configuration-for-node-js/</link>
		<comments>http://www.codebudo.com/2011/04/application-configuration-for-node-js/#comments</comments>
		<pubDate>Wed, 27 Apr 2011 22:49:56 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[how to]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[node.js]]></category>

		<guid isPermaLink="false">http://www.codebudo.com/?p=138</guid>
		<description><![CDATA[I&#8217;ve seen a few blog posts on reading in config files to node.js apps. This can be done with an eval() (which is potentially dangerous) or by reading in a file and JSON.parse()-ing it. I wanted a solution that would work on both a node app, and could also be called as JSONP in the [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve seen a few blog posts on reading in config files to node.js apps.  This can be done with an <a href="http://bravenewmethod.wordpress.com/2010/12/13/node-js-application-configuration-files/">eval()</a> (which is potentially dangerous) or by <a href="http://blog.jteam.nl/2011/04/18/learning-node-js/">reading in a file and JSON.parse()-ing it</a>.  I wanted a solution that would work on both a node app, and could also be called as JSONP in the client portion of my app, so I added a non-destructive module block to the bottom of the config file.  If module.exports isn&#8217;t available, we assume we&#8217;re not running in node and call a &#8216;callback&#8217; function that can be handled by like JSONP.<br />
<span id="more-138"></span></p>
<pre class="qoate-code">
//config.js
conf = {
    port: 8000,
    name: 'app name',
    otherSetting: 'etc.',
};

if( typeof module !== "undefined" &#038;&#038; ('exports' in module)){
    module.exports = function(){return conf;};
} else {
    callback( conf );
}
</pre>
<p>The config file can be accessed like any other CommonJS module.</p>
<pre class="qoate-code">
//config_test.js
var configuration = require('config.js')();
console.dir( configuration );
</pre>
<p>or included as a JSONP-like call in an HTML page like this</p>
<pre class="qoate-code">
&lt;html&gt;
    &lt;head&gt;
        &lt;script type="text/javascript"&gt;
            function callback(data){
                alert(data);
            }
        &lt;/script&gt;
    &lt;/head&gt;
    &lt;body&gt;
        body text
        &lt;script src="config.js" type="text/javascript"&gt;&lt;/script&gt;
    &lt;/body&gt;
&lt;/html&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.codebudo.com/2011/04/application-configuration-for-node-js/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Screen</title>
		<link>http://www.codebudo.com/2011/03/screen/</link>
		<comments>http://www.codebudo.com/2011/03/screen/#comments</comments>
		<pubDate>Wed, 23 Mar 2011 00:10:36 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.codebudo.com/?p=134</guid>
		<description><![CDATA[If you&#8217;re not aware, screen is a fantastic way to extend the usefulness of your terminal windows. I run a screen session on my laptop and one on every machine I SSH in to frequently. I just scp this file to any host I&#8217;m going to be working with for an extended time. &#8220;How to [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re not aware, <a href="http://www.gnu.org/software/screen/">screen</a> is a fantastic way to extend the usefulness of your terminal windows.  I run a screen session on my laptop and one on every machine I SSH in to frequently.  I just scp this file to any host I&#8217;m going to be working with for an extended time.  &#8220;How to use screen&#8221; is a common enough blog post, so I&#8217;ll just skip to my .screenrc :</p>
<pre class="qoate-code">
startup_message off
term screen
defscrollback 10000
escape ^Oo
vbell off
bind h prev
bind C hardcopy
hardstatus off
bell_msg ""
shell -$SHELL
</pre>
<p><span id="more-134"></span><br />
The important parts here are &#8216;escape ^Oo&#8217; to move the command key to something on my right hand and &#8216;defscrollback 10000&#8242; so I can find things in scrolling log messages.  Moving the command key to the right hand is important to avoid the extended finger yoga generally required by frequent keyboard shortcuts.  The rest are just to remove some of the annoying bells and whistles and are well documented.</p>
<p>RANT TO ADMINS : Don&#8217;t change the default etc/screenrc!  This will annoy the hell out of anyone trying to use screen on your box.  Just because YOU like colorized numbered tab lists that flash and beep when you change windows, doesn&#8217;t mean all of your users will.  Do you know how much time it takes to disable all that junk in a ~/.screenrc? [/rant]</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codebudo.com/2011/03/screen/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Static Sites with Dynamic Content</title>
		<link>http://www.codebudo.com/2011/03/static-sites-with-dynamic-content/</link>
		<comments>http://www.codebudo.com/2011/03/static-sites-with-dynamic-content/#comments</comments>
		<pubDate>Tue, 15 Mar 2011 19:31:37 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[how to]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://www.codebudo.com/?p=126</guid>
		<description><![CDATA[In my last post, I was showing how a proxy can be used to circumvent XSS rules and said there are some interesting applications. Well, it&#8217;s time I posted one. Take a look at this very simple site (Please ignore the messy CSS, this is just a prototype) : Twitter Search This is being served [...]]]></description>
			<content:encoded><![CDATA[<p>In my last post, I was showing how a proxy can be used to circumvent XSS rules and said there are some interesting applications.  Well, it&#8217;s time I posted one.  Take a look at this very simple site (Please ignore the messy CSS, this is just a prototype) : <a href="http://www.codebudo.com:8080/twitterview/index.html">Twitter Search</a></p>
<p>This is being served statically from Nginx without writing any server-side logic.  <span id="more-126"></span>This page could come from any machine in a cluster without needing to share state, added to an HTML5 manifest, or served from a CDN.  This is the purest form of separation between data and display.  The only source of dynamic data is a single ajax call. </p>
<pre class="qoate-code">
&lt;script type="text/javascript"&gt;
    jQuery.ajax(
        "/twitter/search.json?q=%23haiku", {
        success: function(data, textStatus, jqXHR){
            twitterData = JSON.parse( jqXHR.responseText );
            $('body').append( $('#template').jqote(twitterData) );
        }
    });
&lt;/script&gt;
</pre>
<p>The important line here is the call to <a href="http://aefxx.com/jquery-plugins/jqote/">jQote</a> (pronounced like Chicote from Star Trek: Voyager).  jQote is a client side templating system in the spirit of John Resig&#8217;s now famous <a href="http://ejohn.org/blog/javascript-micro-templating/">Micro-Template</a> code.  To use it, you create a script block with type text/html:</p>
<pre class="qoate-code">
&lt;script type="text/html" id="template"&gt;
...
&lt;/script&gt;
</pre>
<p>The browser will ignore this block and not parse it as javascript.  You can add javascript code and data just like you might do with a PHP, Mason, or JSP page using <% %> and <%= %> syntax.  This lets you push CPU expensive page creation to the client and conserve your resources for API calls.</p>
<p>In this particular example, I&#8217;m pulling the content from Twitter (using a proxy to get around XSS rules), so this takes next to nothing in terms of memory and CPU.  I could improve the example further by adding a manifest file and whitelisting the /twitter/* network call.  Then only the first request would be served from my server and all subsequent requests would only make one call out of the browser.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codebudo.com/2011/03/static-sites-with-dynamic-content/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Nginx Bypassing Single-Origin Policy</title>
		<link>http://www.codebudo.com/2011/03/nginx-bypassing-single-origin-policy/</link>
		<comments>http://www.codebudo.com/2011/03/nginx-bypassing-single-origin-policy/#comments</comments>
		<pubDate>Fri, 11 Mar 2011 22:47:54 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[how to]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://www.codebudo.com/?p=119</guid>
		<description><![CDATA[Anyone building a web application knows that XmlHttpRequest can only be made to the same domain and port that the page was loaded from. This is known as the &#8216;single origin&#8217; policy for web browsers. Bypassing this restriction is known as Cross-Site Scripting or XSS. While there are some very real security reasons for only [...]]]></description>
			<content:encoded><![CDATA[<p>Anyone building a web application knows that XmlHttpRequest can only be made to the same domain and port that the page was loaded from.  This is known as the &#8216;single origin&#8217; policy for web browsers.  Bypassing this restriction is known as Cross-Site Scripting or XSS.  While there are some very real security reasons for only allowing a web page to access resources from its own domain and port, there are some really cool things that can be done when bypassing this restriction.<br />
<span id="more-119"></span>There are many client-side tricks to bypass the single origin policy: iframe name attributes, adding img tags to the DOM, even javascript compiled as PNGs (Firefox only).  </p>
<p>YQL offers a server-side proxy service, and I&#8217;ve seen some PHP proxies on the web, but if you run Nginx it&#8217;s dead simple to make your own.  I&#8217;ll use the Twitter API as an example.</p>
<p>Say you want to show twitter search results in a web page.  You could register with Twitter and get an API key, make the search, cache the results and serve them to the user.   It&#8217;s much easer to just proxy the request with Nginx like this:</p>
<pre class="qoate-code">
http {
    include       mime.types;
    default_type  application/octet-stream;
    server {
        listen       8080;
        server_name  *.codebudo.com codebudo.com;
        location /twitter {
            proxy_pass          http://search.twitter.com/;
            proxy_redirect      http://localhost:8080 http://search.twitter.com/;
        }
    }
}
</pre>
<p>This let&#8217;s us take any request to <a href="http://codebudo.com:8080/twitter/search.json?q=%23haiku">http://codebudo.com:8080/twitter/search.json?q=%23haiku</a> and have it mimic the results you&#8217;d get from <a href="http://search.twitter.com/search.json?q=%23haiku">http://search.twitter.com/search.json?q=%23haiku</a>.  So, it&#8217;s a proxy.  Not a big deal, but has some really useful applications.  </p>
]]></content:encoded>
			<wfw:commentRss>http://www.codebudo.com/2011/03/nginx-bypassing-single-origin-policy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simulating Bezier Curves with CSS</title>
		<link>http://www.codebudo.com/2010/11/simulating-bezier-curves-with-css/</link>
		<comments>http://www.codebudo.com/2010/11/simulating-bezier-curves-with-css/#comments</comments>
		<pubDate>Fri, 19 Nov 2010 06:13:28 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[how to]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[canvas]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.codebudo.com/?p=103</guid>
		<description><![CDATA[I recently had to make a visual editor that included lines between different boxes to define the &#8216;flow&#8217; of a process (think UML). Rendering something like this in a web page is sometime tricky when you want the line to look fluid between it&#8217;s two connecting points. What I wanted was something like Bezier curves. [...]]]></description>
			<content:encoded><![CDATA[<p>I recently had to make a visual editor that included lines between different boxes to define the &#8216;flow&#8217; of a process (think UML).  Rendering something like this in a web page is sometime tricky when you want the line to look fluid between it&#8217;s two connecting points.  What I wanted was something like <a href="http://en.wikipedia.org/wiki/B%C3%A9zier_curve">Bezier curves</a>.  I built a series of prototypes to figure out which one would meet the needs of this project best.  I&#8217;ll walk though my options and conclusions in the next few paragraphs, but this was the result:</p>
<p><iframe src="http://www.groket.com/sites/borders/" height="400" width="400" ></iframe><br />
Drag the boxes around to see the effect.</p>
<p><span id="more-103"></span><br />
<a href="http://pipes.yahoo.com/pipes/">Yahoo Pipes</a> uses the CANVAS tag to draw Bezier curves.  While this looks the best and can be hardware accelerated, it&#8217;s not supported by IE.  Also, in this application I would potentially have hundreds of these links and that could get quite heavy.  Canvas would also require that I write using the canvas API, which is not something many developers are acquainted with (myself included).  To avoid having a large number of tags, I could include all my content in a single canvas tag and draw everything with canvas.  But, then I have zero separation between my content and display which just didn&#8217;t seem maintainable.</p>
<p>SVG is another possible option, but has some browser compatibility issues.  I would have to implement the solution differently depending on the browser rendering the page and that was more complicated than I was hoping for.  I played around with it, but unfortunately IE&#8217;s lack of support and increased complexity killed this as an option.  I fully expect that to change in the future.</p>
<p><a href="http://code.google.com/p/jsdraw/">JSDraw</a> is a 2D drawing library that will draw hundreds of exactly positioned DIVs to draw straight lines or any mathematical function you like (Bezier included).  It&#8217;s quite easy to use and has the flexibility and gives me the separation of content and display that I want.  It&#8217;s main disadvantage is that is pollutes the DOM with hundreds of DIVs.  This could slow down page rendering if any CSS selectors have a DIV as their rightmost element (CSS selectors are evaluated from right to left).  The results aren&#8217;t bad, but when moving on a diagonal the lines become drastically aliased.</p>
<p><iframe src="http://www.groket.com/sites/jsdraw/" height="250"  width="400"></iframe></p>
<p>There&#8217;s also the <a href="http://raphaeljs.com/">Raphael</a> library that has some nice <a href="http://raphaeljs.com/graffle.html">examples</a> of drawing continuously updating lines.  The example is exactly what I want, but again this uses the canvas tag and that puts it outside my requirements.</p>
<p>This leaves the option I settled on.  It&#8217;s not perfect, but using CSS border radius I could achieve an effective simulacrum of the intended curve.  Setting the border radius larger than the width of the element using the Mozilla and Webkit extensions (and the W3C standard naming convention for Opera, and a behaviour URL used for IE support) results in a nearly circular radius.  Combining two DIVs, one for the first half the curve and another for the second half, a &#8220;double spherical&#8221; line is created.  I have no idea how to represent this mathematically, but the result is pleasing enough to the eye for my purposes.  </p>
<p>Several CSS styles are needed to accommodate the different quadrants where a line could be drawn: upper-right, upper-left, lower-left, and lower-right.  You can see the full CSS in the iframe above, but here&#8217;s an excerpt.</p>
<pre class="qoate-code">
            .bottom_right .first_half {
                border-bottom-left-radius: 1000px;
                -webkit-border-bottom-left-radius: 1000px;
                -moz-border-radius-bottomleft: 1000px;
                border-left: 2px solid green;
                border-bottom: 2px solid green;
            }
            .bottom_right .second_half {
                border-top-right-radius: 1000px;
                -webkit-border-top-right-radius: 1000px;
                -moz-border-radius-topright: 1000px;
                border-top: 2px solid green;
                border-right: 2px solid green;
                left: 50%;
                top: -2;
            }
</pre>
<p>That&#8217;s pretty much it.  With a little javascript to move a div containing these curved DIVs and to change which CSS class to use based on the difference in location between the source and destination object, the draggable DIVs can be followed by the curved lines like above.  Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codebudo.com/2010/11/simulating-bezier-curves-with-css/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mayor / Celebrity Programming Puzzle</title>
		<link>http://www.codebudo.com/2010/11/mayor-celebrity-programming-puzzle/</link>
		<comments>http://www.codebudo.com/2010/11/mayor-celebrity-programming-puzzle/#comments</comments>
		<pubDate>Wed, 10 Nov 2010 16:55:15 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[how to]]></category>

		<guid isPermaLink="false">http://www.codebudo.com/?p=90</guid>
		<description><![CDATA[Also known as the &#8220;mayor problem&#8221; or &#8220;mayor puzzle&#8221;, this is a directed graph puzzle where a group of people have single directed relationships. That is person A knows person B, but person B may or may not know person A. The puzzle is to find a person in this group that everyone knows, but [...]]]></description>
			<content:encoded><![CDATA[<p>Also known as the &#8220;mayor problem&#8221; or &#8220;mayor puzzle&#8221;, this is a directed graph puzzle where a group of people have single directed relationships.  That is person A knows person B, but person B may or may not know person A.  The puzzle is to find a person in this group that everyone knows, but he only knows himself.  To phrase it differently, this breaks down to two conditions:<br />
1) person C must be known by everyone, and<br />
2) person C must know no one but himself.</p>
<p>The obvious solution is to compare every member to every other member and that would give you a solution that runs in O(n^2).  If we&#8217;re given a function called &#8216;Knows&#8217; that accepts two arguments (and returns in O(1)), we can write a PHP function like this:<br />
<span id="more-90"></span></p>
<pre class="qoate-code">
function theSlowMayor(){
    $townSize = 5;

    $candidates = array();

    // 1) The mayor must know no one.
    for( $i=0; $i &lt; $townSize; $i++ ){
        for( $j=0; $j &lt; $townSize; $j++ ){
            if( Knows($i,$j) &#038;&#038; $i != $j )
                break;

            if( $j == $townSize - 1)
                $candidates[] = $i;
        }
    }

    // 2) Every one must know the mayor.
    foreach( $candidates as $c ){
        for( $i=0; $i&lt;$townSize; $i++ ){
            if( !Knows($i,$c) &#038;&#038; $i != $c )
                break;

            if( $i == $townSize - 1 )
                return $c;
        }
    }
}
</pre>
<p>While this may work, it's hardly ideal.  We need a way to disqualify a candidate with every iteration over the list.  This way, with one pass over the list we can remove anyone that is not the mayor / celebrity.</p>
<pre class="qoate-code">
function theMayor(){

    $townSize = 5;
    $mayor_set = array();
    for( $i=0; $i &lt; $townSize; $i++ )
        $mayor_set[] = $i;

    for( $i=0; $i &lt; count($mayor_set); $i++ ){
        for( $j=0; $j &lt; count($mayor_set); $j++ ){
            if( $i == $j )
                continue;
            if( Knows($i, $j) ) {
                // 1) The mayor must know no one.
                unset($mayor_set[$i]);
            } else {
                // 2) Every one must know the mayor.
                // if i doens't know j, then j can't be the mayor
                unset($mayor_set[$j]);
            }
        }
    }

    return array_shift($mayor_set);
}
</pre>
<p>Reading the algorithmic complexity of this code can be tricky.  Seeing a nested for loop usually means O(n^2), but in this case we are eliminating one element from the $mayor_set with every iteration so we only require one pass to find the mayor.  This does require enough memory to hold the a list of identifiers for the entire town, so this algorithm may not work on very large data sets.</p>
<p>This question comes from the <a href="http://www.amazon.com/Introduction-Algorithms-Second-Thomas-Cormen/dp/0262032937">Cormin Book</a> where 22.1-6 states:</p>
<blockquote><p>When an adjacency-matrix representation is used, most graph algorithms require time O(V^2), but there are some exceptions.  To show that determining whether a directed graph G contains a universal sink - vertex with in-degree |V|-1 and out-degree 0 - can be determined in O(V), given an adjacency matrix for G.</p></blockquote>
<p>If you want to test the functions above, you can use this sample 'Knows' function:</p>
<pre class="qoate-code">
function Knows($i, $j){
    $set = array();
    $set[] = array(1, 0, 1, 0, 1);
    $set[] = array(0, 1, 1, 1, 0);
    $set[] = array(0, 0, 1, 0, 0);
    $set[] = array(1, 1, 1, 1, 1);
    $set[] = array(0, 1, 1, 0, 1);
    return $set[$i][$j];
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.codebudo.com/2010/11/mayor-celebrity-programming-puzzle/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Applying JOONE to Real-World Data</title>
		<link>http://www.codebudo.com/2009/06/applying-joone-to-real-world-data/</link>
		<comments>http://www.codebudo.com/2009/06/applying-joone-to-real-world-data/#comments</comments>
		<pubDate>Sun, 07 Jun 2009 05:23:13 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Pattern Classification]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[machine learning]]></category>

		<guid isPermaLink="false">http://www.codebudo.com/?p=67</guid>
		<description><![CDATA[JOONE is a toolset used to build and run neural networks in Java.  To demonstrate its capability, I&#8217;ve built a simple supervised network and trained it on a common data set used for other machine learning projects.  By using a common data set, comparisons can be made between the different approaches. The data set was [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.jooneworld.com/" target="_blank">JOONE</a> is a toolset used to build and run neural networks in Java.  To demonstrate its capability, I&#8217;ve built a simple supervised network and trained it on a common data set used for other machine learning projects.  By using a common data set, comparisons can be made between the different approaches.</p>
<p>The <a href="http://archive.ics.uci.edu/ml/datasets/Mushroom" target="_blank">data set</a> was published by the Audubon Society Field Guide and describes the characteristics of mushrooms found in North America. <span id="more-67"></span> The version I&#8217;m using was compiled by the <a href="http://archive.ics.uci.edu/ml/datasets.html" target="_blank">UCI Machine Learning Repository</a>.  It contains 8124 records (one record per line) with its classification and each of the 22 mushroom characteristics represented by a character value in a comma separated list.  The first value describes the poisonous or edible classification.</p>
<blockquote><p>p,x,s,n,t,p,f,c,n,k,e,e,s,s,w,w,p,w,o,p,k,s,u<br />
e,x,s,y,t,a,f,c,b,k,e,c,s,s,w,w,p,w,o,p,n,n,g</p></blockquote>
<p>JOONE requires semicolon separated numerical values for input, so I replaced each character value with its alphabetical position and changed the commas to semicolons.  Missing values were given the value 27.</p>
<blockquote><p>16;24;19;14;20;16;6;3;14;11;5;5;19;19;23;23;16;23;15;16;11;19;21<br />
5;24;19;25;20;1;6;3;2;11;5;3;19;19;23;23;16;23;15;16;14;14;7</p></blockquote>
<p>The network has three layers: 22 input nodes, 10 hidden nodes, and a single output node.  If the output node is 16 (p), the mushroom is classified as poisonous.  If this node is 5 (e), it is classified as edible.  The hidden nodes and output node have a sigmoidal activation function.  The network is trained on the first 3000 elements of the data set using JOON&#8217;s built in back propagation functions and a Root Mean Squared Error (RMSE) function.  The remaining ~5124 nodes can be used in verifying the application.  Running in training batches of 10,000 iterations (epochs) and storing a serialized representation of the network to disk every 100 iterations allowed fine grained monitor the progress of the application and ensure net trained network could be recovered in the even of a crash.</p>
<p>Serialization is a mechanism where an object in memory is converted into a portable form (XML in this case) so it can be later retrieved and the object restored to memory exactly as it once was.  In this case, we are using the &#8216;serializeable&#8217; java interface to store a neural network that contains the network diagram, weighted synapses, and trainer (error).</p>
<p>The error after the first 100 iterations was ~5%, and decreased to 4.25% after 50,000 iterations.  While this is rather slow, the error is still decreasing and could be within acceptable levels with a few million iterations.</p>
<p>Further research should be done on the design of the network and its training.  Adding another layer or changing the number of hidden nodes could converge more quickly.  The serialization mechanism could produce an easy way to distribute and parallelize the training.  If the current RMSE of the network were stored along with serialized net, a node could determine if its error is less than the current &#8220;best&#8221; for a group of nodes.  The node with the lowest error would write a new serialized net and global error file and nodes with greater error would use the least error net to continue training.</p>
<p>Here are the files required to continue developing this network:</p>
<p><a href="/download/mushroom_numerical.data">MushroomFFNN.java</a></p>
<p><a href="/download/mushroom_numerical.data">mushroom_numerical.data</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.codebudo.com/2009/06/applying-joone-to-real-world-data/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>AvantGo is AvantGone</title>
		<link>http://www.codebudo.com/2009/06/avantgo-is-avantgone/</link>
		<comments>http://www.codebudo.com/2009/06/avantgo-is-avantgone/#comments</comments>
		<pubDate>Tue, 02 Jun 2009 21:21:40 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[advertising]]></category>
		<category><![CDATA[mobile]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://www.codebudo.com/?p=63</guid>
		<description><![CDATA[AvantGo, the once ubiquitous application for all PDAs, is shutting down its web sync service.  Users of the service have just begun to see banners stating, &#8220;Starting June 30, Avantgo will no longer offer mobile web content.&#8221; With modern wireless networks and browsers built in to new smartphones, the on device browser just couldn&#8217;t meet [...]]]></description>
			<content:encoded><![CDATA[<p>AvantGo, the once ubiquitous application for all PDAs, is shutting down its web sync service.  Users of the service have just begun to see banners stating, <strong>&#8220;Starting June 30, Avantgo will no longer offer mobile web content.&#8221;</strong> With modern wireless networks and browsers built in to new smartphones, the on device browser just couldn&#8217;t meet the demands of modern consumers.  While there are no direct competitors to this service (in the consumer market) there are a few companies that meet the needs of some consumers.  AvantGo is suggesting mysnacs.com as an alternative.  Some users have received this message:</p>
<blockquote><p>After June 30, 2009, AvantGo will no longer be providing mobile Web content for sync or online access, and you will not be able to access or update your AvantGo content or account.  Your account information will continue to be protected by our privacy policy, and we plan to delete any personally identifiable information you’ve provided (e.g., your e-mail address) as soon as reasonably possible.</p>
<p>If you are an 8MB account subscriber you may be entitled to a refund for a portion of your subscription fees that are unused. To request a refund, please click here and submit the refund request form. You will need to reference your AvantGo User ID (included in this email).</p>
<p>To continue receiving news and information from your favorite content providers, you should visit that content provider’s channel before June 30 for details on how to obtain their content other than through AvantGo.  Also, AvantGo recommends the Snac mobile widget application &#8211; a new, fun way to get your favorite content on your mobile device. You can find out more about Snac at: http://www.mysnacs.com/landing?token=avantgo0609</p>
<p>Best wishes,<br />
The AvantGo Team</p></blockquote>
<p><span id="more-63"></span></p>
<p>The original AvantGo sync service was a pioneering effort.  It brought the web to your handheld device and allowed users to take any piece of the web they wished along for the ride.  Web applications were supported with an offline form submission system and advanced javascript hooks allowed mobile web developers to interact with their users in a useful way while they were offline.  The &#8220;HandheldFriendly&#8221; meta tag was originally developed by AvantGo to differentiate websites designed for desktop or mobile view and is now used by many browsers including Opera Mini, Opera Mobile and some BlackBerry devices.</p>
<p>AvantGo taught its approximately 10 million recorded users what to expect of the mobile web and defined a market for the mobile device browsers followed.  Aspects of the service&#8217;s design are sure to remain in the mobile computing field.  Many former AvantGo engineers went on to help develop Yahoo! Go, Google Gears, and other mobile content services.</p>
<p>If HTML 5 ever gets adopted, most of the offline browsing features will be available on a large number of browsers.  Safari 4 beta already supports the site manifest file aspects of HTML 5 for pre-downloading content (a feature that has caused some controversy over wasted bandwidth) which allows offline view of pages.</p>
<p>According to parent company Sybase, AvantGo will transition from a mobile web service, to an <a href="AvantGo Mobile Advertising Services" target="_blank">SMS advertising</a> and content delivery system.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codebudo.com/2009/06/avantgo-is-avantgone/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

