<?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>outlaw love song</title>
	<atom:link href="http://blog.johncrepezzi.com/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.johncrepezzi.com</link>
	<description>john crepezzi: developer (NYC)</description>
	<lastBuildDate>Fri, 18 Jun 2010 23:55:56 +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>EasyTranslate v0.1.1</title>
		<link>http://blog.johncrepezzi.com/archives/154</link>
		<comments>http://blog.johncrepezzi.com/archives/154#comments</comments>
		<pubDate>Fri, 18 Jun 2010 23:13:08 +0000</pubDate>
		<dc:creator>john</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[translate]]></category>

		<guid isPermaLink="false">http://blog.johncrepezzi.com/?p=154</guid>
		<description><![CDATA[The project has existed for a little bit, but now I think most of the kinks are ironed out, and its ready for use. EasyTranslate is a Ruby binding for the Google translate/detect APIs (http://code.google.com/apis/ajaxlanguage/). Its different than other libraries that do the same for a few reasons: Only Ruby binding to have support for [...]]]></description>
			<content:encoded><![CDATA[<p>The project has existed for a little bit, but now I think most of the kinks are ironed out, and its ready for use.  </p>
<p>EasyTranslate is a Ruby binding for the Google translate/detect APIs (<a href="http://code.google.com/apis/ajaxlanguage/">http://code.google.com/apis/ajaxlanguage/</a>).  Its different than other libraries that do the same for a few reasons:</p>
<ul>
<li>Only Ruby binding to have support for Bulk Translations</li>
<li>Only Ruby binding to offer POST support for long translations</li>
<li>Supports every option in the API, especially API keys and user_ip, which most Ruby bindings skip over.</li>
<li>Has an extremely clean syntax</li>
</ul>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># woah, really?</span>
EasyTranslate.<span style="color:#9900CC;">translate</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'Hello, world'</span>, <span style="color:#ff3333; font-weight:bold;">:to</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:spanish</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#008000; font-style:italic;"># =&gt; &quot;Hola, mundo&quot;</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># what about batch translation? =&gt; [&quot;¡Hola&quot;, &quot;Despedida&quot;]</span>
EasyTranslate.<span style="color:#9900CC;">translate</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'Hello'</span>, <span style="color:#996600;">'Goodbye'</span><span style="color:#006600; font-weight:bold;">&#93;</span>, <span style="color:#ff3333; font-weight:bold;">:to</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:spanish</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># what if you're even crazier? =&gt; [['¡Hola', 'Despedida'], ['Ciao', 'Addio']]</span>
EasyTranslate.<span style="color:#9900CC;">translate</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'Hello'</span>, <span style="color:#996600;">'Goodbye'</span><span style="color:#006600; font-weight:bold;">&#93;</span>, <span style="color:#ff3333; font-weight:bold;">:to</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:es</span>, <span style="color:#ff3333; font-weight:bold;">:it</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># translate something into every language in Google Translate</span>
<span style="color:#008000; font-style:italic;"># WITH A SINGLE CALL TO THE API</span>
EasyTranslate.<span style="color:#9900CC;">translate</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'hello'</span>, <span style="color:#ff3333; font-weight:bold;">:to</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> EasyTranslate.<span style="color:#9900CC;">LANGUAGES</span>.<span style="color:#9900CC;">keys</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></td></tr></table></div>

<p>The whole thing is licensed under the <a href="http://en.wikipedia.org/wiki/MIT_License">MIT License</a>, so get out there, make something cool, and let me know how it turns out!</p>
<p><strong>to install:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ gem <span style="color: #c20cb9; font-weight: bold;">install</span> easy_translate</pre></div></div>

<p><a href="http://github.com/seejohnrun/easy_translate">http://github.com/seejohnrun/easy_translate</a></p>




	<a rel="nofollow"  href="mailto:?subject=EasyTranslate%20v0.1.1&amp;body=http%3A%2F%2Fblog.johncrepezzi.com%2Farchives%2F154" title="email"><img src="http://blog.johncrepezzi.com/wp-content/plugins/sociable/images/email_link.png" title="email" alt="email" /></a>
	<a rel="nofollow"  href="http://delicious.com/post?url=http%3A%2F%2Fblog.johncrepezzi.com%2Farchives%2F154&amp;title=EasyTranslate%20v0.1.1&amp;notes=The%20project%20has%20existed%20for%20a%20little%20bit%2C%20but%20now%20I%20think%20most%20of%20the%20kinks%20are%20ironed%20out%2C%20and%20its%20ready%20for%20use.%20%20%0A%0AEasyTranslate%20is%20a%20Ruby%20binding%20for%20the%20Google%20translate%2Fdetect%20APIs%20%28http%3A%2F%2Fcode.google.com%2Fapis%2Fajaxlanguage%2F%29.%20%20Its%20different%20tha" title="del.icio.us"><img src="http://blog.johncrepezzi.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" /></a>
	<a rel="nofollow"  href="http://www.facebook.com/share.php?u=http%3A%2F%2Fblog.johncrepezzi.com%2Farchives%2F154&amp;t=EasyTranslate%20v0.1.1" title="Facebook"><img src="http://blog.johncrepezzi.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" /></a>
	<a rel="nofollow"  href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fblog.johncrepezzi.com%2Farchives%2F154&amp;title=EasyTranslate%20v0.1.1&amp;bodytext=The%20project%20has%20existed%20for%20a%20little%20bit%2C%20but%20now%20I%20think%20most%20of%20the%20kinks%20are%20ironed%20out%2C%20and%20its%20ready%20for%20use.%20%20%0A%0AEasyTranslate%20is%20a%20Ruby%20binding%20for%20the%20Google%20translate%2Fdetect%20APIs%20%28http%3A%2F%2Fcode.google.com%2Fapis%2Fajaxlanguage%2F%29.%20%20Its%20different%20tha" title="Digg"><img src="http://blog.johncrepezzi.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" /></a>
	<a rel="nofollow"  href="http://twitter.com/home?status=EasyTranslate%20v0.1.1%20-%20http%3A%2F%2Fblog.johncrepezzi.com%2Farchives%2F154%20(via%20%40seejohnrun)" title="Twitter"><img src="http://blog.johncrepezzi.com/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" /></a>
	<a rel="nofollow"  href="http://www.friendfeed.com/share?title=EasyTranslate%20v0.1.1&amp;link=http%3A%2F%2Fblog.johncrepezzi.com%2Farchives%2F154" title="FriendFeed"><img src="http://blog.johncrepezzi.com/wp-content/plugins/sociable/images/friendfeed.png" title="FriendFeed" alt="FriendFeed" /></a>
	<a rel="nofollow"  href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fblog.johncrepezzi.com%2Farchives%2F154&amp;title=EasyTranslate%20v0.1.1&amp;annotation=The%20project%20has%20existed%20for%20a%20little%20bit%2C%20but%20now%20I%20think%20most%20of%20the%20kinks%20are%20ironed%20out%2C%20and%20its%20ready%20for%20use.%20%20%0A%0AEasyTranslate%20is%20a%20Ruby%20binding%20for%20the%20Google%20translate%2Fdetect%20APIs%20%28http%3A%2F%2Fcode.google.com%2Fapis%2Fajaxlanguage%2F%29.%20%20Its%20different%20tha" title="Google Bookmarks"><img src="http://blog.johncrepezzi.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://blog.johncrepezzi.com/archives/154/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>rake + rspec + gemcutter</title>
		<link>http://blog.johncrepezzi.com/archives/146</link>
		<comments>http://blog.johncrepezzi.com/archives/146#comments</comments>
		<pubDate>Thu, 17 Jun 2010 18:33:50 +0000</pubDate>
		<dc:creator>john</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[conventions]]></category>
		<category><![CDATA[rake]]></category>
		<category><![CDATA[rspec]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://blog.johncrepezzi.com/?p=146</guid>
		<description><![CDATA[Today I&#8217;m going to talk about how I release new versions of ice_cube. I&#8217;ve set up a rake task called &#8216;release&#8217;, which makes sure that all of my tests pass before deploying tagging and pushing to RubyGems. I got the basis of the idea from a yehuda katz blog post. 1 2 3 4 5 [...]]]></description>
			<content:encoded><![CDATA[<p>Today I&#8217;m going to talk about how I release new versions of <a href="http://github.com/seejohnrun/ice_cube">ice_cube</a>.  I&#8217;ve set up a rake task called &#8216;release&#8217;, which makes sure that all of my tests pass before deploying tagging and pushing to RubyGems.  I got the basis of the idea from a <a href="http://yehudakatz.com/2010/04/02/using-gemspecs-as-intended/">yehuda katz blog post</a>.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'spec/rake/spectask'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'lib/ice_cube/version'</span>
&nbsp;
task <span style="color:#ff3333; font-weight:bold;">:build</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:test</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  <span style="color:#CC0066; font-weight:bold;">system</span> <span style="color:#996600;">&quot;gem build ice_cube.gemspec&quot;</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
task <span style="color:#ff3333; font-weight:bold;">:release</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:build</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  <span style="color:#008000; font-style:italic;"># tag and push</span>
  <span style="color:#CC0066; font-weight:bold;">system</span> <span style="color:#996600;">&quot;git tag v#{IceCube::VERSION}&quot;</span>
  <span style="color:#CC0066; font-weight:bold;">system</span> <span style="color:#996600;">&quot;git push origin --tags&quot;</span>
  <span style="color:#008000; font-style:italic;"># push the gem</span>
  <span style="color:#CC0066; font-weight:bold;">system</span> <span style="color:#996600;">&quot;gem push ice_cube-#{IceCube::VERSION}.gem&quot;</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#6666ff; font-weight:bold;">Spec::Rake::SpecTask</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:test</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>t<span style="color:#006600; font-weight:bold;">|</span>
  t.<span style="color:#9900CC;">spec_files</span> = FileList<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'spec/**/*_spec.rb'</span><span style="color:#006600; font-weight:bold;">&#93;</span>
  fail_on_error = <span style="color:#0000FF; font-weight:bold;">true</span> <span style="color:#008000; font-style:italic;"># be explicit</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>Then you can just update the version.rb file:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">module</span> IceCube
  VERSION = <span style="color:#996600;">&quot;0.3.9&quot;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>and type:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ rake release</pre></div></div>

<p>Voila!  Using this simple release method (thanks to rake and rspec), will make sure you don&#8217;t accidentally push broken versions ever (again).</p>




	<a rel="nofollow"  href="mailto:?subject=rake%20%2B%20rspec%20%2B%20gemcutter&amp;body=http%3A%2F%2Fblog.johncrepezzi.com%2Farchives%2F146" title="email"><img src="http://blog.johncrepezzi.com/wp-content/plugins/sociable/images/email_link.png" title="email" alt="email" /></a>
	<a rel="nofollow"  href="http://delicious.com/post?url=http%3A%2F%2Fblog.johncrepezzi.com%2Farchives%2F146&amp;title=rake%20%2B%20rspec%20%2B%20gemcutter&amp;notes=Today%20I%27m%20going%20to%20talk%20about%20how%20I%20release%20new%20versions%20of%20ice_cube.%20%20I%27ve%20set%20up%20a%20rake%20task%20called%20%27release%27%2C%20which%20makes%20sure%20that%20all%20of%20my%20tests%20pass%20before%20deploying%20tagging%20and%20pushing%20to%20RubyGems.%20%20I%20got%20the%20basis%20of%20the%20idea%20from%20a%20yehuda%20k" title="del.icio.us"><img src="http://blog.johncrepezzi.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" /></a>
	<a rel="nofollow"  href="http://www.facebook.com/share.php?u=http%3A%2F%2Fblog.johncrepezzi.com%2Farchives%2F146&amp;t=rake%20%2B%20rspec%20%2B%20gemcutter" title="Facebook"><img src="http://blog.johncrepezzi.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" /></a>
	<a rel="nofollow"  href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fblog.johncrepezzi.com%2Farchives%2F146&amp;title=rake%20%2B%20rspec%20%2B%20gemcutter&amp;bodytext=Today%20I%27m%20going%20to%20talk%20about%20how%20I%20release%20new%20versions%20of%20ice_cube.%20%20I%27ve%20set%20up%20a%20rake%20task%20called%20%27release%27%2C%20which%20makes%20sure%20that%20all%20of%20my%20tests%20pass%20before%20deploying%20tagging%20and%20pushing%20to%20RubyGems.%20%20I%20got%20the%20basis%20of%20the%20idea%20from%20a%20yehuda%20k" title="Digg"><img src="http://blog.johncrepezzi.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" /></a>
	<a rel="nofollow"  href="http://twitter.com/home?status=rake%20%2B%20rspec%20%2B%20gemcutter%20-%20http%3A%2F%2Fblog.johncrepezzi.com%2Farchives%2F146%20(via%20%40seejohnrun)" title="Twitter"><img src="http://blog.johncrepezzi.com/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" /></a>
	<a rel="nofollow"  href="http://www.friendfeed.com/share?title=rake%20%2B%20rspec%20%2B%20gemcutter&amp;link=http%3A%2F%2Fblog.johncrepezzi.com%2Farchives%2F146" title="FriendFeed"><img src="http://blog.johncrepezzi.com/wp-content/plugins/sociable/images/friendfeed.png" title="FriendFeed" alt="FriendFeed" /></a>
	<a rel="nofollow"  href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fblog.johncrepezzi.com%2Farchives%2F146&amp;title=rake%20%2B%20rspec%20%2B%20gemcutter&amp;annotation=Today%20I%27m%20going%20to%20talk%20about%20how%20I%20release%20new%20versions%20of%20ice_cube.%20%20I%27ve%20set%20up%20a%20rake%20task%20called%20%27release%27%2C%20which%20makes%20sure%20that%20all%20of%20my%20tests%20pass%20before%20deploying%20tagging%20and%20pushing%20to%20RubyGems.%20%20I%20got%20the%20basis%20of%20the%20idea%20from%20a%20yehuda%20k" title="Google Bookmarks"><img src="http://blog.johncrepezzi.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://blog.johncrepezzi.com/archives/146/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Quick, local short_urls </title>
		<link>http://blog.johncrepezzi.com/archives/125</link>
		<comments>http://blog.johncrepezzi.com/archives/125#comments</comments>
		<pubDate>Thu, 22 Apr 2010 17:14:16 +0000</pubDate>
		<dc:creator>john</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[short_url]]></category>

		<guid isPermaLink="false">http://blog.johncrepezzi.com/?p=125</guid>
		<description><![CDATA[Cross-posted from http://engineering.patch.com/quick-local-shorturls On patch.com, we generate short_urls for our editors to use on services like Twitter. The benefit of generating the short URL internally is three-fold: We get to maintain the Patch branding We don&#8217;t have to rely on an external shortening service We can be in control of how our links are created [...]]]></description>
			<content:encoded><![CDATA[<p><b>Cross-posted from <a href="http://engineering.patch.com/quick-local-shorturls">http://engineering.patch.com/quick-local-shorturls</a></b></p>
<hr />
<p>On patch.com, we generate short_urls for our editors to use on services like Twitter.  The benefit of generating the short URL internally is three-fold:</p>
<ol>
<li>We get to maintain the Patch branding</li>
<li>We don&#8217;t have to rely on an external shortening service</li>
<li>We can be in control of how our links are created</li>
</ol>
<p>The last one is really fun, because it means that we can cleverly name our short_urls in a way that they don&#8217;t need to make an extra request to the database for lookup.  So, instead of a user requesting <a href="http://patch.com/bE582" rel="nofollow">http://patch.com/bE582</a>, and us looking up in a table what page that references, we can created a short URL like: <a href="http://patch.com/L-dbrB" rel="nofollow">http://patch.com/L-dbrB</a> and serve the user Listing 281923.</p>
<p>Its really simple, as is the code to support it:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># John Crepezzi  April 22, 2010  </span>
<span style="color:#9966CC; font-weight:bold;">class</span> ShortId  
&nbsp;
  <span style="color:#008000; font-style:italic;"># We cut out vowels to avoid shortened strings from mistakenly </span>
  <span style="color:#008000; font-style:italic;"># forming words  </span>
  Alphabet = <span style="color:#996600;">'bcdfghjklmnpqrstvwxyz0123456789BCDFGHJKLMNPQRSTVWXYZ'</span>  
  AlphabetLength = Alphabet.<span style="color:#9900CC;">length</span>  
&nbsp;
  <span style="color:#008000; font-style:italic;"># Encode a numeric ID  </span>
  <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">encode</span><span style="color:#006600; font-weight:bold;">&#40;</span>id<span style="color:#006600; font-weight:bold;">&#41;</span>  
    alpha = <span style="color:#996600;">''</span>  
    <span style="color:#9966CC; font-weight:bold;">while</span> id != <span style="color:#006666;">0</span>  
      alpha = Alphabet<span style="color:#006600; font-weight:bold;">&#91;</span>id <span style="color:#006600; font-weight:bold;">%</span> AlphabetLength<span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">chr</span> <span style="color:#006600; font-weight:bold;">+</span> alpha  
      id <span style="color:#006600; font-weight:bold;">/</span>= AlphabetLength  
    <span style="color:#9966CC; font-weight:bold;">end</span>  
    alpha  
  <span style="color:#9966CC; font-weight:bold;">end</span>  
&nbsp;
  <span style="color:#008000; font-style:italic;"># Decode an ID created with self.encode  </span>
  <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">decode</span><span style="color:#006600; font-weight:bold;">&#40;</span>alpha<span style="color:#006600; font-weight:bold;">&#41;</span>  
    alpha = alpha.<span style="color:#9900CC;">dup</span>; id = <span style="color:#006666;">0</span>  
    0.<span style="color:#9900CC;">upto</span><span style="color:#006600; font-weight:bold;">&#40;</span>alpha.<span style="color:#9900CC;">length</span> <span style="color:#006600; font-weight:bold;">-</span> <span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>i<span style="color:#006600; font-weight:bold;">|</span>  
      id <span style="color:#006600; font-weight:bold;">+</span>= Alphabet.<span style="color:#9900CC;">index</span><span style="color:#006600; font-weight:bold;">&#40;</span>alpha<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">*</span> <span style="color:#006600; font-weight:bold;">&#40;</span>AlphabetLength <span style="color:#006600; font-weight:bold;">**</span> i<span style="color:#006600; font-weight:bold;">&#41;</span>  
      alpha.<span style="color:#CC0066; font-weight:bold;">chop!</span>  
    <span style="color:#9966CC; font-weight:bold;">end</span>  
    id  
  <span style="color:#9966CC; font-weight:bold;">end</span>  
&nbsp;
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>Enjoy!</p>




	<a rel="nofollow"  href="mailto:?subject=Quick%2C%20local%20short_urls%20%3CPatch%3E&amp;body=http%3A%2F%2Fblog.johncrepezzi.com%2Farchives%2F125" title="email"><img src="http://blog.johncrepezzi.com/wp-content/plugins/sociable/images/email_link.png" title="email" alt="email" /></a>
	<a rel="nofollow"  href="http://delicious.com/post?url=http%3A%2F%2Fblog.johncrepezzi.com%2Farchives%2F125&amp;title=Quick%2C%20local%20short_urls%20%3CPatch%3E&amp;notes=Cross-posted%20from%20http%3A%2F%2Fengineering.patch.com%2Fquick-local-shorturls%0A%0A%0A%0AOn%20patch.com%2C%20we%20generate%20short_urls%20for%20our%20editors%20to%20use%20on%20services%20like%20Twitter.%20%20The%20benefit%20of%20generating%20the%20short%20URL%20internally%20is%20three-fold%3A%0A%0AWe%20get%20to%20maintain%20the%20P" title="del.icio.us"><img src="http://blog.johncrepezzi.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" /></a>
	<a rel="nofollow"  href="http://www.facebook.com/share.php?u=http%3A%2F%2Fblog.johncrepezzi.com%2Farchives%2F125&amp;t=Quick%2C%20local%20short_urls%20%3CPatch%3E" title="Facebook"><img src="http://blog.johncrepezzi.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" /></a>
	<a rel="nofollow"  href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fblog.johncrepezzi.com%2Farchives%2F125&amp;title=Quick%2C%20local%20short_urls%20%3CPatch%3E&amp;bodytext=Cross-posted%20from%20http%3A%2F%2Fengineering.patch.com%2Fquick-local-shorturls%0A%0A%0A%0AOn%20patch.com%2C%20we%20generate%20short_urls%20for%20our%20editors%20to%20use%20on%20services%20like%20Twitter.%20%20The%20benefit%20of%20generating%20the%20short%20URL%20internally%20is%20three-fold%3A%0A%0AWe%20get%20to%20maintain%20the%20P" title="Digg"><img src="http://blog.johncrepezzi.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" /></a>
	<a rel="nofollow"  href="http://twitter.com/home?status=Quick%2C%20local%20short_urls%20%3CPatch%3E%20-%20http%3A%2F%2Fblog.johncrepezzi.com%2Farchives%2F125%20(via%20%40seejohnrun)" title="Twitter"><img src="http://blog.johncrepezzi.com/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" /></a>
	<a rel="nofollow"  href="http://www.friendfeed.com/share?title=Quick%2C%20local%20short_urls%20%3CPatch%3E&amp;link=http%3A%2F%2Fblog.johncrepezzi.com%2Farchives%2F125" title="FriendFeed"><img src="http://blog.johncrepezzi.com/wp-content/plugins/sociable/images/friendfeed.png" title="FriendFeed" alt="FriendFeed" /></a>
	<a rel="nofollow"  href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fblog.johncrepezzi.com%2Farchives%2F125&amp;title=Quick%2C%20local%20short_urls%20%3CPatch%3E&amp;annotation=Cross-posted%20from%20http%3A%2F%2Fengineering.patch.com%2Fquick-local-shorturls%0A%0A%0A%0AOn%20patch.com%2C%20we%20generate%20short_urls%20for%20our%20editors%20to%20use%20on%20services%20like%20Twitter.%20%20The%20benefit%20of%20generating%20the%20short%20URL%20internally%20is%20three-fold%3A%0A%0AWe%20get%20to%20maintain%20the%20P" title="Google Bookmarks"><img src="http://blog.johncrepezzi.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://blog.johncrepezzi.com/archives/125/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Pretty Damn Fancy &#8211; Java PDF Cracker</title>
		<link>http://blog.johncrepezzi.com/archives/118</link>
		<comments>http://blog.johncrepezzi.com/archives/118#comments</comments>
		<pubDate>Sat, 13 Feb 2010 18:37:32 +0000</pubDate>
		<dc:creator>john</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.johncrepezzi.com/?p=118</guid>
		<description><![CDATA[I had to open a PDF, so I spent the morning working on a basic PDF password cracker written in Java. I haven&#8217;t encapsulated it in a command line tool yet (and I&#8217;m not sure I ever will), but it came out pretty neat. It started out simple enough: 1 2 3 4 5 6 [...]]]></description>
			<content:encoded><![CDATA[<p>I had to open a PDF, so I spent the morning working on a basic PDF password cracker written in Java.  I haven&#8217;t encapsulated it in a command line tool yet (and I&#8217;m not sure <strong>I</strong> ever will), but it came out pretty neat.</p>
<p>It started out simple enough:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">boolean</span> attempt<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> password<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">//attempt to open the reader stream</span>
        PdfReader reader <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> PdfReader<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">filename</span>, password.<span style="color: #006633;">getBytes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        reader.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>BadPasswordException e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>After I had the password, I couldn&#8217;t resist the urge to implement:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">boolean</span> attempt<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> password<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003399;">String</span> crackViaWordlistFiles<span style="color: #009900;">&#40;</span><span style="color: #003399;">Collection</span> wordlistFiles<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003399;">String</span> crackViaWordlistFile<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> wordlistFile<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003399;">String</span> crackViaWordlist<span style="color: #009900;">&#40;</span><span style="color: #003399;">Collection</span> words<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003399;">String</span> crackViaBruteForce<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> alphabet, <span style="color: #000066; font-weight: bold;">int</span> length<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003399;">String</span> crackViaBruteForce<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> alphabet, <span style="color: #000066; font-weight: bold;">int</span> lower_length, <span style="color: #000066; font-weight: bold;">int</span> upper_length<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>The coolest of which, was the code for generating the brute force permutations of @length</p>
<p>Hopefully someone finds a use for this, and if not, finds a use for my brute force algorithm.  Thanks!</p>
<p><span style="color: #ff0000;">Update:</span> This project has been moved to github, expanded, and unit tested.  <a href="http://github.com/seejohnrun/Pretty-Damn-Fancy">http://github.com/seejohnrun/Pretty-Damn-Fancy</a></p>




	<a rel="nofollow"  href="mailto:?subject=Pretty%20Damn%20Fancy%20-%20Java%20PDF%20Cracker&amp;body=http%3A%2F%2Fblog.johncrepezzi.com%2Farchives%2F118" title="email"><img src="http://blog.johncrepezzi.com/wp-content/plugins/sociable/images/email_link.png" title="email" alt="email" /></a>
	<a rel="nofollow"  href="http://delicious.com/post?url=http%3A%2F%2Fblog.johncrepezzi.com%2Farchives%2F118&amp;title=Pretty%20Damn%20Fancy%20-%20Java%20PDF%20Cracker&amp;notes=I%20had%20to%20open%20a%20PDF%2C%20so%20I%20spent%20the%20morning%20working%20on%20a%20basic%20PDF%20password%20cracker%20written%20in%20Java.%20%20I%20haven%27t%20encapsulated%20it%20in%20a%20command%20line%20tool%20yet%20%28and%20I%27m%20not%20sure%20I%20ever%20will%29%2C%20but%20it%20came%20out%20pretty%20neat.%0A%0AIt%20started%20out%20simple%20enough%3A%0Aboo" title="del.icio.us"><img src="http://blog.johncrepezzi.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" /></a>
	<a rel="nofollow"  href="http://www.facebook.com/share.php?u=http%3A%2F%2Fblog.johncrepezzi.com%2Farchives%2F118&amp;t=Pretty%20Damn%20Fancy%20-%20Java%20PDF%20Cracker" title="Facebook"><img src="http://blog.johncrepezzi.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" /></a>
	<a rel="nofollow"  href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fblog.johncrepezzi.com%2Farchives%2F118&amp;title=Pretty%20Damn%20Fancy%20-%20Java%20PDF%20Cracker&amp;bodytext=I%20had%20to%20open%20a%20PDF%2C%20so%20I%20spent%20the%20morning%20working%20on%20a%20basic%20PDF%20password%20cracker%20written%20in%20Java.%20%20I%20haven%27t%20encapsulated%20it%20in%20a%20command%20line%20tool%20yet%20%28and%20I%27m%20not%20sure%20I%20ever%20will%29%2C%20but%20it%20came%20out%20pretty%20neat.%0A%0AIt%20started%20out%20simple%20enough%3A%0Aboo" title="Digg"><img src="http://blog.johncrepezzi.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" /></a>
	<a rel="nofollow"  href="http://twitter.com/home?status=Pretty%20Damn%20Fancy%20-%20Java%20PDF%20Cracker%20-%20http%3A%2F%2Fblog.johncrepezzi.com%2Farchives%2F118%20(via%20%40seejohnrun)" title="Twitter"><img src="http://blog.johncrepezzi.com/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" /></a>
	<a rel="nofollow"  href="http://www.friendfeed.com/share?title=Pretty%20Damn%20Fancy%20-%20Java%20PDF%20Cracker&amp;link=http%3A%2F%2Fblog.johncrepezzi.com%2Farchives%2F118" title="FriendFeed"><img src="http://blog.johncrepezzi.com/wp-content/plugins/sociable/images/friendfeed.png" title="FriendFeed" alt="FriendFeed" /></a>
	<a rel="nofollow"  href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fblog.johncrepezzi.com%2Farchives%2F118&amp;title=Pretty%20Damn%20Fancy%20-%20Java%20PDF%20Cracker&amp;annotation=I%20had%20to%20open%20a%20PDF%2C%20so%20I%20spent%20the%20morning%20working%20on%20a%20basic%20PDF%20password%20cracker%20written%20in%20Java.%20%20I%20haven%27t%20encapsulated%20it%20in%20a%20command%20line%20tool%20yet%20%28and%20I%27m%20not%20sure%20I%20ever%20will%29%2C%20but%20it%20came%20out%20pretty%20neat.%0A%0AIt%20started%20out%20simple%20enough%3A%0Aboo" title="Google Bookmarks"><img src="http://blog.johncrepezzi.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://blog.johncrepezzi.com/archives/118/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>TweetStream4J &#8211; Twitter Streaming API in Java</title>
		<link>http://blog.johncrepezzi.com/archives/113</link>
		<comments>http://blog.johncrepezzi.com/archives/113#comments</comments>
		<pubDate>Tue, 05 Jan 2010 16:32:09 +0000</pubDate>
		<dc:creator>john</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[stream]]></category>
		<category><![CDATA[streaming]]></category>
		<category><![CDATA[tweet]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://blog.johncrepezzi.com/?p=113</guid>
		<description><![CDATA[I spent some time a few days back on the initial release of TweetStream4J. It is a Java library to interact with the new Twitter Streaming API (v1). Admittedly the initial release is one day old and a bit rough around the edges but still very useful. I just wanna show here on the blog [...]]]></description>
			<content:encoded><![CDATA[<p>I spent some time a few days back on the initial release of <a href="http://github.com/seejohnrun/tweetStream4J">TweetStream4J</a>.  It is a Java library to interact with the new <a href="http://apiwiki.twitter.com/Streaming-API-Documentation">Twitter Streaming API</a> (v1).  Admittedly the initial release is one day old and a bit rough around the edges but still very useful.</p>
<p>I just wanna show here on the blog the example usage in order to persuade people to pick it up, or develop similarly built libraries in other languages.</p>
<p>My implementation revolves around an interface called TwitterStream Handler:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">interface</span> TwitterStreamHandler <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">//incoming tweet</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> addTweet<span style="color: #009900;">&#40;</span>STweet t<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">//incoming deletion request</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> addLimit<span style="color: #009900;">&#40;</span>STweet l<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">//incoming limit</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> addDeletion<span style="color: #009900;">&#40;</span>SDeletion d<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>The handler is set to handle individual tweet, deletion, and limit request from twitter, and the objects they take as parameters are sent directly from the Streaming API, so a simple implmenetation of addTweet(STweet t) might look like:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="java" style="font-family:monospace;">@Override
<span style="color: #000066; font-weight: bold;">void</span> addTweet<span style="color: #009900;">&#40;</span>STweet t<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>t.<span style="color: #006633;">getText</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot; (by &quot;</span> <span style="color: #339933;">+</span> t.<span style="color: #006633;">getUser</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getScreenName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;)&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Once you have a useful handler, its time to put it to work.  To use the &#8216;sample&#8217; method is as easy as:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="java" style="font-family:monospace;">TwitterStreamConfiguraion tws <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> TwitterStreamConfiguration<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;username&quot;</span>, <span style="color: #0000ff;">&quot;xx&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
TwitterStream ts <span style="color: #339933;">=</span> TweetRiver.<span style="color: #006633;">sample</span><span style="color: #009900;">&#40;</span>tws, handler<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Thread</span><span style="color: #009900;">&#40;</span>ts<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>and the streaming will begin.  If you&#8217;d rather track keywords or users as specified by the Twitter API site, you can use the &#8216;filter&#8217; method.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="java" style="font-family:monospace;">TwitterStreamConfiguration tws <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> TwitterStreamConfiguration<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;username&quot;</span>, <span style="color: #0000ff;">&quot;xx&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//build a list of strings to track</span>
Collection<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;</span> tracks <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ArrayList<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
tracks.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;obama&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
tracks.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;bush&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//start streaming</span>
TwitterStream ts <span style="color: #339933;">=</span> TweetRiver.<span style="color: #006633;">filter</span><span style="color: #009900;">&#40;</span>tws, handler, <span style="color: #000066; font-weight: bold;">null</span>, tracks<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Thread</span><span style="color: #009900;">&#40;</span>ts<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>The implementation covers the higher-level methods like &#8216;retweet&#8217; and &#8216;firehose&#8217; inaccessible to normal users, and has a full JavaDoc &#8230; so try it out and maybe contribute some code.</p>
<p><em>(BSD License)</em></p>




	<a rel="nofollow"  href="mailto:?subject=TweetStream4J%20-%20Twitter%20Streaming%20API%20in%20Java&amp;body=http%3A%2F%2Fblog.johncrepezzi.com%2Farchives%2F113" title="email"><img src="http://blog.johncrepezzi.com/wp-content/plugins/sociable/images/email_link.png" title="email" alt="email" /></a>
	<a rel="nofollow"  href="http://delicious.com/post?url=http%3A%2F%2Fblog.johncrepezzi.com%2Farchives%2F113&amp;title=TweetStream4J%20-%20Twitter%20Streaming%20API%20in%20Java&amp;notes=I%20spent%20some%20time%20a%20few%20days%20back%20on%20the%20initial%20release%20of%20TweetStream4J.%20%20It%20is%20a%20Java%20library%20to%20interact%20with%20the%20new%20Twitter%20Streaming%20API%20%28v1%29.%20%20Admittedly%20the%20initial%20release%20is%20one%20day%20old%20and%20a%20bit%20rough%20around%20the%20edges%20but%20still%20very%20usefu" title="del.icio.us"><img src="http://blog.johncrepezzi.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" /></a>
	<a rel="nofollow"  href="http://www.facebook.com/share.php?u=http%3A%2F%2Fblog.johncrepezzi.com%2Farchives%2F113&amp;t=TweetStream4J%20-%20Twitter%20Streaming%20API%20in%20Java" title="Facebook"><img src="http://blog.johncrepezzi.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" /></a>
	<a rel="nofollow"  href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fblog.johncrepezzi.com%2Farchives%2F113&amp;title=TweetStream4J%20-%20Twitter%20Streaming%20API%20in%20Java&amp;bodytext=I%20spent%20some%20time%20a%20few%20days%20back%20on%20the%20initial%20release%20of%20TweetStream4J.%20%20It%20is%20a%20Java%20library%20to%20interact%20with%20the%20new%20Twitter%20Streaming%20API%20%28v1%29.%20%20Admittedly%20the%20initial%20release%20is%20one%20day%20old%20and%20a%20bit%20rough%20around%20the%20edges%20but%20still%20very%20usefu" title="Digg"><img src="http://blog.johncrepezzi.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" /></a>
	<a rel="nofollow"  href="http://twitter.com/home?status=TweetStream4J%20-%20Twitter%20Streaming%20API%20in%20Java%20-%20http%3A%2F%2Fblog.johncrepezzi.com%2Farchives%2F113%20(via%20%40seejohnrun)" title="Twitter"><img src="http://blog.johncrepezzi.com/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" /></a>
	<a rel="nofollow"  href="http://www.friendfeed.com/share?title=TweetStream4J%20-%20Twitter%20Streaming%20API%20in%20Java&amp;link=http%3A%2F%2Fblog.johncrepezzi.com%2Farchives%2F113" title="FriendFeed"><img src="http://blog.johncrepezzi.com/wp-content/plugins/sociable/images/friendfeed.png" title="FriendFeed" alt="FriendFeed" /></a>
	<a rel="nofollow"  href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fblog.johncrepezzi.com%2Farchives%2F113&amp;title=TweetStream4J%20-%20Twitter%20Streaming%20API%20in%20Java&amp;annotation=I%20spent%20some%20time%20a%20few%20days%20back%20on%20the%20initial%20release%20of%20TweetStream4J.%20%20It%20is%20a%20Java%20library%20to%20interact%20with%20the%20new%20Twitter%20Streaming%20API%20%28v1%29.%20%20Admittedly%20the%20initial%20release%20is%20one%20day%20old%20and%20a%20bit%20rough%20around%20the%20edges%20but%20still%20very%20usefu" title="Google Bookmarks"><img src="http://blog.johncrepezzi.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://blog.johncrepezzi.com/archives/113/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>famfamfam flag icons addition</title>
		<link>http://blog.johncrepezzi.com/archives/104</link>
		<comments>http://blog.johncrepezzi.com/archives/104#comments</comments>
		<pubDate>Tue, 17 Nov 2009 20:51:57 +0000</pubDate>
		<dc:creator>john</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.johncrepezzi.com/?p=104</guid>
		<description><![CDATA[I needed some flag icons for a project i&#8217;m working on. I wanted the icons to follow ISO-3166 as not to miss any countries. I found a great resource on famfamfam.com http://www.famfamfam.com/lab/icons/flags/ 247 such icons in GIF and PNG formats Lining this up against current ISO-3166, I found a few missing, particularly: Antartica (aq) Saint [...]]]></description>
			<content:encoded><![CDATA[<p>I needed some flag icons for a project i&#8217;m working on.  I wanted the icons to follow ISO-3166 as not to miss any countries.  I found a great resource on famfamfam.com</p>
<p><a href="http://www.famfamfam.com/lab/icons/flags/" rel="nofollow">http://www.famfamfam.com/lab/icons/flags/</a></p>
<p>247 such icons in GIF and PNG formats</p>
<p>Lining this up against current ISO-3166, I found a few missing, particularly:<br />
Antartica (aq)<br />
Saint Barthelemy (bl)<br />
Guernsey (gg)<br />
Isle of Man (im)<br />
Jersey (je)<br />
St. Martin (mf) </p>
<p>I made up these icons to match the existing set for these extra countries, and have attached them here.  Feel free to use them anywhere you&#8217;d like to round out your flag set.  They&#8217;re the same dimensions as the original set.</p>
<p>Enjoy!</p>
<p><a href="http://johncrepezzi.com/wp-content/uploads/2009/11/fam-moreflags.zip">Click to Download</a></p>




	<a rel="nofollow"  href="mailto:?subject=famfamfam%20flag%20icons%20addition&amp;body=http%3A%2F%2Fblog.johncrepezzi.com%2Farchives%2F104" title="email"><img src="http://blog.johncrepezzi.com/wp-content/plugins/sociable/images/email_link.png" title="email" alt="email" /></a>
	<a rel="nofollow"  href="http://delicious.com/post?url=http%3A%2F%2Fblog.johncrepezzi.com%2Farchives%2F104&amp;title=famfamfam%20flag%20icons%20addition&amp;notes=I%20needed%20some%20flag%20icons%20for%20a%20project%20i%27m%20working%20on.%20%20I%20wanted%20the%20icons%20to%20follow%20ISO-3166%20as%20not%20to%20miss%20any%20countries.%20%20I%20found%20a%20great%20resource%20on%20famfamfam.com%0A%0Ahttp%3A%2F%2Fwww.famfamfam.com%2Flab%2Ficons%2Fflags%2F%0A247%20such%20icons%20in%20GIF%20and%20PNG%20formats%0A%0AL" title="del.icio.us"><img src="http://blog.johncrepezzi.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" /></a>
	<a rel="nofollow"  href="http://www.facebook.com/share.php?u=http%3A%2F%2Fblog.johncrepezzi.com%2Farchives%2F104&amp;t=famfamfam%20flag%20icons%20addition" title="Facebook"><img src="http://blog.johncrepezzi.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" /></a>
	<a rel="nofollow"  href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fblog.johncrepezzi.com%2Farchives%2F104&amp;title=famfamfam%20flag%20icons%20addition&amp;bodytext=I%20needed%20some%20flag%20icons%20for%20a%20project%20i%27m%20working%20on.%20%20I%20wanted%20the%20icons%20to%20follow%20ISO-3166%20as%20not%20to%20miss%20any%20countries.%20%20I%20found%20a%20great%20resource%20on%20famfamfam.com%0A%0Ahttp%3A%2F%2Fwww.famfamfam.com%2Flab%2Ficons%2Fflags%2F%0A247%20such%20icons%20in%20GIF%20and%20PNG%20formats%0A%0AL" title="Digg"><img src="http://blog.johncrepezzi.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" /></a>
	<a rel="nofollow"  href="http://twitter.com/home?status=famfamfam%20flag%20icons%20addition%20-%20http%3A%2F%2Fblog.johncrepezzi.com%2Farchives%2F104%20(via%20%40seejohnrun)" title="Twitter"><img src="http://blog.johncrepezzi.com/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" /></a>
	<a rel="nofollow"  href="http://www.friendfeed.com/share?title=famfamfam%20flag%20icons%20addition&amp;link=http%3A%2F%2Fblog.johncrepezzi.com%2Farchives%2F104" title="FriendFeed"><img src="http://blog.johncrepezzi.com/wp-content/plugins/sociable/images/friendfeed.png" title="FriendFeed" alt="FriendFeed" /></a>
	<a rel="nofollow"  href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fblog.johncrepezzi.com%2Farchives%2F104&amp;title=famfamfam%20flag%20icons%20addition&amp;annotation=I%20needed%20some%20flag%20icons%20for%20a%20project%20i%27m%20working%20on.%20%20I%20wanted%20the%20icons%20to%20follow%20ISO-3166%20as%20not%20to%20miss%20any%20countries.%20%20I%20found%20a%20great%20resource%20on%20famfamfam.com%0A%0Ahttp%3A%2F%2Fwww.famfamfam.com%2Flab%2Ficons%2Fflags%2F%0A247%20such%20icons%20in%20GIF%20and%20PNG%20formats%0A%0AL" title="Google Bookmarks"><img src="http://blog.johncrepezzi.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://blog.johncrepezzi.com/archives/104/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>CodeIgniter form validation regex</title>
		<link>http://blog.johncrepezzi.com/archives/100</link>
		<comments>http://blog.johncrepezzi.com/archives/100#comments</comments>
		<pubDate>Sat, 26 Sep 2009 17:12:45 +0000</pubDate>
		<dc:creator>john</dc:creator>
				<category><![CDATA[code]]></category>

		<guid isPermaLink="false">http://blog.johncrepezzi.com/?p=100</guid>
		<description><![CDATA[I&#8217;ve been using the CodeIgniter form_validation library: http://codeigniter.com/user_guide/libraries/form_validation.html not to be confused with the older http://codeigniter.com/user_guide/libraries/validation.html. There are some great additions in this new library that make the syntax of form validation not clutter your controllers. The one thing I wanted that the library didn&#8217;t come with, was a way to easily test regular expressions [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been using the CodeIgniter form_validation library:<br />
<a href="http://codeigniter.com/user_guide/libraries/form_validation.html">http://codeigniter.com/user_guide/libraries/form_validation.html</a> not to be confused with the older <a href='http://codeigniter.com/user_guide/libraries/validation.html'>http://codeigniter.com/user_guide/libraries/validation.html</a>.</p>
<p>There are some great additions in this new library that make the syntax of form validation not clutter your controllers.  The one thing I wanted that the library didn&#8217;t come with, was a way to easily test regular expressions against fields without cluttering the controller, or ruining my internationalization features.  </p>
<p>Ideally, what we&#8217;re aiming for is:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$register</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
    <span style="color: #0000ff;">'field'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'username'</span><span style="color: #339933;">,</span>    
    <span style="color: #0000ff;">'label'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'Username'</span><span style="color: #339933;">,</span>                
    <span style="color: #0000ff;">'rules'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'required|validate[username]'</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>The hope is that we dont&#8217; need to write anything extra in our controller, and we can use this from anywhere.<br />
I started with a function, that I thought did pretty well:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> _validate<span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #339933;">,</span> <span style="color: #000088;">$type</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">config</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'validation_regex'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">form_validation</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set_message</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'matches'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'%s gotsta match %s'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">//validation succeeded </span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">config</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">item</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'regex_'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$type</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">//validation failed</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">language</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'invalid'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">form_validation</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set_message</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'_validate'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">lang</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">line</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'invalid_'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$type</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>This was great, it allows easy configuration, and all you need is a line in your $config[]:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'regex_username'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'/^[a-zA-Z0-9]{6,15}$/'</span><span style="color: #339933;">;</span></pre></div></div>

<p>and a line in your $lang[]:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$lang</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'invalid_username'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Username must be alpha-numeric, between 6-15 characters&quot;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The last step was to move this function a central location so that I could use it in multiple controllers, and not have to use the &#8216;callback_&#8217; functionality (thus repeating code).</p>
<p>I ended up extending the form_validation library, like so (application/libraries/MY_Form_validation.php):</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span> <span style="color: #990000;">defined</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'BASEPATH'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #990000;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'No direct script access allowed'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> MY_Form_validation <span style="color: #000000; font-weight: bold;">extends</span> CI_Form_validation <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">function</span> validate<span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #339933;">,</span> <span style="color: #000088;">$type</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$CI</span> <span style="color: #339933;">=</span> <span style="color: #339933;">&amp;</span>get_instance<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$CI</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">config</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'validation_regex'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$CI</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">form_validation</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set_message</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'matches'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'%s gotsta match %s'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">//validation succeeded</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$CI</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">config</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">item</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'regex_'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$type</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">//validation failed</span>
        <span style="color: #000088;">$CI</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">language</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'invalid'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$CI</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">form_validation</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set_message</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'validate'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$CI</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">lang</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">line</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'invalid_'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$type</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>





	<a rel="nofollow"  href="mailto:?subject=CodeIgniter%20form%20validation%20regex&amp;body=http%3A%2F%2Fblog.johncrepezzi.com%2Farchives%2F100" title="email"><img src="http://blog.johncrepezzi.com/wp-content/plugins/sociable/images/email_link.png" title="email" alt="email" /></a>
	<a rel="nofollow"  href="http://delicious.com/post?url=http%3A%2F%2Fblog.johncrepezzi.com%2Farchives%2F100&amp;title=CodeIgniter%20form%20validation%20regex&amp;notes=I%27ve%20been%20using%20the%20CodeIgniter%20form_validation%20library%3A%0Ahttp%3A%2F%2Fcodeigniter.com%2Fuser_guide%2Flibraries%2Fform_validation.html%20not%20to%20be%20confused%20with%20the%20older%20http%3A%2F%2Fcodeigniter.com%2Fuser_guide%2Flibraries%2Fvalidation.html.%0A%0AThere%20are%20some%20great%20additions%20i" title="del.icio.us"><img src="http://blog.johncrepezzi.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" /></a>
	<a rel="nofollow"  href="http://www.facebook.com/share.php?u=http%3A%2F%2Fblog.johncrepezzi.com%2Farchives%2F100&amp;t=CodeIgniter%20form%20validation%20regex" title="Facebook"><img src="http://blog.johncrepezzi.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" /></a>
	<a rel="nofollow"  href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fblog.johncrepezzi.com%2Farchives%2F100&amp;title=CodeIgniter%20form%20validation%20regex&amp;bodytext=I%27ve%20been%20using%20the%20CodeIgniter%20form_validation%20library%3A%0Ahttp%3A%2F%2Fcodeigniter.com%2Fuser_guide%2Flibraries%2Fform_validation.html%20not%20to%20be%20confused%20with%20the%20older%20http%3A%2F%2Fcodeigniter.com%2Fuser_guide%2Flibraries%2Fvalidation.html.%0A%0AThere%20are%20some%20great%20additions%20i" title="Digg"><img src="http://blog.johncrepezzi.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" /></a>
	<a rel="nofollow"  href="http://twitter.com/home?status=CodeIgniter%20form%20validation%20regex%20-%20http%3A%2F%2Fblog.johncrepezzi.com%2Farchives%2F100%20(via%20%40seejohnrun)" title="Twitter"><img src="http://blog.johncrepezzi.com/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" /></a>
	<a rel="nofollow"  href="http://www.friendfeed.com/share?title=CodeIgniter%20form%20validation%20regex&amp;link=http%3A%2F%2Fblog.johncrepezzi.com%2Farchives%2F100" title="FriendFeed"><img src="http://blog.johncrepezzi.com/wp-content/plugins/sociable/images/friendfeed.png" title="FriendFeed" alt="FriendFeed" /></a>
	<a rel="nofollow"  href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fblog.johncrepezzi.com%2Farchives%2F100&amp;title=CodeIgniter%20form%20validation%20regex&amp;annotation=I%27ve%20been%20using%20the%20CodeIgniter%20form_validation%20library%3A%0Ahttp%3A%2F%2Fcodeigniter.com%2Fuser_guide%2Flibraries%2Fform_validation.html%20not%20to%20be%20confused%20with%20the%20older%20http%3A%2F%2Fcodeigniter.com%2Fuser_guide%2Flibraries%2Fvalidation.html.%0A%0AThere%20are%20some%20great%20additions%20i" title="Google Bookmarks"><img src="http://blog.johncrepezzi.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://blog.johncrepezzi.com/archives/100/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CodeIgniter / PHP Custom GUID Generation</title>
		<link>http://blog.johncrepezzi.com/archives/98</link>
		<comments>http://blog.johncrepezzi.com/archives/98#comments</comments>
		<pubDate>Thu, 17 Sep 2009 22:35:39 +0000</pubDate>
		<dc:creator>john</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[codeigniter]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://blog.johncrepezzi.com/?p=98</guid>
		<description><![CDATA[Today I was working with CodeIgniter, and found myself wanting to make GUID (Globally Unique Identifiers) for a certain database table upon insert. I wanted to make the length configurable on the fly and not use any extra DB functionality. I also wanted to ensure that there would never be a collision as long as [...]]]></description>
			<content:encoded><![CDATA[<p>Today I was working with CodeIgniter, and found myself wanting to make GUID (Globally Unique Identifiers) for a certain database table upon insert.  I wanted to make the length configurable on the fly and not use any extra DB functionality.  I also wanted to ensure that there would never be a collision as long as there were still available keys in the namespace. </p>
<p>I came up with the following code:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> newTopic<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$original</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db_debug</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db_debug</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">do</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">//create it</span>
        <span style="color: #000088;">$tgid</span> <span style="color: #339933;">=</span> randomString<span style="color: #009900;">&#40;</span>config_item<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'topic_key_length'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'tgid'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$tgid</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'date_added'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'NOW()'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'removed'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">insert</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'topics'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db_debug</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$original</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">insert_id</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Which works great!  The only part of this that is a little bit of a hack is the db_debug toggling, which turns off code igniter db errors for a second so that I can avoid duplicate key errors.</p>
<p>Enjoy!!!</p>




	<a rel="nofollow"  href="mailto:?subject=CodeIgniter%20%2F%20PHP%20Custom%20GUID%20Generation&amp;body=http%3A%2F%2Fblog.johncrepezzi.com%2Farchives%2F98" title="email"><img src="http://blog.johncrepezzi.com/wp-content/plugins/sociable/images/email_link.png" title="email" alt="email" /></a>
	<a rel="nofollow"  href="http://delicious.com/post?url=http%3A%2F%2Fblog.johncrepezzi.com%2Farchives%2F98&amp;title=CodeIgniter%20%2F%20PHP%20Custom%20GUID%20Generation&amp;notes=Today%20I%20was%20working%20with%20CodeIgniter%2C%20and%20found%20myself%20wanting%20to%20make%20GUID%20%28Globally%20Unique%20Identifiers%29%20for%20a%20certain%20database%20table%20upon%20insert.%20%20I%20wanted%20to%20make%20the%20length%20configurable%20on%20the%20fly%20and%20not%20use%20any%20extra%20DB%20functionality.%20%20I%20also%20w" title="del.icio.us"><img src="http://blog.johncrepezzi.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" /></a>
	<a rel="nofollow"  href="http://www.facebook.com/share.php?u=http%3A%2F%2Fblog.johncrepezzi.com%2Farchives%2F98&amp;t=CodeIgniter%20%2F%20PHP%20Custom%20GUID%20Generation" title="Facebook"><img src="http://blog.johncrepezzi.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" /></a>
	<a rel="nofollow"  href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fblog.johncrepezzi.com%2Farchives%2F98&amp;title=CodeIgniter%20%2F%20PHP%20Custom%20GUID%20Generation&amp;bodytext=Today%20I%20was%20working%20with%20CodeIgniter%2C%20and%20found%20myself%20wanting%20to%20make%20GUID%20%28Globally%20Unique%20Identifiers%29%20for%20a%20certain%20database%20table%20upon%20insert.%20%20I%20wanted%20to%20make%20the%20length%20configurable%20on%20the%20fly%20and%20not%20use%20any%20extra%20DB%20functionality.%20%20I%20also%20w" title="Digg"><img src="http://blog.johncrepezzi.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" /></a>
	<a rel="nofollow"  href="http://twitter.com/home?status=CodeIgniter%20%2F%20PHP%20Custom%20GUID%20Generation%20-%20http%3A%2F%2Fblog.johncrepezzi.com%2Farchives%2F98%20(via%20%40seejohnrun)" title="Twitter"><img src="http://blog.johncrepezzi.com/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" /></a>
	<a rel="nofollow"  href="http://www.friendfeed.com/share?title=CodeIgniter%20%2F%20PHP%20Custom%20GUID%20Generation&amp;link=http%3A%2F%2Fblog.johncrepezzi.com%2Farchives%2F98" title="FriendFeed"><img src="http://blog.johncrepezzi.com/wp-content/plugins/sociable/images/friendfeed.png" title="FriendFeed" alt="FriendFeed" /></a>
	<a rel="nofollow"  href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fblog.johncrepezzi.com%2Farchives%2F98&amp;title=CodeIgniter%20%2F%20PHP%20Custom%20GUID%20Generation&amp;annotation=Today%20I%20was%20working%20with%20CodeIgniter%2C%20and%20found%20myself%20wanting%20to%20make%20GUID%20%28Globally%20Unique%20Identifiers%29%20for%20a%20certain%20database%20table%20upon%20insert.%20%20I%20wanted%20to%20make%20the%20length%20configurable%20on%20the%20fly%20and%20not%20use%20any%20extra%20DB%20functionality.%20%20I%20also%20w" title="Google Bookmarks"><img src="http://blog.johncrepezzi.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://blog.johncrepezzi.com/archives/98/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>John&#8217;s Hash Tester</title>
		<link>http://blog.johncrepezzi.com/archives/95</link>
		<comments>http://blog.johncrepezzi.com/archives/95#comments</comments>
		<pubDate>Fri, 04 Sep 2009 18:24:52 +0000</pubDate>
		<dc:creator>john</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[hash]]></category>

		<guid isPermaLink="false">http://johncrepezzi.com/?p=95</guid>
		<description><![CDATA[Hey everyone, Just wanted to post up this little utility I wrote up because I wanted something like it. its for testing hashes of input on the fly against a variety of algorithms. Took about 10 minutes to write, using PHP&#8217;s built-in hash library, but maybe someone will have a use for it when I [...]]]></description>
			<content:encoded><![CDATA[<p>Hey everyone,<br />
Just wanted to post up this little utility I wrote up because I wanted something like it.  its for testing hashes of input on the fly against a variety of algorithms.  Took about 10 minutes to write, using PHP&#8217;s built-in hash library, but maybe someone will have a use for it when I put it in a central location:</p>
<p><a href="http://crepezzi.com/encdec/">http://crepezzi.com/encdec/</a></p>




	<a rel="nofollow"  href="mailto:?subject=John%27s%20Hash%20Tester&amp;body=http%3A%2F%2Fblog.johncrepezzi.com%2Farchives%2F95" title="email"><img src="http://blog.johncrepezzi.com/wp-content/plugins/sociable/images/email_link.png" title="email" alt="email" /></a>
	<a rel="nofollow"  href="http://delicious.com/post?url=http%3A%2F%2Fblog.johncrepezzi.com%2Farchives%2F95&amp;title=John%27s%20Hash%20Tester&amp;notes=Hey%20everyone%2C%0D%0AJust%20wanted%20to%20post%20up%20this%20little%20utility%20I%20wrote%20up%20because%20I%20wanted%20something%20like%20it.%20%20its%20for%20testing%20hashes%20of%20input%20on%20the%20fly%20against%20a%20variety%20of%20algorithms.%20%20Took%20about%2010%20minutes%20to%20write%2C%20using%20PHP%27s%20built-in%20hash%20library%2C%20" title="del.icio.us"><img src="http://blog.johncrepezzi.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" /></a>
	<a rel="nofollow"  href="http://www.facebook.com/share.php?u=http%3A%2F%2Fblog.johncrepezzi.com%2Farchives%2F95&amp;t=John%27s%20Hash%20Tester" title="Facebook"><img src="http://blog.johncrepezzi.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" /></a>
	<a rel="nofollow"  href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fblog.johncrepezzi.com%2Farchives%2F95&amp;title=John%27s%20Hash%20Tester&amp;bodytext=Hey%20everyone%2C%0D%0AJust%20wanted%20to%20post%20up%20this%20little%20utility%20I%20wrote%20up%20because%20I%20wanted%20something%20like%20it.%20%20its%20for%20testing%20hashes%20of%20input%20on%20the%20fly%20against%20a%20variety%20of%20algorithms.%20%20Took%20about%2010%20minutes%20to%20write%2C%20using%20PHP%27s%20built-in%20hash%20library%2C%20" title="Digg"><img src="http://blog.johncrepezzi.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" /></a>
	<a rel="nofollow"  href="http://twitter.com/home?status=John%27s%20Hash%20Tester%20-%20http%3A%2F%2Fblog.johncrepezzi.com%2Farchives%2F95%20(via%20%40seejohnrun)" title="Twitter"><img src="http://blog.johncrepezzi.com/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" /></a>
	<a rel="nofollow"  href="http://www.friendfeed.com/share?title=John%27s%20Hash%20Tester&amp;link=http%3A%2F%2Fblog.johncrepezzi.com%2Farchives%2F95" title="FriendFeed"><img src="http://blog.johncrepezzi.com/wp-content/plugins/sociable/images/friendfeed.png" title="FriendFeed" alt="FriendFeed" /></a>
	<a rel="nofollow"  href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fblog.johncrepezzi.com%2Farchives%2F95&amp;title=John%27s%20Hash%20Tester&amp;annotation=Hey%20everyone%2C%0D%0AJust%20wanted%20to%20post%20up%20this%20little%20utility%20I%20wrote%20up%20because%20I%20wanted%20something%20like%20it.%20%20its%20for%20testing%20hashes%20of%20input%20on%20the%20fly%20against%20a%20variety%20of%20algorithms.%20%20Took%20about%2010%20minutes%20to%20write%2C%20using%20PHP%27s%20built-in%20hash%20library%2C%20" title="Google Bookmarks"><img src="http://blog.johncrepezzi.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://blog.johncrepezzi.com/archives/95/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Office Duties</title>
		<link>http://blog.johncrepezzi.com/archives/87</link>
		<comments>http://blog.johncrepezzi.com/archives/87#comments</comments>
		<pubDate>Thu, 03 Sep 2009 16:17:22 +0000</pubDate>
		<dc:creator>john</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[office]]></category>

		<guid isPermaLink="false">http://johncrepezzi.com/?p=87</guid>
		<description><![CDATA[By far my favorite part of programming is little scripts that perform functions that save people time. This convenient PHP script allows for rotation of office duties on a regular basis. Its quick and dirty, but it does its job well. It even works with any number of people/duties, they don&#8217;t need to be one [...]]]></description>
			<content:encoded><![CDATA[<p>By far my favorite part of programming is little scripts that perform functions that save people time.  This convenient PHP script allows for rotation of office duties on a regular basis.  Its quick and dirty, but it does its job well.  It even works with any number of people/duties, they don&#8217;t need to be one for one.</p>
<p>we start out with the data:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//data</span>
<span style="color: #000088;">$people</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'JB'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Kenny'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Dan'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Tar'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'JC'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$duties</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Trash'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Dishes'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Backroom'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Vacuum'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Bathroom'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$timezone</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'America/New_York'</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>then, in order to rotate the duties on a weekly basis, we get a rotationary number.  This number is based on the week of the year, which PHP makes it pretty easy to get.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>4
5
6
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//get a rotationary number</span>
<span style="color: #990000;">date_default_timezone_set</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$timezone</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$rot</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'W'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">%</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$people</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Shifting these arrays based on the rotational number get us most of the way to what we need:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>7
8
9
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//shift the duties array</span>
<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$rot</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$duties</span><span style="color: #009900;">&#91;</span><span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$duties</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_shift</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$duties</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$rot</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$people</span><span style="color: #009900;">&#91;</span><span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$people</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_shift</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$people</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>We assign the duties into a nice array that associates people with the duties they have to perform:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>10
11
12
13
14
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$rot</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//the same person shouldn't always get two duties</span>
<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$duties</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$duty</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$work</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$people</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$duty</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//give person duty</span>
	<span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #339933;">++</span><span style="color: #000088;">$i</span> <span style="color: #339933;">%</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$people</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//pick what person gets the next duty</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>and then sort by names to make the list easier to read:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>15
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">ksort</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$work</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>The display code is extremely straightforward.  I customized mine a bit more, but to give you the general idea:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">&lt;html&gt;
&nbsp;
	&lt;head&gt;
		&lt;title&gt;office duties&lt;/title&gt;
	&lt;/head&gt;
&nbsp;
	&lt;body&gt;
		&lt;h2&gt;office duties&lt;/h2&gt;
		<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$work</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$person</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$duties</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
			&lt;strong&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$person</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/strong&gt;: 
			<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$duties</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">', '</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
                        &lt;br/&gt;
		<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endforeach</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
		&lt;hr&gt;
		&lt;em&gt;Dates rotate each Monday&lt;/em&gt;
	&lt;/body&gt;
&nbsp;
&lt;/html&gt;</pre></td></tr></table></div>

<p>Hope you enjoy it.  Let me know how you use it!</p>
<p>To give you all that code in one place:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">/****************
	John Crepezzi
	September 3, 2009
	*****************/</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//data</span>
	<span style="color: #000088;">$people</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'JB'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Kenny'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Dan'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Tar'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'JC'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$duties</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Trash'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Dishes'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Backroom'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Vacuum'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Bathroom'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$timezone</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'America/New_York'</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//get a rotationary number</span>
	<span style="color: #990000;">date_default_timezone_set</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$timezone</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$rot</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'W'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">%</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$people</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//shift the duties array</span>
	<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$rot</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$duties</span><span style="color: #009900;">&#91;</span><span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$duties</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_shift</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$duties</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$rot</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$people</span><span style="color: #009900;">&#91;</span><span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$people</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_shift</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$people</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//assign the duties</span>
	<span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$rot</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//the same person shouldn't always get two duties</span>
	<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$duties</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$duty</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$work</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$people</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$duty</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//give person duty</span>
		<span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #339933;">++</span><span style="color: #000088;">$i</span> <span style="color: #339933;">%</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$people</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//pick what person gets the next duty</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//sort the names in alphabetical order</span>
	<span style="color: #990000;">ksort</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$work</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;</span>html<span style="color: #339933;">&gt;</span>
&nbsp;
	<span style="color: #339933;">&lt;</span>head<span style="color: #339933;">&gt;</span>
		<span style="color: #339933;">&lt;</span>title<span style="color: #339933;">&gt;</span>office duties<span style="color: #339933;">&lt;/</span>title<span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;/</span>head<span style="color: #339933;">&gt;</span>
&nbsp;
	<span style="color: #339933;">&lt;</span>body<span style="color: #339933;">&gt;</span>
		<span style="color: #339933;">&lt;</span>h2<span style="color: #339933;">&gt;</span>office duties<span style="color: #339933;">&lt;/</span>h2<span style="color: #339933;">&gt;</span>
		<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$work</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$person</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$duties</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
			<span style="color: #339933;">&lt;</span>strong<span style="color: #339933;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;?</span>php <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$person</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span><span style="color: #339933;">&lt;/</span>strong<span style="color: #339933;">&gt;:</span> 
			<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$duties</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">', '</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span> &lt;br/&gt;
		<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endforeach</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
		&lt;hr&gt;
		&lt;em&gt;Dates rotate each Monday&lt;/em&gt;
	&lt;/body&gt;
&nbsp;
&lt;/html&gt;</pre></div></div>





	<a rel="nofollow"  href="mailto:?subject=Office%20Duties&amp;body=http%3A%2F%2Fblog.johncrepezzi.com%2Farchives%2F87" title="email"><img src="http://blog.johncrepezzi.com/wp-content/plugins/sociable/images/email_link.png" title="email" alt="email" /></a>
	<a rel="nofollow"  href="http://delicious.com/post?url=http%3A%2F%2Fblog.johncrepezzi.com%2Farchives%2F87&amp;title=Office%20Duties&amp;notes=By%20far%20my%20favorite%20part%20of%20programming%20is%20little%20scripts%20that%20perform%20functions%20that%20save%20people%20time.%20%20This%20convenient%20PHP%20script%20allows%20for%20rotation%20of%20office%20duties%20on%20a%20regular%20basis.%20%20Its%20quick%20and%20dirty%2C%20but%20it%20does%20its%20job%20well.%20%20It%20even%20works" title="del.icio.us"><img src="http://blog.johncrepezzi.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" /></a>
	<a rel="nofollow"  href="http://www.facebook.com/share.php?u=http%3A%2F%2Fblog.johncrepezzi.com%2Farchives%2F87&amp;t=Office%20Duties" title="Facebook"><img src="http://blog.johncrepezzi.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" /></a>
	<a rel="nofollow"  href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fblog.johncrepezzi.com%2Farchives%2F87&amp;title=Office%20Duties&amp;bodytext=By%20far%20my%20favorite%20part%20of%20programming%20is%20little%20scripts%20that%20perform%20functions%20that%20save%20people%20time.%20%20This%20convenient%20PHP%20script%20allows%20for%20rotation%20of%20office%20duties%20on%20a%20regular%20basis.%20%20Its%20quick%20and%20dirty%2C%20but%20it%20does%20its%20job%20well.%20%20It%20even%20works" title="Digg"><img src="http://blog.johncrepezzi.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" /></a>
	<a rel="nofollow"  href="http://twitter.com/home?status=Office%20Duties%20-%20http%3A%2F%2Fblog.johncrepezzi.com%2Farchives%2F87%20(via%20%40seejohnrun)" title="Twitter"><img src="http://blog.johncrepezzi.com/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" /></a>
	<a rel="nofollow"  href="http://www.friendfeed.com/share?title=Office%20Duties&amp;link=http%3A%2F%2Fblog.johncrepezzi.com%2Farchives%2F87" title="FriendFeed"><img src="http://blog.johncrepezzi.com/wp-content/plugins/sociable/images/friendfeed.png" title="FriendFeed" alt="FriendFeed" /></a>
	<a rel="nofollow"  href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fblog.johncrepezzi.com%2Farchives%2F87&amp;title=Office%20Duties&amp;annotation=By%20far%20my%20favorite%20part%20of%20programming%20is%20little%20scripts%20that%20perform%20functions%20that%20save%20people%20time.%20%20This%20convenient%20PHP%20script%20allows%20for%20rotation%20of%20office%20duties%20on%20a%20regular%20basis.%20%20Its%20quick%20and%20dirty%2C%20but%20it%20does%20its%20job%20well.%20%20It%20even%20works" title="Google Bookmarks"><img src="http://blog.johncrepezzi.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://blog.johncrepezzi.com/archives/87/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
