<?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>Werx Limited &#187; software development</title> <atom:link href="http://werxltd.com/wp/category/software-development/feed/" rel="self" type="application/rss+xml" /><link>http://werxltd.com/wp</link> <description>We make IT work.</description> <lastBuildDate>Mon, 23 Jan 2012 23:03:59 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.1</generator> <item><title>node.js at Facebook</title><link>http://werxltd.com/wp/2012/01/23/node-js-at-facebook/</link> <comments>http://werxltd.com/wp/2012/01/23/node-js-at-facebook/#comments</comments> <pubDate>Mon, 23 Jan 2012 14:18:24 +0000</pubDate> <dc:creator>wes</dc:creator> <category><![CDATA[it industry]]></category> <category><![CDATA[javascript]]></category> <category><![CDATA[facebook]]></category> <category><![CDATA[node.js]]></category> <category><![CDATA[scale]]></category><guid
isPermaLink="false">http://werxltd.com/wp/?p=1148</guid> <description><![CDATA[Slides No related content found.]]></description> <content:encoded><![CDATA[<p><iframe
src="http://blip.tv/play/g_MngtCYdgI.html?p=1" width="480" height="346" frameborder="0" allowfullscreen></iframe><embed
type="application/x-shockwave-flash" src="http://a.blip.tv/api.swf#g_MngtCYdgI" style="display:none"></embed></p><p><a
href="http://broofa.com/presentations/FacebookAtNode_NodeConf2011.pdf">Slides</a></p><div
class="betterrelated none"><p>No related content found.</p></div><p><!--[if IE]><iframe
frameborder="0" allowTransparency="true" class="addtoany_special_service facebook_like" src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwerxltd.com%2Fwp%2F2012%2F01%2F23%2Fnode-js-at-facebook%2F&amp;layout=button_count&amp;show_faces=false&amp;width=75&amp;action=like&amp;colorscheme=light&amp;height=20&amp;ref=addtoany" scrolling="no" style="border:none;overflow:hidden;width:90px;height:21px"></iframe><![endif]--><!--[if !IE]><!--><iframe
class="addtoany_special_service facebook_like" src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwerxltd.com%2Fwp%2F2012%2F01%2F23%2Fnode-js-at-facebook%2F&amp;layout=button_count&amp;show_faces=false&amp;width=75&amp;action=like&amp;colorscheme=light&amp;height=20&amp;ref=addtoany" scrolling="no" style="border:none;overflow:hidden;width:90px;height:21px"></iframe><!--<![endif]--><!--[if IE]><iframe
frameborder="0" allowTransparency="true" class="addtoany_special_service twitter_tweet" src="http://platform.twitter.com/widgets/tweet_button.html?url=http%3A%2F%2Fwerxltd.com%2Fwp%2F2012%2F01%2F23%2Fnode-js-at-facebook%2F&amp;counturl=http%3A%2F%2Fwerxltd.com%2Fwp%2F2012%2F01%2F23%2Fnode-js-at-facebook%2F&amp;count=none&amp;text=node.js%20at%20Facebook" scrolling="no" style="border:none;overflow:hidden;width:55px;height:20px"></iframe><![endif]--><!--[if !IE]><!--><iframe
class="addtoany_special_service twitter_tweet" src="http://platform.twitter.com/widgets/tweet_button.html?url=http%3A%2F%2Fwerxltd.com%2Fwp%2F2012%2F01%2F23%2Fnode-js-at-facebook%2F&amp;counturl=http%3A%2F%2Fwerxltd.com%2Fwp%2F2012%2F01%2F23%2Fnode-js-at-facebook%2F&amp;count=none&amp;text=node.js%20at%20Facebook" scrolling="no" style="border:none;overflow:hidden;width:55px;height:20px"></iframe><!--<![endif]--><!--[if IE]><iframe
frameborder="0" allowTransparency="true" class="addtoany_special_service google_plusone" src="https://plusone.google.com/u/0/_/%2B1/fastbutton?url=http%3A%2F%2Fwerxltd.com%2Fwp%2F2012%2F01%2F23%2Fnode-js-at-facebook%2F&amp;size=medium&amp;count=false" scrolling="no" style="border:none;overflow:hidden;width:32px;height:20px"></iframe><![endif]--><!--[if !IE]><!--><iframe
class="addtoany_special_service google_plusone" src="https://plusone.google.com/u/0/_/%2B1/fastbutton?url=http%3A%2F%2Fwerxltd.com%2Fwp%2F2012%2F01%2F23%2Fnode-js-at-facebook%2F&amp;size=medium&amp;count=false" scrolling="no" style="border:none;overflow:hidden;width:32px;height:20px"></iframe><!--<![endif]--><a
class="a2a_button_linkedin" href="http://www.addtoany.com/add_to/linkedin?linkurl=http%3A%2F%2Fwerxltd.com%2Fwp%2F2012%2F01%2F23%2Fnode-js-at-facebook%2F&amp;linkname=node.js%20at%20Facebook" title="LinkedIn" rel="nofollow" target="_blank"><img
src="http://werxltd.com/wp/wp-content/plugins/add-to-any/icons/linkedin.png?9d7bd4" width="16" height="16" alt="LinkedIn"/></a><a
class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwerxltd.com%2Fwp%2F2012%2F01%2F23%2Fnode-js-at-facebook%2F&amp;title=node.js%20at%20Facebook" id="wpa2a_2">Share/Save</a></p>]]></content:encoded> <wfw:commentRss>http://werxltd.com/wp/2012/01/23/node-js-at-facebook/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Simple init.d script template</title><link>http://werxltd.com/wp/2012/01/05/simple-init-d-script-template/</link> <comments>http://werxltd.com/wp/2012/01/05/simple-init-d-script-template/#comments</comments> <pubDate>Thu, 05 Jan 2012 19:25:24 +0000</pubDate> <dc:creator>wes</dc:creator> <category><![CDATA[bash]]></category> <category><![CDATA[hosting]]></category> <category><![CDATA[administration]]></category> <category><![CDATA[daemon]]></category> <category><![CDATA[init.d]]></category> <category><![CDATA[script]]></category> <category><![CDATA[startup]]></category> <category><![CDATA[system]]></category><guid
isPermaLink="false">http://werxltd.com/wp/?p=1077</guid> <description><![CDATA[Recently I found the need to create an init.d script and since I had a hard time finding an example elsewhere1, here&#8217;s the overly simple script I came up with to get the job done: #!/bin/bash # myapp daemon # chkconfig: 345 20 80 # description: myapp daemon # processname: myapp DAEMON_PATH="/home/wes/Development/projects/myapp" DAEMON=myapp DAEMONOPTS="-my opts" [...]]]></description> <content:encoded><![CDATA[<p>Recently I found the need to create an init.d script and since I had a hard time finding an example elsewhere<sup><a
href="http://werxltd.com/wp/2012/01/05/simple-init-d-script-template/#footnote_0_1077" id="identifier_0_1077" class="footnote-link footnote-identifier-link" title="That said, if you know of such an example I&amp;#8217;d love to hear from you.">1</a></sup>, here&#8217;s the overly simple script I came up with to get the job done:</p><pre class="brush:bash">
#!/bin/bash
# myapp daemon
# chkconfig: 345 20 80
# description: myapp daemon
# processname: myapp

DAEMON_PATH="/home/wes/Development/projects/myapp"

DAEMON=myapp
DAEMONOPTS="-my opts"

NAME=myapp
DESC="My daemon description"
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME

case "$1" in
start)
	printf "%-50s" "Starting $NAME..."
	cd $DAEMON_PATH
	PID=`$DAEMON $DAEMONOPTS > /dev/null 2>&#038;1 &#038; echo $!`
	#echo "Saving PID" $PID " to " $PIDFILE
        if [ -z $PID ]; then
            printf "%s\n" "Fail"
        else
            echo $PID > $PIDFILE
            printf "%s\n" "Ok"
        fi
;;
status)
        printf "%-50s" "Checking $NAME..."
        if [ -f $PIDFILE ]; then
            PID=`cat $PIDFILE`
            if [ -z `ps axf | grep 5003 | grep -v grep` ]; then
                printf "%s\n" "Process dead but pidfile exists"
            else
                echo "Running"
            fi
        else
            printf "%s\n" "Service not running"
        fi
;;
stop)
        printf "%-50s" "Stopping $NAME"
            PID=`cat $PIDFILE`
            cd $DAEMON_PATH
        if [ -f $PIDFILE ]; then
            kill -HUP $PID
            printf "%s\n" "Ok"
            rm -rf $PIDFILE
        else
            printf "%s\n" "pidfile not found"
        fi
;;

restart)
  	$0 stop
  	$0 start
;;

*)
        echo "Usage: $0 {status|start|stop|restart}"
        exit 1
esac
</pre><p>This script will work in /etc/init.d on Xubuntu 11.10 (so most Debian-based systems) and CentOS 5.5 and you can control it via chkconfig.</p><div
class="betterrelated none"><p>No related content found.</p></div><ol
class="footnotes"><li
id="footnote_0_1077" class="footnote">That said, if you know of such an example I&#8217;d love to hear from you.</li></ol><p><!--[if IE]><iframe
frameborder="0" allowTransparency="true" class="addtoany_special_service facebook_like" src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwerxltd.com%2Fwp%2F2012%2F01%2F05%2Fsimple-init-d-script-template%2F&amp;layout=button_count&amp;show_faces=false&amp;width=75&amp;action=like&amp;colorscheme=light&amp;height=20&amp;ref=addtoany" scrolling="no" style="border:none;overflow:hidden;width:90px;height:21px"></iframe><![endif]--><!--[if !IE]><!--><iframe
class="addtoany_special_service facebook_like" src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwerxltd.com%2Fwp%2F2012%2F01%2F05%2Fsimple-init-d-script-template%2F&amp;layout=button_count&amp;show_faces=false&amp;width=75&amp;action=like&amp;colorscheme=light&amp;height=20&amp;ref=addtoany" scrolling="no" style="border:none;overflow:hidden;width:90px;height:21px"></iframe><!--<![endif]--><!--[if IE]><iframe
frameborder="0" allowTransparency="true" class="addtoany_special_service twitter_tweet" src="http://platform.twitter.com/widgets/tweet_button.html?url=http%3A%2F%2Fwerxltd.com%2Fwp%2F2012%2F01%2F05%2Fsimple-init-d-script-template%2F&amp;counturl=http%3A%2F%2Fwerxltd.com%2Fwp%2F2012%2F01%2F05%2Fsimple-init-d-script-template%2F&amp;count=none&amp;text=Simple%20init.d%20script%20template" scrolling="no" style="border:none;overflow:hidden;width:55px;height:20px"></iframe><![endif]--><!--[if !IE]><!--><iframe
class="addtoany_special_service twitter_tweet" src="http://platform.twitter.com/widgets/tweet_button.html?url=http%3A%2F%2Fwerxltd.com%2Fwp%2F2012%2F01%2F05%2Fsimple-init-d-script-template%2F&amp;counturl=http%3A%2F%2Fwerxltd.com%2Fwp%2F2012%2F01%2F05%2Fsimple-init-d-script-template%2F&amp;count=none&amp;text=Simple%20init.d%20script%20template" scrolling="no" style="border:none;overflow:hidden;width:55px;height:20px"></iframe><!--<![endif]--><!--[if IE]><iframe
frameborder="0" allowTransparency="true" class="addtoany_special_service google_plusone" src="https://plusone.google.com/u/0/_/%2B1/fastbutton?url=http%3A%2F%2Fwerxltd.com%2Fwp%2F2012%2F01%2F05%2Fsimple-init-d-script-template%2F&amp;size=medium&amp;count=false" scrolling="no" style="border:none;overflow:hidden;width:32px;height:20px"></iframe><![endif]--><!--[if !IE]><!--><iframe
class="addtoany_special_service google_plusone" src="https://plusone.google.com/u/0/_/%2B1/fastbutton?url=http%3A%2F%2Fwerxltd.com%2Fwp%2F2012%2F01%2F05%2Fsimple-init-d-script-template%2F&amp;size=medium&amp;count=false" scrolling="no" style="border:none;overflow:hidden;width:32px;height:20px"></iframe><!--<![endif]--><a
class="a2a_button_linkedin" href="http://www.addtoany.com/add_to/linkedin?linkurl=http%3A%2F%2Fwerxltd.com%2Fwp%2F2012%2F01%2F05%2Fsimple-init-d-script-template%2F&amp;linkname=Simple%20init.d%20script%20template" title="LinkedIn" rel="nofollow" target="_blank"><img
src="http://werxltd.com/wp/wp-content/plugins/add-to-any/icons/linkedin.png?9d7bd4" width="16" height="16" alt="LinkedIn"/></a><a
class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwerxltd.com%2Fwp%2F2012%2F01%2F05%2Fsimple-init-d-script-template%2F&amp;title=Simple%20init.d%20script%20template" id="wpa2a_4">Share/Save</a></p>]]></content:encoded> <wfw:commentRss>http://werxltd.com/wp/2012/01/05/simple-init-d-script-template/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Fun with jsonselect</title><link>http://werxltd.com/wp/2011/11/16/fun-with-jsonselect/</link> <comments>http://werxltd.com/wp/2011/11/16/fun-with-jsonselect/#comments</comments> <pubDate>Wed, 16 Nov 2011 16:39:07 +0000</pubDate> <dc:creator>wes</dc:creator> <category><![CDATA[javascript]]></category> <category><![CDATA[css]]></category> <category><![CDATA[json]]></category> <category><![CDATA[jsonselect]]></category> <category><![CDATA[noschema]]></category> <category><![CDATA[selector]]></category><guid
isPermaLink="false">http://werxltd.com/wp/?p=1063</guid> <description><![CDATA[One of the strengths of CSS and jQuery is that it provides a common and powerful mechanism known as a selector language for referencing bits of data, especially data whose structure is not exactly known at runtime which makes such an addressing scheme a perfect fit for the often lumpy world of HTML. Increasingly JSON [...]]]></description> <content:encoded><![CDATA[<p>One of the strengths of CSS and jQuery is that it provides a common and powerful mechanism known as a selector language for referencing bits of data, especially data whose structure is not exactly known at runtime which makes such an addressing scheme a perfect fit for the often lumpy world of HTML.</p><p>Increasingly JSON is being used as a transport medium for data and with the rise of NoSQL solutions, having a selector language for JSON makes a lot of sense when dealing with JSON documents whose structure isn&#8217;t deterministic.</p><p><a
href="http://jsonselect.org/">JSONSelect</a> provides a good implementation of just such a JSON selector language but after working with it on a project I found myself needing to do more than it allowed me to do. Namely, I wanted 1. to be able to perform a selection and receive matching paths instead of the data contained in those paths and I wanted 2. to be able to modify data specified at a path location in-place.</p><pre class="brush:javascript">
jsonselect.match(sel, obj, asPath); // Added the asPath flag to return a path instead of the values
jsonselect.forEach(sel, obj, fun, asPath); // Added the same flag to forEach, I use this to
jsonselect.get(path,obj); // For getting the value using a path
jsonselect.set(path, value, obj); // For setting the value of a path
jsonselect.del(path,root); // For deleting a path
</pre><p><a
href="http://werxltd.com/wp/wp-content/uploads/2011/11/jsonselect.js?9d7bd4">Here is my modified version of jsonselect</a> in case anyone needs help solving the same problems I mentioned above.</p><div
class="betterrelated none"><p>No related content found.</p></div><p><!--[if IE]><iframe
frameborder="0" allowTransparency="true" class="addtoany_special_service facebook_like" src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwerxltd.com%2Fwp%2F2011%2F11%2F16%2Ffun-with-jsonselect%2F&amp;layout=button_count&amp;show_faces=false&amp;width=75&amp;action=like&amp;colorscheme=light&amp;height=20&amp;ref=addtoany" scrolling="no" style="border:none;overflow:hidden;width:90px;height:21px"></iframe><![endif]--><!--[if !IE]><!--><iframe
class="addtoany_special_service facebook_like" src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwerxltd.com%2Fwp%2F2011%2F11%2F16%2Ffun-with-jsonselect%2F&amp;layout=button_count&amp;show_faces=false&amp;width=75&amp;action=like&amp;colorscheme=light&amp;height=20&amp;ref=addtoany" scrolling="no" style="border:none;overflow:hidden;width:90px;height:21px"></iframe><!--<![endif]--><!--[if IE]><iframe
frameborder="0" allowTransparency="true" class="addtoany_special_service twitter_tweet" src="http://platform.twitter.com/widgets/tweet_button.html?url=http%3A%2F%2Fwerxltd.com%2Fwp%2F2011%2F11%2F16%2Ffun-with-jsonselect%2F&amp;counturl=http%3A%2F%2Fwerxltd.com%2Fwp%2F2011%2F11%2F16%2Ffun-with-jsonselect%2F&amp;count=none&amp;text=Fun%20with%20jsonselect" scrolling="no" style="border:none;overflow:hidden;width:55px;height:20px"></iframe><![endif]--><!--[if !IE]><!--><iframe
class="addtoany_special_service twitter_tweet" src="http://platform.twitter.com/widgets/tweet_button.html?url=http%3A%2F%2Fwerxltd.com%2Fwp%2F2011%2F11%2F16%2Ffun-with-jsonselect%2F&amp;counturl=http%3A%2F%2Fwerxltd.com%2Fwp%2F2011%2F11%2F16%2Ffun-with-jsonselect%2F&amp;count=none&amp;text=Fun%20with%20jsonselect" scrolling="no" style="border:none;overflow:hidden;width:55px;height:20px"></iframe><!--<![endif]--><!--[if IE]><iframe
frameborder="0" allowTransparency="true" class="addtoany_special_service google_plusone" src="https://plusone.google.com/u/0/_/%2B1/fastbutton?url=http%3A%2F%2Fwerxltd.com%2Fwp%2F2011%2F11%2F16%2Ffun-with-jsonselect%2F&amp;size=medium&amp;count=false" scrolling="no" style="border:none;overflow:hidden;width:32px;height:20px"></iframe><![endif]--><!--[if !IE]><!--><iframe
class="addtoany_special_service google_plusone" src="https://plusone.google.com/u/0/_/%2B1/fastbutton?url=http%3A%2F%2Fwerxltd.com%2Fwp%2F2011%2F11%2F16%2Ffun-with-jsonselect%2F&amp;size=medium&amp;count=false" scrolling="no" style="border:none;overflow:hidden;width:32px;height:20px"></iframe><!--<![endif]--><a
class="a2a_button_linkedin" href="http://www.addtoany.com/add_to/linkedin?linkurl=http%3A%2F%2Fwerxltd.com%2Fwp%2F2011%2F11%2F16%2Ffun-with-jsonselect%2F&amp;linkname=Fun%20with%20jsonselect" title="LinkedIn" rel="nofollow" target="_blank"><img
src="http://werxltd.com/wp/wp-content/plugins/add-to-any/icons/linkedin.png?9d7bd4" width="16" height="16" alt="LinkedIn"/></a><a
class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwerxltd.com%2Fwp%2F2011%2F11%2F16%2Ffun-with-jsonselect%2F&amp;title=Fun%20with%20jsonselect" id="wpa2a_6">Share/Save</a></p>]]></content:encoded> <wfw:commentRss>http://werxltd.com/wp/2011/11/16/fun-with-jsonselect/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Finding yesterday&#8217;s beginning and ending unix timestamp</title><link>http://werxltd.com/wp/2011/08/25/finding-yesterdays-beginning-and-ending-unix-timestamp/</link> <comments>http://werxltd.com/wp/2011/08/25/finding-yesterdays-beginning-and-ending-unix-timestamp/#comments</comments> <pubDate>Thu, 25 Aug 2011 20:03:58 +0000</pubDate> <dc:creator>wes</dc:creator> <category><![CDATA[python]]></category> <category><![CDATA[data]]></category> <category><![CDATA[data management]]></category> <category><![CDATA[database]]></category> <category><![CDATA[reports]]></category><guid
isPermaLink="false">http://werxltd.com/wp/?p=1047</guid> <description><![CDATA[When writing reports I&#8217;ve often come across the need to find the unix timestamp beginning and end of a day. Here is a Python snippet that does just that. yesterday = datetime.datetime.now() - datetime.timedelta(days = 1) yesterday_beginning = datetime.datetime(yesterday.year, yesterday.month, yesterday.day,0,0,0,0) yesterday_beginning_time = int(time.mktime(yesterday_beginning.timetuple())) yesterday_end = datetime.datetime(yesterday.year, yesterday.month, yesterday.day,23,59,59,999) yesterday_end_time = int(time.mktime(yesterday_end.timetuple())) print yesterday_beginning_time print [...]]]></description> <content:encoded><![CDATA[<p>When writing reports I&#8217;ve often come across the need to find the unix timestamp beginning and end of a day. Here is a Python snippet that does just that.</p><pre class="brush:python">
yesterday = datetime.datetime.now() - datetime.timedelta(days = 1)
yesterday_beginning = datetime.datetime(yesterday.year, yesterday.month, yesterday.day,0,0,0,0)
yesterday_beginning_time = int(time.mktime(yesterday_beginning.timetuple()))
yesterday_end = datetime.datetime(yesterday.year, yesterday.month, yesterday.day,23,59,59,999)
yesterday_end_time = int(time.mktime(yesterday_end.timetuple()))

print yesterday_beginning_time
print yesterday_end_time
</pre><div
class="betterrelated none"><p>No related content found.</p></div><p><!--[if IE]><iframe
frameborder="0" allowTransparency="true" class="addtoany_special_service facebook_like" src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwerxltd.com%2Fwp%2F2011%2F08%2F25%2Ffinding-yesterdays-beginning-and-ending-unix-timestamp%2F&amp;layout=button_count&amp;show_faces=false&amp;width=75&amp;action=like&amp;colorscheme=light&amp;height=20&amp;ref=addtoany" scrolling="no" style="border:none;overflow:hidden;width:90px;height:21px"></iframe><![endif]--><!--[if !IE]><!--><iframe
class="addtoany_special_service facebook_like" src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwerxltd.com%2Fwp%2F2011%2F08%2F25%2Ffinding-yesterdays-beginning-and-ending-unix-timestamp%2F&amp;layout=button_count&amp;show_faces=false&amp;width=75&amp;action=like&amp;colorscheme=light&amp;height=20&amp;ref=addtoany" scrolling="no" style="border:none;overflow:hidden;width:90px;height:21px"></iframe><!--<![endif]--><!--[if IE]><iframe
frameborder="0" allowTransparency="true" class="addtoany_special_service twitter_tweet" src="http://platform.twitter.com/widgets/tweet_button.html?url=http%3A%2F%2Fwerxltd.com%2Fwp%2F2011%2F08%2F25%2Ffinding-yesterdays-beginning-and-ending-unix-timestamp%2F&amp;counturl=http%3A%2F%2Fwerxltd.com%2Fwp%2F2011%2F08%2F25%2Ffinding-yesterdays-beginning-and-ending-unix-timestamp%2F&amp;count=none&amp;text=Finding%20yesterday%26%238217%3Bs%20beginning%20and%20ending%20unix%20timestamp" scrolling="no" style="border:none;overflow:hidden;width:55px;height:20px"></iframe><![endif]--><!--[if !IE]><!--><iframe
class="addtoany_special_service twitter_tweet" src="http://platform.twitter.com/widgets/tweet_button.html?url=http%3A%2F%2Fwerxltd.com%2Fwp%2F2011%2F08%2F25%2Ffinding-yesterdays-beginning-and-ending-unix-timestamp%2F&amp;counturl=http%3A%2F%2Fwerxltd.com%2Fwp%2F2011%2F08%2F25%2Ffinding-yesterdays-beginning-and-ending-unix-timestamp%2F&amp;count=none&amp;text=Finding%20yesterday%26%238217%3Bs%20beginning%20and%20ending%20unix%20timestamp" scrolling="no" style="border:none;overflow:hidden;width:55px;height:20px"></iframe><!--<![endif]--><!--[if IE]><iframe
frameborder="0" allowTransparency="true" class="addtoany_special_service google_plusone" src="https://plusone.google.com/u/0/_/%2B1/fastbutton?url=http%3A%2F%2Fwerxltd.com%2Fwp%2F2011%2F08%2F25%2Ffinding-yesterdays-beginning-and-ending-unix-timestamp%2F&amp;size=medium&amp;count=false" scrolling="no" style="border:none;overflow:hidden;width:32px;height:20px"></iframe><![endif]--><!--[if !IE]><!--><iframe
class="addtoany_special_service google_plusone" src="https://plusone.google.com/u/0/_/%2B1/fastbutton?url=http%3A%2F%2Fwerxltd.com%2Fwp%2F2011%2F08%2F25%2Ffinding-yesterdays-beginning-and-ending-unix-timestamp%2F&amp;size=medium&amp;count=false" scrolling="no" style="border:none;overflow:hidden;width:32px;height:20px"></iframe><!--<![endif]--><a
class="a2a_button_linkedin" href="http://www.addtoany.com/add_to/linkedin?linkurl=http%3A%2F%2Fwerxltd.com%2Fwp%2F2011%2F08%2F25%2Ffinding-yesterdays-beginning-and-ending-unix-timestamp%2F&amp;linkname=Finding%20yesterday%26%238217%3Bs%20beginning%20and%20ending%20unix%20timestamp" title="LinkedIn" rel="nofollow" target="_blank"><img
src="http://werxltd.com/wp/wp-content/plugins/add-to-any/icons/linkedin.png?9d7bd4" width="16" height="16" alt="LinkedIn"/></a><a
class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwerxltd.com%2Fwp%2F2011%2F08%2F25%2Ffinding-yesterdays-beginning-and-ending-unix-timestamp%2F&amp;title=Finding%20yesterday%26%238217%3Bs%20beginning%20and%20ending%20unix%20timestamp" id="wpa2a_8">Share/Save</a></p>]]></content:encoded> <wfw:commentRss>http://werxltd.com/wp/2011/08/25/finding-yesterdays-beginning-and-ending-unix-timestamp/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Check an array for all null values</title><link>http://werxltd.com/wp/2011/06/13/check-an-array-for-all-null-values/</link> <comments>http://werxltd.com/wp/2011/06/13/check-an-array-for-all-null-values/#comments</comments> <pubDate>Mon, 13 Jun 2011 20:38:00 +0000</pubDate> <dc:creator>wes</dc:creator> <category><![CDATA[php]]></category> <category><![CDATA[software development]]></category> <category><![CDATA[function]]></category> <category><![CDATA[null]]></category> <category><![CDATA[utility]]></category><guid
isPermaLink="false">http://werxltd.com/wp/?p=978</guid> <description><![CDATA[Here is a simple function to check an array to see if it contains all null values. function allNulls($arr) { if(is_array($arr) &#038;&#038; count(array_diff($arr, array(null))) == 0) { return true; } return false; } echo (allNulls(array(null,null,null)) ? "true" : "false") . PHP_EOL; echo (allNulls(array(null,1,null)) ? "true" : "false") . PHP_EOL; echo (allNulls(array("test",null,null)) ? "true" : "false") [...]]]></description> <content:encoded><![CDATA[<p>Here is a simple function to check an array to see if it contains all null values.</p><pre class="brush:php">
function allNulls($arr) {
    if(is_array($arr) &#038;&#038; count(array_diff($arr, array(null))) == 0) {
            return true;
    }

    return false;
}

echo (allNulls(array(null,null,null)) ? "true" : "false") . PHP_EOL;
echo (allNulls(array(null,1,null)) ? "true" : "false") . PHP_EOL;
echo (allNulls(array("test",null,null)) ? "true" : "false") . PHP_EOL;
echo (allNulls(array("",null,null)) ? "true" : "false") . PHP_EOL;
echo (allNulls(array(0,null,null)) ? "true" : "false") . PHP_EOL;
</pre><div
class="betterrelated none"><p>No related content found.</p></div><p><!--[if IE]><iframe
frameborder="0" allowTransparency="true" class="addtoany_special_service facebook_like" src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwerxltd.com%2Fwp%2F2011%2F06%2F13%2Fcheck-an-array-for-all-null-values%2F&amp;layout=button_count&amp;show_faces=false&amp;width=75&amp;action=like&amp;colorscheme=light&amp;height=20&amp;ref=addtoany" scrolling="no" style="border:none;overflow:hidden;width:90px;height:21px"></iframe><![endif]--><!--[if !IE]><!--><iframe
class="addtoany_special_service facebook_like" src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwerxltd.com%2Fwp%2F2011%2F06%2F13%2Fcheck-an-array-for-all-null-values%2F&amp;layout=button_count&amp;show_faces=false&amp;width=75&amp;action=like&amp;colorscheme=light&amp;height=20&amp;ref=addtoany" scrolling="no" style="border:none;overflow:hidden;width:90px;height:21px"></iframe><!--<![endif]--><!--[if IE]><iframe
frameborder="0" allowTransparency="true" class="addtoany_special_service twitter_tweet" src="http://platform.twitter.com/widgets/tweet_button.html?url=http%3A%2F%2Fwerxltd.com%2Fwp%2F2011%2F06%2F13%2Fcheck-an-array-for-all-null-values%2F&amp;counturl=http%3A%2F%2Fwerxltd.com%2Fwp%2F2011%2F06%2F13%2Fcheck-an-array-for-all-null-values%2F&amp;count=none&amp;text=Check%20an%20array%20for%20all%20null%20values" scrolling="no" style="border:none;overflow:hidden;width:55px;height:20px"></iframe><![endif]--><!--[if !IE]><!--><iframe
class="addtoany_special_service twitter_tweet" src="http://platform.twitter.com/widgets/tweet_button.html?url=http%3A%2F%2Fwerxltd.com%2Fwp%2F2011%2F06%2F13%2Fcheck-an-array-for-all-null-values%2F&amp;counturl=http%3A%2F%2Fwerxltd.com%2Fwp%2F2011%2F06%2F13%2Fcheck-an-array-for-all-null-values%2F&amp;count=none&amp;text=Check%20an%20array%20for%20all%20null%20values" scrolling="no" style="border:none;overflow:hidden;width:55px;height:20px"></iframe><!--<![endif]--><!--[if IE]><iframe
frameborder="0" allowTransparency="true" class="addtoany_special_service google_plusone" src="https://plusone.google.com/u/0/_/%2B1/fastbutton?url=http%3A%2F%2Fwerxltd.com%2Fwp%2F2011%2F06%2F13%2Fcheck-an-array-for-all-null-values%2F&amp;size=medium&amp;count=false" scrolling="no" style="border:none;overflow:hidden;width:32px;height:20px"></iframe><![endif]--><!--[if !IE]><!--><iframe
class="addtoany_special_service google_plusone" src="https://plusone.google.com/u/0/_/%2B1/fastbutton?url=http%3A%2F%2Fwerxltd.com%2Fwp%2F2011%2F06%2F13%2Fcheck-an-array-for-all-null-values%2F&amp;size=medium&amp;count=false" scrolling="no" style="border:none;overflow:hidden;width:32px;height:20px"></iframe><!--<![endif]--><a
class="a2a_button_linkedin" href="http://www.addtoany.com/add_to/linkedin?linkurl=http%3A%2F%2Fwerxltd.com%2Fwp%2F2011%2F06%2F13%2Fcheck-an-array-for-all-null-values%2F&amp;linkname=Check%20an%20array%20for%20all%20null%20values" title="LinkedIn" rel="nofollow" target="_blank"><img
src="http://werxltd.com/wp/wp-content/plugins/add-to-any/icons/linkedin.png?9d7bd4" width="16" height="16" alt="LinkedIn"/></a><a
class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwerxltd.com%2Fwp%2F2011%2F06%2F13%2Fcheck-an-array-for-all-null-values%2F&amp;title=Check%20an%20array%20for%20all%20null%20values" id="wpa2a_10">Share/Save</a></p>]]></content:encoded> <wfw:commentRss>http://werxltd.com/wp/2011/06/13/check-an-array-for-all-null-values/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Simple PHP Proxy</title><link>http://werxltd.com/wp/2011/05/24/simple-php-proxy/</link> <comments>http://werxltd.com/wp/2011/05/24/simple-php-proxy/#comments</comments> <pubDate>Tue, 24 May 2011 12:00:17 +0000</pubDate> <dc:creator>wes</dc:creator> <category><![CDATA[php]]></category> <category><![CDATA[proxy]]></category><guid
isPermaLink="false">http://werxltd.com/wp/?p=765</guid> <description><![CDATA[While developing apps that use external web services, a proxy often comes in handy in order to bypass the pesky XSS security settings found in most browsers. Here is a simple PHP proxy I&#8217;ve found quite helpful.]]></description> <content:encoded><![CDATA[<p>While developing apps that use external web services, a proxy often comes in handy in order to bypass the pesky XSS security settings found in most browsers. Here is a simple PHP proxy I&#8217;ve found quite helpful.</p><pre class="brush:php">
<?

// http://benalman.com/projects/php-simple-proxy/

$url = "http://mcaf.ee/api/shorten";

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
curl_setopt($ch, CURLOPT_FORBID_REUSE, true);
curl_setopt($ch, CURLOPT_MAXCONNECTS, 16);
curl_setopt($ch, CURLOPT_ENCODING, "gzip");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($_REQUEST));
$result = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$type = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
curl_close($ch);  

if(!is_null($type)) $type = 'text/html';
header('Content-Type: '.$type);

switch($status) {
        case 500:
                header("HTTP/1.1 500 Internal Server Error");
                header("Cache-Control: no-cache");
        break;
        case 200:
        default:
                header("HTTP/1.1 200 OK");
        break;
}

echo $result;
</pre><div
class="betterrelated none"><p>No related content found.</p></div><p><!--[if IE]><iframe
frameborder="0" allowTransparency="true" class="addtoany_special_service facebook_like" src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwerxltd.com%2Fwp%2F2011%2F05%2F24%2Fsimple-php-proxy%2F&amp;layout=button_count&amp;show_faces=false&amp;width=75&amp;action=like&amp;colorscheme=light&amp;height=20&amp;ref=addtoany" scrolling="no" style="border:none;overflow:hidden;width:90px;height:21px"></iframe><![endif]--><!--[if !IE]><!--><iframe
class="addtoany_special_service facebook_like" src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwerxltd.com%2Fwp%2F2011%2F05%2F24%2Fsimple-php-proxy%2F&amp;layout=button_count&amp;show_faces=false&amp;width=75&amp;action=like&amp;colorscheme=light&amp;height=20&amp;ref=addtoany" scrolling="no" style="border:none;overflow:hidden;width:90px;height:21px"></iframe><!--<![endif]--><!--[if IE]><iframe
frameborder="0" allowTransparency="true" class="addtoany_special_service twitter_tweet" src="http://platform.twitter.com/widgets/tweet_button.html?url=http%3A%2F%2Fwerxltd.com%2Fwp%2F2011%2F05%2F24%2Fsimple-php-proxy%2F&amp;counturl=http%3A%2F%2Fwerxltd.com%2Fwp%2F2011%2F05%2F24%2Fsimple-php-proxy%2F&amp;count=none&amp;text=Simple%20PHP%20Proxy" scrolling="no" style="border:none;overflow:hidden;width:55px;height:20px"></iframe><![endif]--><!--[if !IE]><!--><iframe
class="addtoany_special_service twitter_tweet" src="http://platform.twitter.com/widgets/tweet_button.html?url=http%3A%2F%2Fwerxltd.com%2Fwp%2F2011%2F05%2F24%2Fsimple-php-proxy%2F&amp;counturl=http%3A%2F%2Fwerxltd.com%2Fwp%2F2011%2F05%2F24%2Fsimple-php-proxy%2F&amp;count=none&amp;text=Simple%20PHP%20Proxy" scrolling="no" style="border:none;overflow:hidden;width:55px;height:20px"></iframe><!--<![endif]--><!--[if IE]><iframe
frameborder="0" allowTransparency="true" class="addtoany_special_service google_plusone" src="https://plusone.google.com/u/0/_/%2B1/fastbutton?url=http%3A%2F%2Fwerxltd.com%2Fwp%2F2011%2F05%2F24%2Fsimple-php-proxy%2F&amp;size=medium&amp;count=false" scrolling="no" style="border:none;overflow:hidden;width:32px;height:20px"></iframe><![endif]--><!--[if !IE]><!--><iframe
class="addtoany_special_service google_plusone" src="https://plusone.google.com/u/0/_/%2B1/fastbutton?url=http%3A%2F%2Fwerxltd.com%2Fwp%2F2011%2F05%2F24%2Fsimple-php-proxy%2F&amp;size=medium&amp;count=false" scrolling="no" style="border:none;overflow:hidden;width:32px;height:20px"></iframe><!--<![endif]--><a
class="a2a_button_linkedin" href="http://www.addtoany.com/add_to/linkedin?linkurl=http%3A%2F%2Fwerxltd.com%2Fwp%2F2011%2F05%2F24%2Fsimple-php-proxy%2F&amp;linkname=Simple%20PHP%20Proxy" title="LinkedIn" rel="nofollow" target="_blank"><img
src="http://werxltd.com/wp/wp-content/plugins/add-to-any/icons/linkedin.png?9d7bd4" width="16" height="16" alt="LinkedIn"/></a><a
class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwerxltd.com%2Fwp%2F2011%2F05%2F24%2Fsimple-php-proxy%2F&amp;title=Simple%20PHP%20Proxy" id="wpa2a_12">Share/Save</a></p>]]></content:encoded> <wfw:commentRss>http://werxltd.com/wp/2011/05/24/simple-php-proxy/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Dividing a file into chunks along line endings in Erlang</title><link>http://werxltd.com/wp/2011/05/23/dividing-a-file-into-chunks-along-line-endings-in-erlang/</link> <comments>http://werxltd.com/wp/2011/05/23/dividing-a-file-into-chunks-along-line-endings-in-erlang/#comments</comments> <pubDate>Mon, 23 May 2011 12:26:38 +0000</pubDate> <dc:creator>wes</dc:creator> <category><![CDATA[erlang]]></category><guid
isPermaLink="false">http://werxltd.com/wp/?p=967</guid> <description><![CDATA[I&#8217;ve been dabbling in Erlang recently. I&#8217;ve wanted to learn a functional programming language for a while now and Erlang&#8217;s concurrency make it rather attractive. For my &#8220;hello world&#8221; app, I decided to write a simple log parser which processes chunks of a file in parallel. Here is a part of that app which produces [...]]]></description> <content:encoded><![CDATA[<p>I&#8217;ve been dabbling in Erlang recently. I&#8217;ve wanted to learn a functional programming language for a while now and Erlang&#8217;s concurrency make it rather attractive.</p><p>For my &#8220;hello world&#8221; app, I decided to write a simple log parser which processes chunks of a file in parallel. Here is a part of that app which produces a list of tuples which describes the chunks adjusted to the nearest newline (Unix newlines, \n, in this case).</p><pre  class="brush:plain">
getChunkDivisions(File, 0, Chunksize, ChunkDivisions) ->
	[{chunk,0,Chunksize}|ChunkDivisions];
getChunkDivisions(File, Size, Chunksize, ChunkDivisions) ->
	if
		Size-Chunksize=<0 ->
			ComputedChunkEnd = Chunksize-(Chunksize-Size),
			CorrectedChunkEnd = walkToNextLineBreak(File, ComputedChunkEnd),
			getChunkDivisions(File, 0, CorrectedChunkEnd, ChunkDivisions);
		true		 ->
			ComputedChunkEnd = Size-Chunksize,
			CorrectedChunkEnd = walkToNextLineBreak(File, ComputedChunkEnd),
			getChunkDivisions(File, CorrectedChunkEnd, Chunksize, [{chunk,CorrectedChunkEnd,Size}|ChunkDivisions])
	end.

walkToNextLineBreak(File,Start) ->
	file:position(File, Start-1),
	{ok, Data} = file:read(File, 1024),
	Start+string:chr(Data, $\n).
</pre><div
class="betterrelated none"><p>No related content found.</p></div><p><!--[if IE]><iframe
frameborder="0" allowTransparency="true" class="addtoany_special_service facebook_like" src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwerxltd.com%2Fwp%2F2011%2F05%2F23%2Fdividing-a-file-into-chunks-along-line-endings-in-erlang%2F&amp;layout=button_count&amp;show_faces=false&amp;width=75&amp;action=like&amp;colorscheme=light&amp;height=20&amp;ref=addtoany" scrolling="no" style="border:none;overflow:hidden;width:90px;height:21px"></iframe><![endif]--><!--[if !IE]><!--><iframe
class="addtoany_special_service facebook_like" src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwerxltd.com%2Fwp%2F2011%2F05%2F23%2Fdividing-a-file-into-chunks-along-line-endings-in-erlang%2F&amp;layout=button_count&amp;show_faces=false&amp;width=75&amp;action=like&amp;colorscheme=light&amp;height=20&amp;ref=addtoany" scrolling="no" style="border:none;overflow:hidden;width:90px;height:21px"></iframe><!--<![endif]--><!--[if IE]><iframe
frameborder="0" allowTransparency="true" class="addtoany_special_service twitter_tweet" src="http://platform.twitter.com/widgets/tweet_button.html?url=http%3A%2F%2Fwerxltd.com%2Fwp%2F2011%2F05%2F23%2Fdividing-a-file-into-chunks-along-line-endings-in-erlang%2F&amp;counturl=http%3A%2F%2Fwerxltd.com%2Fwp%2F2011%2F05%2F23%2Fdividing-a-file-into-chunks-along-line-endings-in-erlang%2F&amp;count=none&amp;text=Dividing%20a%20file%20into%20chunks%20along%20line%20endings%20in%20Erlang" scrolling="no" style="border:none;overflow:hidden;width:55px;height:20px"></iframe><![endif]--><!--[if !IE]><!--><iframe
class="addtoany_special_service twitter_tweet" src="http://platform.twitter.com/widgets/tweet_button.html?url=http%3A%2F%2Fwerxltd.com%2Fwp%2F2011%2F05%2F23%2Fdividing-a-file-into-chunks-along-line-endings-in-erlang%2F&amp;counturl=http%3A%2F%2Fwerxltd.com%2Fwp%2F2011%2F05%2F23%2Fdividing-a-file-into-chunks-along-line-endings-in-erlang%2F&amp;count=none&amp;text=Dividing%20a%20file%20into%20chunks%20along%20line%20endings%20in%20Erlang" scrolling="no" style="border:none;overflow:hidden;width:55px;height:20px"></iframe><!--<![endif]--><!--[if IE]><iframe
frameborder="0" allowTransparency="true" class="addtoany_special_service google_plusone" src="https://plusone.google.com/u/0/_/%2B1/fastbutton?url=http%3A%2F%2Fwerxltd.com%2Fwp%2F2011%2F05%2F23%2Fdividing-a-file-into-chunks-along-line-endings-in-erlang%2F&amp;size=medium&amp;count=false" scrolling="no" style="border:none;overflow:hidden;width:32px;height:20px"></iframe><![endif]--><!--[if !IE]><!--><iframe
class="addtoany_special_service google_plusone" src="https://plusone.google.com/u/0/_/%2B1/fastbutton?url=http%3A%2F%2Fwerxltd.com%2Fwp%2F2011%2F05%2F23%2Fdividing-a-file-into-chunks-along-line-endings-in-erlang%2F&amp;size=medium&amp;count=false" scrolling="no" style="border:none;overflow:hidden;width:32px;height:20px"></iframe><!--<![endif]--><a
class="a2a_button_linkedin" href="http://www.addtoany.com/add_to/linkedin?linkurl=http%3A%2F%2Fwerxltd.com%2Fwp%2F2011%2F05%2F23%2Fdividing-a-file-into-chunks-along-line-endings-in-erlang%2F&amp;linkname=Dividing%20a%20file%20into%20chunks%20along%20line%20endings%20in%20Erlang" title="LinkedIn" rel="nofollow" target="_blank"><img
src="http://werxltd.com/wp/wp-content/plugins/add-to-any/icons/linkedin.png?9d7bd4" width="16" height="16" alt="LinkedIn"/></a><a
class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwerxltd.com%2Fwp%2F2011%2F05%2F23%2Fdividing-a-file-into-chunks-along-line-endings-in-erlang%2F&amp;title=Dividing%20a%20file%20into%20chunks%20along%20line%20endings%20in%20Erlang" id="wpa2a_14">Share/Save</a></p>]]></content:encoded> <wfw:commentRss>http://werxltd.com/wp/2011/05/23/dividing-a-file-into-chunks-along-line-endings-in-erlang/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>A Java String permutations utility</title><link>http://werxltd.com/wp/2011/05/09/a-java-string-permutations-utility/</link> <comments>http://werxltd.com/wp/2011/05/09/a-java-string-permutations-utility/#comments</comments> <pubDate>Tue, 10 May 2011 03:21:31 +0000</pubDate> <dc:creator>wes</dc:creator> <category><![CDATA[java]]></category> <category><![CDATA[software development]]></category> <category><![CDATA[permutation]]></category><guid
isPermaLink="false">http://werxltd.com/wp/?p=956</guid> <description><![CDATA[On a recent project I need to find all the possible permutations of a given URL. Stripping off subdomains, paths, and query parameters. Here is the first part of the solution. A method which takes a string and strips it down based on a given divider in a given direction at a given interval. Here&#8217;s [...]]]></description> <content:encoded><![CDATA[<p>On a recent project I need to find all the possible permutations of a given URL. Stripping off subdomains, paths, and query parameters. Here is the first part of the solution. A method which takes a string and strips it down based on a given divider in a given direction at a given interval.</p><p>Here&#8217;s the code:</p><pre  class="brush:java">
private static String[] getPermutations(String whole, String divider, int lim, int dir) {
	   String[] chunks = whole.split((divider.matches("\\.") ? "\\" : "")+divider);
	   System.out.println("chunks.length: "+chunks.length);

	   if(chunks.length <= lim) {
		   System.out.println("return whole: "+whole);
		   return new String[]{whole};
	   }

	   String[] permutations = new String[chunks.length-lim];

	   if(dir == 1) {
		   	permutations[0] = whole;
   		    System.out.println("permutations[0]: "+permutations[0]);
			for(int i = 1; i < chunks.length-lim; i++) {
			   String permutation = "";
			   for(int o = i; o < chunks.length; o++) {
				   permutation += (o == i ? "" : divider) + chunks[o];
			   }
			   permutations[i] = permutation;
			   System.out.println("permutations["+i+"]: "+permutations[i]);
			}
	   } else if(dir == -1) {
		   for(int i = 0; i < chunks.length-lim; i++) {
			   String permutation = "";
	 		   for(int o = 0; o < chunks.length-i; o++) {
				   permutation += (o == 0 ? "" : divider) + chunks[o];
			   }
			   permutations[i] = permutation;
			   System.out.println("permutations["+i+"]: "+permutations[i]);
			}
	   }

	   return permutations;
   }
</pre><p>Here is an example of it being used.</p><p>Input:</p><pre  class="brush:java">
      getPermutations("com",".",1, 1);
      getPermutations("google.com",".",1, 1);
      getPermutations("a.b.c.d.e.cool.google.com",".",1, 1);
      getPermutations("/path/asdf/a/b/c/d/e/f","/",0, -1);
      getPermutations("a=b&#038;c=d&#038;e=f","&#038;",0, -1);
</pre><p>Output:</p><pre  class="brush:bash">
$ javac Runme.java &#038;&#038; java Runme
chunks.length: 1
return whole: com
chunks.length: 2
permutations[0]: google.com
chunks.length: 8
permutations[0]: a.b.c.d.e.cool.google.com
permutations[1]: b.c.d.e.cool.google.com
permutations[2]: c.d.e.cool.google.com
permutations[3]: d.e.cool.google.com
permutations[4]: e.cool.google.com
permutations[5]: cool.google.com
permutations[6]: google.com
chunks.length: 9
permutations[0]: /path/asdf/a/b/c/d/e/f
permutations[1]: /path/asdf/a/b/c/d/e
permutations[2]: /path/asdf/a/b/c/d
permutations[3]: /path/asdf/a/b/c
permutations[4]: /path/asdf/a/b
permutations[5]: /path/asdf/a
permutations[6]: /path/asdf
permutations[7]: /path
permutations[8]:
chunks.length: 3
permutations[0]: a=b&#038;c=d&#038;e=f
permutations[1]: a=b&#038;c=d
permutations[2]: a=b
</pre><p>Next I'll need to combine the URL components to get a list of valid URLs..</p><div
class="betterrelated none"><p>No related content found.</p></div><p><!--[if IE]><iframe
frameborder="0" allowTransparency="true" class="addtoany_special_service facebook_like" src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwerxltd.com%2Fwp%2F2011%2F05%2F09%2Fa-java-string-permutations-utility%2F&amp;layout=button_count&amp;show_faces=false&amp;width=75&amp;action=like&amp;colorscheme=light&amp;height=20&amp;ref=addtoany" scrolling="no" style="border:none;overflow:hidden;width:90px;height:21px"></iframe><![endif]--><!--[if !IE]><!--><iframe
class="addtoany_special_service facebook_like" src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwerxltd.com%2Fwp%2F2011%2F05%2F09%2Fa-java-string-permutations-utility%2F&amp;layout=button_count&amp;show_faces=false&amp;width=75&amp;action=like&amp;colorscheme=light&amp;height=20&amp;ref=addtoany" scrolling="no" style="border:none;overflow:hidden;width:90px;height:21px"></iframe><!--<![endif]--><!--[if IE]><iframe
frameborder="0" allowTransparency="true" class="addtoany_special_service twitter_tweet" src="http://platform.twitter.com/widgets/tweet_button.html?url=http%3A%2F%2Fwerxltd.com%2Fwp%2F2011%2F05%2F09%2Fa-java-string-permutations-utility%2F&amp;counturl=http%3A%2F%2Fwerxltd.com%2Fwp%2F2011%2F05%2F09%2Fa-java-string-permutations-utility%2F&amp;count=none&amp;text=A%20Java%20String%20permutations%20utility" scrolling="no" style="border:none;overflow:hidden;width:55px;height:20px"></iframe><![endif]--><!--[if !IE]><!--><iframe
class="addtoany_special_service twitter_tweet" src="http://platform.twitter.com/widgets/tweet_button.html?url=http%3A%2F%2Fwerxltd.com%2Fwp%2F2011%2F05%2F09%2Fa-java-string-permutations-utility%2F&amp;counturl=http%3A%2F%2Fwerxltd.com%2Fwp%2F2011%2F05%2F09%2Fa-java-string-permutations-utility%2F&amp;count=none&amp;text=A%20Java%20String%20permutations%20utility" scrolling="no" style="border:none;overflow:hidden;width:55px;height:20px"></iframe><!--<![endif]--><!--[if IE]><iframe
frameborder="0" allowTransparency="true" class="addtoany_special_service google_plusone" src="https://plusone.google.com/u/0/_/%2B1/fastbutton?url=http%3A%2F%2Fwerxltd.com%2Fwp%2F2011%2F05%2F09%2Fa-java-string-permutations-utility%2F&amp;size=medium&amp;count=false" scrolling="no" style="border:none;overflow:hidden;width:32px;height:20px"></iframe><![endif]--><!--[if !IE]><!--><iframe
class="addtoany_special_service google_plusone" src="https://plusone.google.com/u/0/_/%2B1/fastbutton?url=http%3A%2F%2Fwerxltd.com%2Fwp%2F2011%2F05%2F09%2Fa-java-string-permutations-utility%2F&amp;size=medium&amp;count=false" scrolling="no" style="border:none;overflow:hidden;width:32px;height:20px"></iframe><!--<![endif]--><a
class="a2a_button_linkedin" href="http://www.addtoany.com/add_to/linkedin?linkurl=http%3A%2F%2Fwerxltd.com%2Fwp%2F2011%2F05%2F09%2Fa-java-string-permutations-utility%2F&amp;linkname=A%20Java%20String%20permutations%20utility" title="LinkedIn" rel="nofollow" target="_blank"><img
src="http://werxltd.com/wp/wp-content/plugins/add-to-any/icons/linkedin.png?9d7bd4" width="16" height="16" alt="LinkedIn"/></a><a
class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwerxltd.com%2Fwp%2F2011%2F05%2F09%2Fa-java-string-permutations-utility%2F&amp;title=A%20Java%20String%20permutations%20utility" id="wpa2a_16">Share/Save</a></p>]]></content:encoded> <wfw:commentRss>http://werxltd.com/wp/2011/05/09/a-java-string-permutations-utility/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Javascript color gradient calculator</title><link>http://werxltd.com/wp/2011/05/02/javascript-color-gradient-calculator/</link> <comments>http://werxltd.com/wp/2011/05/02/javascript-color-gradient-calculator/#comments</comments> <pubDate>Mon, 02 May 2011 15:00:18 +0000</pubDate> <dc:creator>wes</dc:creator> <category><![CDATA[javascript]]></category> <category><![CDATA[software development]]></category> <category><![CDATA[color]]></category> <category><![CDATA[design]]></category> <category><![CDATA[gradient]]></category><guid
isPermaLink="false">http://werxltd.com/wp/?p=953</guid> <description><![CDATA[Here is a color calculator I adapted from a friend&#8217;s PHP implementation: Color = function() { }; Color.hexdec = function(hex_string) { hex_string = (hex_string + '').replace(/[^a-f0-9]/gi, ''); return parseInt(hex_string, 16); } Color.dechex = function(number) { if (number < 0) { number = 0xFFFFFFFF + number + 1; } return parseInt(number, 10).toString(16); } Color.pad = function(number, [...]]]></description> <content:encoded><![CDATA[<p>Here is a color calculator I adapted from a <a
href="http://suddendevelopment.com/">friend&#8217;s</a> PHP implementation:</p><pre class="brush:javascript">
Color = function() {
};

Color.hexdec = function(hex_string) {
    hex_string = (hex_string + '').replace(/[^a-f0-9]/gi, '');
    return parseInt(hex_string, 16);
}

Color.dechex = function(number) {
    if (number < 0) {
        number = 0xFFFFFFFF + number + 1;
    }
    return parseInt(number, 10).toString(16);
}

Color.pad = function(number, length) {
    var str = '' + number;
    while (str.length < length) {
        str = '0' + str;
    }
    return str;
}

Color.calcgrad = function(val, color1, color2) {

    if(!color1.match(/^#[0-9a-f]{6}/) || !color2.match(/^#[0-9a-f]{6}/)) return 'match err!';

    if (val > 1) {
        val = 1;
    }
    if (val < 0) {
        val = 0;
    }
    val = parseFloat(val);

    c1 = [Color.hexdec(color1.substr(1,2)), Color.hexdec(color1.substr(3,2)), Color.hexdec(color1.substr(5,2))]; //b
    c2 = [Color.hexdec(color2.substr(1,2)), Color.hexdec(color2.substr(3,2)), Color.hexdec(color2.substr(5,2))]; //r

    if (val < .5) {
        delta = [(c2[0] - c1[0]), (c2[1] - c1[1]), (c1[2] - c2[2])];
        arrColor = [c1[0] +<sup><a href="http://werxltd.com/wp/2011/05/02/javascript-color-gradient-calculator/#footnote_0_953" id="identifier_0_953" class="footnote-link footnote-identifier-link" title="delta[0] * val) * 2), c1[1] + ((delta[1] * val) * 2), c1[2] - ((delta[2] * val) * 2)];
    } else {
        delta = [(c1[0] - c2[0]), (c1[1] - c2[1]), (c1[2] - c2[2])];
        arrColor = [c1[0] - ((delta[0] * (val - .5">1</a></sup> * 2), c1[1] -<sup><a href="http://werxltd.com/wp/2011/05/02/javascript-color-gradient-calculator/#footnote_1_953" id="identifier_1_953" class="footnote-link footnote-identifier-link" title="delta[1] * (val - .5">2</a></sup> * 2), c1[2] -<sup><a href="http://werxltd.com/wp/2011/05/02/javascript-color-gradient-calculator/#footnote_2_953" id="identifier_2_953" class="footnote-link footnote-identifier-link" title="delta[2] * (val - .5">3</a></sup> * 2)];
    }
    return '#'+Color.pad(Color.dechex(arrColor[0]),2)+Color.pad(Color.dechex(arrColor[1]),2)+Color.pad(Color.dechex(arrColor[2]),2);
}
</pre><div
class="betterrelated none"><p>No related content found.</p></div><ol
class="footnotes"><li
id="footnote_0_953" class="footnote">delta[0] * val) * 2), c1[1] + ((delta[1] * val) * 2), c1[2] - ((delta[2] * val) * 2)];
} else {
delta = [(c1[0] - c2[0]), (c1[1] - c2[1]), (c1[2] - c2[2])];
arrColor = [c1[0] - ((delta[0] * (val - .5</li><li
id="footnote_1_953" class="footnote">delta[1] * (val - .5</li><li
id="footnote_2_953" class="footnote">delta[2] * (val - .5</li></ol><p><!--[if IE]><iframe
frameborder="0" allowTransparency="true" class="addtoany_special_service facebook_like" src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwerxltd.com%2Fwp%2F2011%2F05%2F02%2Fjavascript-color-gradient-calculator%2F&amp;layout=button_count&amp;show_faces=false&amp;width=75&amp;action=like&amp;colorscheme=light&amp;height=20&amp;ref=addtoany" scrolling="no" style="border:none;overflow:hidden;width:90px;height:21px"></iframe><![endif]--><!--[if !IE]><!--><iframe
class="addtoany_special_service facebook_like" src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwerxltd.com%2Fwp%2F2011%2F05%2F02%2Fjavascript-color-gradient-calculator%2F&amp;layout=button_count&amp;show_faces=false&amp;width=75&amp;action=like&amp;colorscheme=light&amp;height=20&amp;ref=addtoany" scrolling="no" style="border:none;overflow:hidden;width:90px;height:21px"></iframe><!--<![endif]--><!--[if IE]><iframe
frameborder="0" allowTransparency="true" class="addtoany_special_service twitter_tweet" src="http://platform.twitter.com/widgets/tweet_button.html?url=http%3A%2F%2Fwerxltd.com%2Fwp%2F2011%2F05%2F02%2Fjavascript-color-gradient-calculator%2F&amp;counturl=http%3A%2F%2Fwerxltd.com%2Fwp%2F2011%2F05%2F02%2Fjavascript-color-gradient-calculator%2F&amp;count=none&amp;text=Javascript%20color%20gradient%20calculator" scrolling="no" style="border:none;overflow:hidden;width:55px;height:20px"></iframe><![endif]--><!--[if !IE]><!--><iframe
class="addtoany_special_service twitter_tweet" src="http://platform.twitter.com/widgets/tweet_button.html?url=http%3A%2F%2Fwerxltd.com%2Fwp%2F2011%2F05%2F02%2Fjavascript-color-gradient-calculator%2F&amp;counturl=http%3A%2F%2Fwerxltd.com%2Fwp%2F2011%2F05%2F02%2Fjavascript-color-gradient-calculator%2F&amp;count=none&amp;text=Javascript%20color%20gradient%20calculator" scrolling="no" style="border:none;overflow:hidden;width:55px;height:20px"></iframe><!--<![endif]--><!--[if IE]><iframe
frameborder="0" allowTransparency="true" class="addtoany_special_service google_plusone" src="https://plusone.google.com/u/0/_/%2B1/fastbutton?url=http%3A%2F%2Fwerxltd.com%2Fwp%2F2011%2F05%2F02%2Fjavascript-color-gradient-calculator%2F&amp;size=medium&amp;count=false" scrolling="no" style="border:none;overflow:hidden;width:32px;height:20px"></iframe><![endif]--><!--[if !IE]><!--><iframe
class="addtoany_special_service google_plusone" src="https://plusone.google.com/u/0/_/%2B1/fastbutton?url=http%3A%2F%2Fwerxltd.com%2Fwp%2F2011%2F05%2F02%2Fjavascript-color-gradient-calculator%2F&amp;size=medium&amp;count=false" scrolling="no" style="border:none;overflow:hidden;width:32px;height:20px"></iframe><!--<![endif]--><a
class="a2a_button_linkedin" href="http://www.addtoany.com/add_to/linkedin?linkurl=http%3A%2F%2Fwerxltd.com%2Fwp%2F2011%2F05%2F02%2Fjavascript-color-gradient-calculator%2F&amp;linkname=Javascript%20color%20gradient%20calculator" title="LinkedIn" rel="nofollow" target="_blank"><img
src="http://werxltd.com/wp/wp-content/plugins/add-to-any/icons/linkedin.png?9d7bd4" width="16" height="16" alt="LinkedIn"/></a><a
class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwerxltd.com%2Fwp%2F2011%2F05%2F02%2Fjavascript-color-gradient-calculator%2F&amp;title=Javascript%20color%20gradient%20calculator" id="wpa2a_18">Share/Save</a></p>]]></content:encoded> <wfw:commentRss>http://werxltd.com/wp/2011/05/02/javascript-color-gradient-calculator/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Dan Cathy: High Tech for High Customer Touch</title><link>http://werxltd.com/wp/2011/04/24/dan-cathy-high-tech-for-high-customer-touch/</link> <comments>http://werxltd.com/wp/2011/04/24/dan-cathy-high-tech-for-high-customer-touch/#comments</comments> <pubDate>Sun, 24 Apr 2011 16:00:56 +0000</pubDate> <dc:creator>wes</dc:creator> <category><![CDATA[it industry]]></category> <category><![CDATA[software development]]></category> <category><![CDATA[chicken]]></category> <category><![CDATA[customer service]]></category> <category><![CDATA[technology]]></category><guid
isPermaLink="false">http://werxltd.com/wp/?p=942</guid> <description><![CDATA[No related content found.]]></description> <content:encoded><![CDATA[<p><iframe
title="YouTube video player" width="640" height="390" src="http://www.youtube.com/embed/K_hXjThGLHc" frameborder="0" allowfullscreen></iframe></p><div
class="betterrelated none"><p>No related content found.</p></div><p><!--[if IE]><iframe
frameborder="0" allowTransparency="true" class="addtoany_special_service facebook_like" src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwerxltd.com%2Fwp%2F2011%2F04%2F24%2Fdan-cathy-high-tech-for-high-customer-touch%2F&amp;layout=button_count&amp;show_faces=false&amp;width=75&amp;action=like&amp;colorscheme=light&amp;height=20&amp;ref=addtoany" scrolling="no" style="border:none;overflow:hidden;width:90px;height:21px"></iframe><![endif]--><!--[if !IE]><!--><iframe
class="addtoany_special_service facebook_like" src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwerxltd.com%2Fwp%2F2011%2F04%2F24%2Fdan-cathy-high-tech-for-high-customer-touch%2F&amp;layout=button_count&amp;show_faces=false&amp;width=75&amp;action=like&amp;colorscheme=light&amp;height=20&amp;ref=addtoany" scrolling="no" style="border:none;overflow:hidden;width:90px;height:21px"></iframe><!--<![endif]--><!--[if IE]><iframe
frameborder="0" allowTransparency="true" class="addtoany_special_service twitter_tweet" src="http://platform.twitter.com/widgets/tweet_button.html?url=http%3A%2F%2Fwerxltd.com%2Fwp%2F2011%2F04%2F24%2Fdan-cathy-high-tech-for-high-customer-touch%2F&amp;counturl=http%3A%2F%2Fwerxltd.com%2Fwp%2F2011%2F04%2F24%2Fdan-cathy-high-tech-for-high-customer-touch%2F&amp;count=none&amp;text=Dan%20Cathy%3A%20High%20Tech%20for%20High%20Customer%20Touch" scrolling="no" style="border:none;overflow:hidden;width:55px;height:20px"></iframe><![endif]--><!--[if !IE]><!--><iframe
class="addtoany_special_service twitter_tweet" src="http://platform.twitter.com/widgets/tweet_button.html?url=http%3A%2F%2Fwerxltd.com%2Fwp%2F2011%2F04%2F24%2Fdan-cathy-high-tech-for-high-customer-touch%2F&amp;counturl=http%3A%2F%2Fwerxltd.com%2Fwp%2F2011%2F04%2F24%2Fdan-cathy-high-tech-for-high-customer-touch%2F&amp;count=none&amp;text=Dan%20Cathy%3A%20High%20Tech%20for%20High%20Customer%20Touch" scrolling="no" style="border:none;overflow:hidden;width:55px;height:20px"></iframe><!--<![endif]--><!--[if IE]><iframe
frameborder="0" allowTransparency="true" class="addtoany_special_service google_plusone" src="https://plusone.google.com/u/0/_/%2B1/fastbutton?url=http%3A%2F%2Fwerxltd.com%2Fwp%2F2011%2F04%2F24%2Fdan-cathy-high-tech-for-high-customer-touch%2F&amp;size=medium&amp;count=false" scrolling="no" style="border:none;overflow:hidden;width:32px;height:20px"></iframe><![endif]--><!--[if !IE]><!--><iframe
class="addtoany_special_service google_plusone" src="https://plusone.google.com/u/0/_/%2B1/fastbutton?url=http%3A%2F%2Fwerxltd.com%2Fwp%2F2011%2F04%2F24%2Fdan-cathy-high-tech-for-high-customer-touch%2F&amp;size=medium&amp;count=false" scrolling="no" style="border:none;overflow:hidden;width:32px;height:20px"></iframe><!--<![endif]--><a
class="a2a_button_linkedin" href="http://www.addtoany.com/add_to/linkedin?linkurl=http%3A%2F%2Fwerxltd.com%2Fwp%2F2011%2F04%2F24%2Fdan-cathy-high-tech-for-high-customer-touch%2F&amp;linkname=Dan%20Cathy%3A%20High%20Tech%20for%20High%20Customer%20Touch" title="LinkedIn" rel="nofollow" target="_blank"><img
src="http://werxltd.com/wp/wp-content/plugins/add-to-any/icons/linkedin.png?9d7bd4" width="16" height="16" alt="LinkedIn"/></a><a
class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwerxltd.com%2Fwp%2F2011%2F04%2F24%2Fdan-cathy-high-tech-for-high-customer-touch%2F&amp;title=Dan%20Cathy%3A%20High%20Tech%20for%20High%20Customer%20Touch" id="wpa2a_20">Share/Save</a></p>]]></content:encoded> <wfw:commentRss>http://werxltd.com/wp/2011/04/24/dan-cathy-high-tech-for-high-customer-touch/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using apc
Page Caching using apc
Database Caching 2/33 queries in 0.224 seconds using apc
Object Caching 995/1060 objects using apc

Served from: werxltd.com @ 2012-02-05 04:15:44 -->
