<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><!-- generator="WordPress/2.9.1" --><rss xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="0.92">
<channel>
	<title>Code Comments</title>
	<link>http://code.hammerpig.com</link>
	<description>Tips and short tutorials on various programming technologies</description>
	<lastBuildDate>Fri, 23 Dec 2011 23:09:44 +0000</lastBuildDate>
	<docs>http://backend.userland.com/rss092</docs>
	<language>en</language>
	
	<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/xml" href="http://feeds.feedburner.com/CodeComments" /><feedburner:info uri="codecomments" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:emailServiceId>CodeComments</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><item>
		<title>How to Delete Files Using Python Code</title>
		<description>It&amp;#8217;s really easy to delete a single file in Python. Say the file you want to delete is called &amp;#8220;MyFile.txt.&amp;#8221; You could delete it using this syntax:

import os
&amp;#160;
os.remove&amp;#40;&amp;#34;MyFile.txt&amp;#34;&amp;#41;

Let&amp;#8217;s say you had many files in a directory, and the ones you wanted to delete were called MyFile1.txt, MyFile2.txt, and MyFile3.txt. One trick that you can use [...]
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/pJ7RADu0TGAHhM5oBwCX0yZ2oIY/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/pJ7RADu0TGAHhM5oBwCX0yZ2oIY/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/pJ7RADu0TGAHhM5oBwCX0yZ2oIY/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/pJ7RADu0TGAHhM5oBwCX0yZ2oIY/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/CodeComments/~4/khbUYyjPdNc" height="1" width="1"/&gt;</description>
		<link>http://feedproxy.google.com/~r/CodeComments/~3/khbUYyjPdNc/delete-files-python.html</link>
			<feedburner:origLink>http://code.hammerpig.com/delete-files-python.html</feedburner:origLink></item>
	<item>
		<title>How to Peek at Top, Middle, or Bottom of Text File Without Opening It in Linux</title>
		<description>Let&amp;#8217;s say you have a really large text file. By large, I mean it has a lot of lines of text in the file. I frequently work with files that have millions or billions of lines of text in them. If I try to open the file in a text editor, it usually takes a [...]
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/cIQgOclwbmmgVtvCcpe4-jjzk9s/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/cIQgOclwbmmgVtvCcpe4-jjzk9s/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/cIQgOclwbmmgVtvCcpe4-jjzk9s/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/cIQgOclwbmmgVtvCcpe4-jjzk9s/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/CodeComments/~4/OYlnPwoeoIc" height="1" width="1"/&gt;</description>
		<link>http://feedproxy.google.com/~r/CodeComments/~3/OYlnPwoeoIc/peek-top-middle-bottom-file-opening-linux.html</link>
			<feedburner:origLink>http://code.hammerpig.com/peek-top-middle-bottom-file-opening-linux.html</feedburner:origLink></item>
	<item>
		<title>Get Smallest Matches Possible with Regular Expressions</title>
		<description>I occasionally use regular expressions, and when I don&amp;#8217;t regret it. But it can be difficult to get the syntax and concepts straight in my head because I only use them occasionally.
The general purpose behind regular expressions is to take a piece of text and find smaller pieces of text within it that match a [...]
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/rNYT9gBPR561ukTawWtQoQG7wCU/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/rNYT9gBPR561ukTawWtQoQG7wCU/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/rNYT9gBPR561ukTawWtQoQG7wCU/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/rNYT9gBPR561ukTawWtQoQG7wCU/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/CodeComments/~4/oCdLD3X8w1M" height="1" width="1"/&gt;</description>
		<link>http://feedproxy.google.com/~r/CodeComments/~3/oCdLD3X8w1M/match-regular-expressions.html</link>
			<feedburner:origLink>http://code.hammerpig.com/match-regular-expressions.html</feedburner:origLink></item>
	<item>
		<title>Vertically Align x-axis Labels in an R plot</title>
		<description>When you are creating a plot in R, sometimes you have axis labels on the x axis. You can create custom ones with the axis function. If your labels are long, you can bring them apart using a newline character so they span multiple lines. But when you do this, it centers the text vertically [...]
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/EdkL76-hFSt0_AUFSG_nZUnpvkA/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/EdkL76-hFSt0_AUFSG_nZUnpvkA/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/EdkL76-hFSt0_AUFSG_nZUnpvkA/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/EdkL76-hFSt0_AUFSG_nZUnpvkA/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/CodeComments/~4/VGBBoSRqpNk" height="1" width="1"/&gt;</description>
		<link>http://feedproxy.google.com/~r/CodeComments/~3/VGBBoSRqpNk/vertically-align-xaxis-labels-plot.html</link>
			<feedburner:origLink>http://code.hammerpig.com/vertically-align-xaxis-labels-plot.html</feedburner:origLink></item>
	<item>
		<title>How to echo a Tab or Other Special Characters in Linux</title>
		<description>I&amp;#8217;m working on a bash script that I want to insert some text into a file. So I&amp;#8217;m using the echo command to do this, like so:

echo &amp;#8220;hello, world&amp;#8221; &amp;#62; myfile.txt

This works just great. Now I want to insert a special character into the file. So I need to do two things: 1) escape special [...]
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/nzcmGvy3ZAaTVbyZQmfE0BwFrlg/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/nzcmGvy3ZAaTVbyZQmfE0BwFrlg/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/nzcmGvy3ZAaTVbyZQmfE0BwFrlg/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/nzcmGvy3ZAaTVbyZQmfE0BwFrlg/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/CodeComments/~4/M-wjvl7cjH8" height="1" width="1"/&gt;</description>
		<link>http://feedproxy.google.com/~r/CodeComments/~3/M-wjvl7cjH8/echo-tab-special-characters-linux.html</link>
			<feedburner:origLink>http://code.hammerpig.com/echo-tab-special-characters-linux.html</feedburner:origLink></item>
	<item>
		<title>Generate a Random String in Linux</title>
		<description>It&amp;#8217;s not too hard to generate a random number at the command line in Linux. You can use $RANDOM. But if you want to generate a random string, it is a bit more obscure. The best solution I found (after searching for longer than expected) was the following:

openssl rand -base64 30

This technique uses the openssl [...]
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/HswNnfWUTl-fxtBjNdMco6Rb5Kw/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/HswNnfWUTl-fxtBjNdMco6Rb5Kw/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/HswNnfWUTl-fxtBjNdMco6Rb5Kw/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/HswNnfWUTl-fxtBjNdMco6Rb5Kw/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/CodeComments/~4/BcHncSvUb_k" height="1" width="1"/&gt;</description>
		<link>http://feedproxy.google.com/~r/CodeComments/~3/BcHncSvUb_k/generate-random-string-linux.html</link>
			<feedburner:origLink>http://code.hammerpig.com/generate-random-string-linux.html</feedburner:origLink></item>
	<item>
		<title>How to Extract Substring in Bash</title>
		<description>Let&amp;#8217;s say you have a bash variable:

x=abc123def

And you want to get everything in the substring that comes before &amp;#8220;def.&amp;#8221; You can use awk to do this, but it&amp;#8217;s a bit &amp;#8220;awk&amp;#8221;ward (though very flexible and powerful in general). An easy solution is to do the following:

y=${x%def*}
echo $y # Should print &amp;#34;abc123&amp;#34;

This approach should work on [...]
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/4qzaPERoNi7ORLKaiLiIkrwj_UY/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/4qzaPERoNi7ORLKaiLiIkrwj_UY/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/4qzaPERoNi7ORLKaiLiIkrwj_UY/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/4qzaPERoNi7ORLKaiLiIkrwj_UY/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/CodeComments/~4/FapxlJ91_fs" height="1" width="1"/&gt;</description>
		<link>http://feedproxy.google.com/~r/CodeComments/~3/FapxlJ91_fs/extract-substring-bash.html</link>
			<feedburner:origLink>http://code.hammerpig.com/extract-substring-bash.html</feedburner:origLink></item>
	<item>
		<title>Splitting a String into Array and Accessing Contents by Index in bash</title>
		<description>Say you have a variable in a bash script that looks like this:

x=&amp;#34;abc_123_def&amp;#34;

Now say you want to split this variable into an array. The character you will use to split it is the underscore (_). So you want to end up with an array of three objects: abc, 123, and def. Then you want to [...]
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/UglxP9pmdBTvde6Q-uUwOlv3k9s/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/UglxP9pmdBTvde6Q-uUwOlv3k9s/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/UglxP9pmdBTvde6Q-uUwOlv3k9s/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/UglxP9pmdBTvde6Q-uUwOlv3k9s/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/CodeComments/~4/nc_fC-4uXfA" height="1" width="1"/&gt;</description>
		<link>http://feedproxy.google.com/~r/CodeComments/~3/nc_fC-4uXfA/splitting-string-array-accessing-contents-index-bash.html</link>
			<feedburner:origLink>http://code.hammerpig.com/splitting-string-array-accessing-contents-index-bash.html</feedburner:origLink></item>
	<item>
		<title>Sorting String Values That Contain Numbers in Python</title>
		<description>If you have a list of String objects in Python and want to sort them but treat any numeric values accordingly, it will not work with the regular sort function in Python. So if you have the following list:

x = &amp;#91;&amp;#34;3&amp;#34;, &amp;#34;1&amp;#34;, &amp;#34;10&amp;#34;, &amp;#34;2&amp;#34;&amp;#93;

You will get the following if you sort and print it:

print sorted&amp;#40;x&amp;#41; [...]
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/gLvWbuiOlLP9bndZTflg5ujXFd8/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/gLvWbuiOlLP9bndZTflg5ujXFd8/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/gLvWbuiOlLP9bndZTflg5ujXFd8/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/gLvWbuiOlLP9bndZTflg5ujXFd8/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/CodeComments/~4/y1O20-zjDQI" height="1" width="1"/&gt;</description>
		<link>http://feedproxy.google.com/~r/CodeComments/~3/y1O20-zjDQI/sorting-string-values-numbers-python.html</link>
			<feedburner:origLink>http://code.hammerpig.com/sorting-string-values-numbers-python.html</feedburner:origLink></item>
	<item>
		<title>How to Scale a Vector of Numbers to One</title>
		<description>Let&amp;#8217;s say you have a vector of numbers: 1, 2, and 5. And let&amp;#8217;s say you have another vector of numbers: 3, 4, 9. These vectors have different ranges, but you believe they actually should have the same range. This scenario probably sounds strange, but it can happen, for example, in cases where genetic data [...]
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/loPz-4rdraWrtM_O53HZ6dDyb3g/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/loPz-4rdraWrtM_O53HZ6dDyb3g/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/loPz-4rdraWrtM_O53HZ6dDyb3g/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/loPz-4rdraWrtM_O53HZ6dDyb3g/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/CodeComments/~4/ss9AENjHA2A" height="1" width="1"/&gt;</description>
		<link>http://feedproxy.google.com/~r/CodeComments/~3/ss9AENjHA2A/scale-vector-numbers.html</link>
			<feedburner:origLink>http://code.hammerpig.com/scale-vector-numbers.html</feedburner:origLink></item>
</channel>
</rss>

