<?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>FLX &#187; Code Snippet of the Week</title>
	<atom:link href="http://flx.me/category/code-snippet-of-the-week/feed/" rel="self" type="application/rss+xml" />
	<link>http://flx.me</link>
	<description>rambles, code and science!</description>
	<lastBuildDate>Tue, 09 Mar 2010 12:47:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
		<item>
		<title>Command line snippet of the week: 3</title>
		<link>http://flx.me/command-line-snippet-of-the-week-3/</link>
		<comments>http://flx.me/command-line-snippet-of-the-week-3/#comments</comments>
		<pubDate>Thu, 21 Jan 2010 13:59:35 +0000</pubDate>
		<dc:creator>FLX</dc:creator>
				<category><![CDATA[Code Snippet of the Week]]></category>

		<guid isPermaLink="false">http://flx.me/?p=597</guid>
		<description><![CDATA[Wouldn&#8217;t it be nice to check if a program is running? You can do that and make it start conditionally if it isn&#8217;t running. Very handy for service daemons that always need to be running. Can be used with cron as well: ps -C servicedaemon &#124;&#124; &#123; servicedaemon &#38; &#125; Replace servicedaemon with your own [...]]]></description>
			<content:encoded><![CDATA[<p>Wouldn&#8217;t it be nice to check if a program is running? You can do that and make it start conditionally if it isn&#8217;t running. Very handy for service daemons that always need to be running. Can be used with cron as well:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">ps</span> <span style="color: #660033;">-C</span> servicedaemon <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span> servicedaemon <span style="color: #000000; font-weight: bold;">&amp;</span> <span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></div></div>

<p>Replace<strong> servicedaemon</strong> with your own process that needs to be checked. The second servicedaemon value describes what program it needs to start if it&#8217;s not running.</p>
]]></content:encoded>
			<wfw:commentRss>http://flx.me/command-line-snippet-of-the-week-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Command line snippet of the week: 2</title>
		<link>http://flx.me/command-line-snippet-of-the-week-2/</link>
		<comments>http://flx.me/command-line-snippet-of-the-week-2/#comments</comments>
		<pubDate>Thu, 14 Jan 2010 13:34:47 +0000</pubDate>
		<dc:creator>FLX</dc:creator>
				<category><![CDATA[Code Snippet of the Week]]></category>

		<guid isPermaLink="false">http://flx.me/?p=593</guid>
		<description><![CDATA[The snippet this week will be about copying arguments without retyping everything. It would be easier to show you how this works: $ cd /home/user/flx cd: /home/user/flx: No such file or directory $ mkdir !* mkdir /home/user/flx By using !* it repeats all arguments previously used. If you only want to use the second argument [...]]]></description>
			<content:encoded><![CDATA[<p>The snippet this week will be about copying arguments without retyping everything. It would be easier to show you how this works:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>user<span style="color: #000000; font-weight: bold;">/</span>flx
<span style="color: #7a0874; font-weight: bold;">cd</span>: <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>user<span style="color: #000000; font-weight: bold;">/</span>flx: No such <span style="color: #c20cb9; font-weight: bold;">file</span> or directory
$ <span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #000000; font-weight: bold;">!*</span>
<span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>user<span style="color: #000000; font-weight: bold;">/</span>flx</pre></div></div>

<p>By using <strong>!*</strong> it repeats all arguments previously used. If you only want to use the second argument for example, you use <strong>!:2</strong>.</p>
]]></content:encoded>
			<wfw:commentRss>http://flx.me/command-line-snippet-of-the-week-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Command line snippet of the week: 1</title>
		<link>http://flx.me/command-line-snippet-of-the-week-1/</link>
		<comments>http://flx.me/command-line-snippet-of-the-week-1/#comments</comments>
		<pubDate>Thu, 07 Jan 2010 13:32:15 +0000</pubDate>
		<dc:creator>FLX</dc:creator>
				<category><![CDATA[Code Snippet of the Week]]></category>

		<guid isPermaLink="false">http://flx.me/?p=590</guid>
		<description><![CDATA[New year, new snippets! Belated good wishes from me as well :-) Anyway, this week&#8217;s snippet is on basic steganography. In this case we would like to hide a rar file in a image, we can do that by doing the following: cat picture.png archive.rar &#62; hidden_archive_in_pic.png This will create a valid png image for [...]]]></description>
			<content:encoded><![CDATA[<p>New year, new snippets! Belated good wishes from me as well :-)</p>
<p>Anyway, this week&#8217;s snippet is on basic <a href="http://en.wikipedia.org/wiki/Steganography">steganography</a>. In this case we would like to hide a rar file in a image, we can do that by doing the following:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">cat</span> picture.png archive.rar <span style="color: #000000; font-weight: bold;">&gt;</span> hidden_archive_in_pic.png</pre></div></div>

<p>This will create a valid png image for viewing with a secret rar file inside!<br />
When you want to retrieve the hidden files, download the image, rename to .rar and extract.</p>
]]></content:encoded>
			<wfw:commentRss>http://flx.me/command-line-snippet-of-the-week-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Command line snippet of the week: 53</title>
		<link>http://flx.me/command-line-snippet-of-the-week-53/</link>
		<comments>http://flx.me/command-line-snippet-of-the-week-53/#comments</comments>
		<pubDate>Thu, 31 Dec 2009 14:00:39 +0000</pubDate>
		<dc:creator>FLX</dc:creator>
				<category><![CDATA[Code Snippet of the Week]]></category>
		<category><![CDATA[automation]]></category>
		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://flx.me/?p=303</guid>
		<description><![CDATA[Last one of this year! Need to mass extract several RAR archives from different folders? Create a file called &#8220;massunrar&#8221; in /usr/bin and paste the following content: find . -type f -name *.r01 -exec unrar e &#123;&#125; \; find . -type f -name *.part01.rar -exec unrar e &#123;&#125; \; echo &#34;Found files:&#34; find . -type [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><strong>Last one of this year!</strong></p>
<p style="text-align: left;">Need to mass extract several RAR archives from different folders? Create a file called &#8220;massunrar&#8221; in /usr/bin and paste the following content:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">find</span> . <span style="color: #660033;">-type</span> f <span style="color: #660033;">-name</span> <span style="color: #000000; font-weight: bold;">*</span>.r01 <span style="color: #660033;">-exec</span> unrar e <span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span> \;
<span style="color: #c20cb9; font-weight: bold;">find</span> . <span style="color: #660033;">-type</span> f <span style="color: #660033;">-name</span> <span style="color: #000000; font-weight: bold;">*</span>.part01.rar <span style="color: #660033;">-exec</span> unrar e <span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span> \;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Found files:&quot;</span>
<span style="color: #c20cb9; font-weight: bold;">find</span> . <span style="color: #660033;">-type</span> f <span style="color: #660033;">-name</span> <span style="color: #000000; font-weight: bold;">*</span>.r01
<span style="color: #c20cb9; font-weight: bold;">find</span> . <span style="color: #660033;">-type</span> f <span style="color: #660033;">-name</span> <span style="color: #000000; font-weight: bold;">*</span>.part01.rar</pre></div></div>

<p>Be sure to chmod &#8220;massunrar&#8221; to make it executable:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">chmod</span> +x <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>massunrar</pre></div></div>

<p>Run &#8220;massunrar&#8221; in the parent folder to let it search for rar files in all subdirectories and extract them.<br />
More to follow next year!</p>
]]></content:encoded>
			<wfw:commentRss>http://flx.me/command-line-snippet-of-the-week-53/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Command line snippet of the week: 52</title>
		<link>http://flx.me/command-line-snippet-of-the-week-52/</link>
		<comments>http://flx.me/command-line-snippet-of-the-week-52/#comments</comments>
		<pubDate>Thu, 24 Dec 2009 14:00:19 +0000</pubDate>
		<dc:creator>FLX</dc:creator>
				<category><![CDATA[Code Snippet of the Week]]></category>
		<category><![CDATA[automation]]></category>
		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://flx.me/?p=301</guid>
		<description><![CDATA[Need to have IP location information? Use: curl -s &#34;http://www.geody.com/geoip.php?ip=$(curl -s icanhazip.com)&#34; &#124; sed '/^IP:/!d;s/&#60;[^&#62;][^&#62;]*&#62;//g' It returns with your IP information such as: IP: 13.13.133.713 Location: Amsterdam, NOORD-HOLLAND, Netherlands &#40;N.V. XS4ALL&#41; Replace (curl -s icanhazip.com) to show a different IP than your own.]]></description>
			<content:encoded><![CDATA[<p>Need to have IP location information? Use:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">curl <span style="color: #660033;">-s</span> <span style="color: #ff0000;">&quot;http://www.geody.com/geoip.php?ip=<span style="color: #007800;">$(curl -s icanhazip.com)</span>&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">'/^IP:/!d;s/&lt;[^&gt;][^&gt;]*&gt;//g'</span></pre></div></div>

<p>It returns with your IP information such as:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">IP: 13.13.133.713 Location: Amsterdam, NOORD-HOLLAND, Netherlands   <span style="color: #7a0874; font-weight: bold;">&#40;</span>N.V. XS4ALL<span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>Replace <em><strong>(curl -s icanhazip.com)</strong></em> to show a different IP than your own.</p>
]]></content:encoded>
			<wfw:commentRss>http://flx.me/command-line-snippet-of-the-week-52/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Command line snippet of the week: 51</title>
		<link>http://flx.me/command-line-snippet-of-the-week-51/</link>
		<comments>http://flx.me/command-line-snippet-of-the-week-51/#comments</comments>
		<pubDate>Thu, 17 Dec 2009 14:00:23 +0000</pubDate>
		<dc:creator>FLX</dc:creator>
				<category><![CDATA[Code Snippet of the Week]]></category>
		<category><![CDATA[automation]]></category>
		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://flx.me/?p=297</guid>
		<description><![CDATA[Need to empty a file fast? Try: &#62; file.txt Shortest emptier in town!]]></description>
			<content:encoded><![CDATA[<p>Need to empty a file fast? Try:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&gt;</span> file.txt</pre></div></div>

<p>Shortest emptier in town!</p>
]]></content:encoded>
			<wfw:commentRss>http://flx.me/command-line-snippet-of-the-week-51/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Command line snippet of the week: 50</title>
		<link>http://flx.me/command-line-snippet-of-the-week-50/</link>
		<comments>http://flx.me/command-line-snippet-of-the-week-50/#comments</comments>
		<pubDate>Thu, 10 Dec 2009 14:00:40 +0000</pubDate>
		<dc:creator>FLX</dc:creator>
				<category><![CDATA[Code Snippet of the Week]]></category>
		<category><![CDATA[automation]]></category>
		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://flx.me/?p=293</guid>
		<description><![CDATA[Forget that your running as underprivileged? No need to retype the command: > command_with_insufficient_permissions Permission denied sudo !! The !! parameter repeats the previous command, thus no need to retype! Source: shell-fu]]></description>
			<content:encoded><![CDATA[<p>Forget that your running as underprivileged? No need to retype the command:</p>
<p>> command_with_insufficient_permissions<br />
Permission denied</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #000000; font-weight: bold;">!!</span></pre></div></div>

<p>The <em>!!</em> parameter repeats the previous command, thus no need to retype!</p>
<p>Source: <a href="http://www.shell-fu.org">shell-fu</a></p>
]]></content:encoded>
			<wfw:commentRss>http://flx.me/command-line-snippet-of-the-week-50/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Command line snippet of the week: 49</title>
		<link>http://flx.me/command-line-snippet-of-the-week-49/</link>
		<comments>http://flx.me/command-line-snippet-of-the-week-49/#comments</comments>
		<pubDate>Thu, 03 Dec 2009 14:00:57 +0000</pubDate>
		<dc:creator>FLX</dc:creator>
				<category><![CDATA[Code Snippet of the Week]]></category>
		<category><![CDATA[automation]]></category>
		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://flx.me/?p=291</guid>
		<description><![CDATA[Want to show something on your machine to someone over the web? Don&#8217;t copy it or upload it somewhere, try this command (requires Python): alias webshare='python -c &#34;import SimpleHTTPServer;SimpleHTTPServer.test()&#34;' Just run &#8220;webshare&#8221; and the current directory and everything beneath it will be served from a new web server listening on port 8000. When you are [...]]]></description>
			<content:encoded><![CDATA[<p>Want to show something on your machine to someone over the web? Don&#8217;t copy it or upload it somewhere, try this command (requires <a href="http://python.org">Python</a>):</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">webshare</span>=<span style="color: #ff0000;">'python -c &quot;import SimpleHTTPServer;SimpleHTTPServer.test()&quot;'</span></pre></div></div>

<p>Just run &#8220;webshare&#8221; and the current directory and everything beneath it will be served from a new web server listening on port 8000. When you are finished, just hit control-c to close the webserver.</p>
]]></content:encoded>
			<wfw:commentRss>http://flx.me/command-line-snippet-of-the-week-49/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Command line snippet of the week: 48</title>
		<link>http://flx.me/command-line-snippet-of-the-week-48/</link>
		<comments>http://flx.me/command-line-snippet-of-the-week-48/#comments</comments>
		<pubDate>Thu, 26 Nov 2009 14:05:22 +0000</pubDate>
		<dc:creator>FLX</dc:creator>
				<category><![CDATA[Code Snippet of the Week]]></category>
		<category><![CDATA[automation]]></category>
		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://flx.me/?p=287</guid>
		<description><![CDATA[Hate having to remember all switches for each different unpacker? You can fix that! Create a new file in /usr/bin/ called &#8220;extract&#8221; and paste the following code: if &#91; -f $1 &#93; ; then case $1 in *.tar.bz2&#41; tar xvjf $1 ;; *.tar.gz&#41; tar xvzf $1 ;; *.bz2&#41; bunzip2 $1 ;; *.rar&#41; unrar x $1 [...]]]></description>
			<content:encoded><![CDATA[<p>Hate having to remember all switches for each different unpacker? You can fix that!<br />
Create a new file in /usr/bin/ called &#8220;extract&#8221; and paste the following code:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-f</span> $<span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> ; <span style="color: #000000; font-weight: bold;">then</span>
<span style="color: #000000; font-weight: bold;">case</span> $<span style="color: #000000;">1</span> <span style="color: #000000; font-weight: bold;">in</span>
    <span style="color: #000000; font-weight: bold;">*</span>.tar.bz2<span style="color: #7a0874; font-weight: bold;">&#41;</span>   <span style="color: #c20cb9; font-weight: bold;">tar</span> xvjf $<span style="color: #000000;">1</span>        <span style="color: #000000; font-weight: bold;">;;</span>
    <span style="color: #000000; font-weight: bold;">*</span>.tar.gz<span style="color: #7a0874; font-weight: bold;">&#41;</span>    <span style="color: #c20cb9; font-weight: bold;">tar</span> xvzf $<span style="color: #000000;">1</span>     <span style="color: #000000; font-weight: bold;">;;</span>
    <span style="color: #000000; font-weight: bold;">*</span>.bz2<span style="color: #7a0874; font-weight: bold;">&#41;</span>       <span style="color: #c20cb9; font-weight: bold;">bunzip2</span> $<span style="color: #000000;">1</span>       <span style="color: #000000; font-weight: bold;">;;</span>
    <span style="color: #000000; font-weight: bold;">*</span>.rar<span style="color: #7a0874; font-weight: bold;">&#41;</span>       unrar x $<span style="color: #000000;">1</span>     <span style="color: #000000; font-weight: bold;">;;</span>
    <span style="color: #000000; font-weight: bold;">*</span>.gz<span style="color: #7a0874; font-weight: bold;">&#41;</span>        <span style="color: #c20cb9; font-weight: bold;">gunzip</span> $<span style="color: #000000;">1</span>     <span style="color: #000000; font-weight: bold;">;;</span>
    <span style="color: #000000; font-weight: bold;">*</span>.tar<span style="color: #7a0874; font-weight: bold;">&#41;</span>       <span style="color: #c20cb9; font-weight: bold;">tar</span> xvf $<span style="color: #000000;">1</span>        <span style="color: #000000; font-weight: bold;">;;</span>
    <span style="color: #000000; font-weight: bold;">*</span>.tbz2<span style="color: #7a0874; font-weight: bold;">&#41;</span>      <span style="color: #c20cb9; font-weight: bold;">tar</span> xvjf $<span style="color: #000000;">1</span>      <span style="color: #000000; font-weight: bold;">;;</span>
    <span style="color: #000000; font-weight: bold;">*</span>.tgz<span style="color: #7a0874; font-weight: bold;">&#41;</span>       <span style="color: #c20cb9; font-weight: bold;">tar</span> xvzf $<span style="color: #000000;">1</span>       <span style="color: #000000; font-weight: bold;">;;</span>
    <span style="color: #000000; font-weight: bold;">*</span>.zip<span style="color: #7a0874; font-weight: bold;">&#41;</span>       <span style="color: #c20cb9; font-weight: bold;">unzip</span> $<span style="color: #000000;">1</span>     <span style="color: #000000; font-weight: bold;">;;</span>
    <span style="color: #000000; font-weight: bold;">*</span>.Z<span style="color: #7a0874; font-weight: bold;">&#41;</span>         uncompress $<span style="color: #000000;">1</span>  <span style="color: #000000; font-weight: bold;">;;</span>
    <span style="color: #000000; font-weight: bold;">*</span>.7z<span style="color: #7a0874; font-weight: bold;">&#41;</span>        7z x $<span style="color: #000000;">1</span>    <span style="color: #000000; font-weight: bold;">;;</span>
    <span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>           <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;'$1' cannot be extracted via &amp;gt;extract&amp;lt;&quot;</span> <span style="color: #000000; font-weight: bold;">;;</span>
<span style="color: #000000; font-weight: bold;">esac</span>
<span style="color: #000000; font-weight: bold;">else</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;'$1' is not a valid file&quot;</span>
<span style="color: #000000; font-weight: bold;">fi</span></pre></div></div>

<p>be sure to chmod it to executable:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">chmod</span> +x <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>extract</pre></div></div>

<p>This code will save you time by extracting almost any kind of archive by using the command:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">extract my_awesome_archive.tar.gz</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://flx.me/command-line-snippet-of-the-week-48/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
