<?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>PCR&#039;s notepad &#187; programming</title>
	<atom:link href="http://notepad.patheticcockroach.com/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://notepad.patheticcockroach.com</link>
	<description>The area in patheticcockroach.com where the EEG isn&#039;t isoelectric</description>
	<lastBuildDate>Fri, 30 Jul 2010 11:13:31 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Some 7-Zip command line examples</title>
		<link>http://notepad.patheticcockroach.com/857/some-7-zip-command-line-examples/</link>
		<comments>http://notepad.patheticcockroach.com/857/some-7-zip-command-line-examples/#comments</comments>
		<pubDate>Tue, 20 Jul 2010 10:29:12 +0000</pubDate>
		<dc:creator>David Dernoncourt</dc:creator>
				<category><![CDATA[Windows]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://notepad.patheticcockroach.com/?p=857</guid>
		<description><![CDATA[As mentioned in the previous post, 7-Zip is a great piece of open-source compression software. Although you&#8217;ll most likely want to use the GUI version for daily use, power users may find the command line version useful for batch jobs. The command line version is bundled in the global installation package, so as far as [...]]]></description>
			<content:encoded><![CDATA[<p>As mentioned in the <a href="http://notepad.patheticcockroach.com/842/7-zip-9-15-beta-portable/">previous post</a>, 7-Zip is a great piece of open-source compression software. Although you&#8217;ll most likely want to use the GUI version for daily use, power users may find the command line version useful for batch jobs. The command line version is bundled in the global installation package, so as far as you installed 7-Zip you do have the command line version installed, too.<br />
Since the 9.x versions have been around for quite a while now and the 4.65 version is getting old, we&#8217;ll only cover the 9.x versions (at the time of writing, the 9.15 beta offered as a portable application in the above-mentioned post). If you want to stick with the 4.65 version I suggest you have a look as <a href="http://dotnetperls.com/7-zip-examples">those examples</a> or at the documentation (the Windows batch commands are of course the same but the 7-Zip parameters are a bit different, and also the executable itself has a different name: <em>7za.exe</em> instead of <em>7z.exe</em>).</p>
<p>For all those examples, we&#8217;ll assume that 7-Zip is installed in <em>G:\UTILITIES\7-Zip\</em>. Also, note that if you want to launch those commands from within a batch file instead of directly from the command line, you need to add an additional &#8216;%&#8217; in front of &#8216;%A&#8217; in the <em>for</em> commands. Finally, we are using LZMA2 with the maximum compression level. If you want LZMA, well, obviously just replace <em>-m9=LZMA2</em> with <em>-m9=LZMA</em>. It&#8217;s actually easy to do a lot more customization, just check out 7-zip.chm in your 7-Zip installation folder.</p>
<h2>Batch compressing individual files (non recursive)</h2>
<p>This one will compress every file located within the current directory (one archive per file) and which have a bmp or txt extension:<br />
<code><a href="http://ss64.com/nt/for2.html">for </a> %A in (*.png *.txt) do "G:\UTILITIES\7-Zip\7z.exe" a -t7z -m9=LZMA2 "%A.7z" "%A"</code></p>
<h2>Batch compressing individual files (recursive)</h2>
<p>This one will individually (one archive per file) compress all files located within <em>L:\My\Folder\</em> (and all sub-folders) and which have a txt or doc extension:<br />
<code><a href="http://ss64.com/nt/for_r.html">for /R</a> "L:\My\Folder\" %A in (*.txt *.doc) do "G:\UTILITIES\7-Zip\7z.exe" a -t7z -m9=LZMA2 "%A.7z" "%A"</code><br />
Also, note that all archives will be placed in the same folder as the file the contain (so there will be archives all around all sub-folders).</p>
<h2>Batch compressing all folders of the current directory</h2>
<p>This one will compress every folder of the current directory (one archive per first sub-level folder):<br />
<code><a href="http://ss64.com/nt/for_d.html">for /D</a> %A in (*) do "G:\UTILITIES\7-Zip\7z.exe" a -t7z -m9=LZMA2 "%A.7z" "%A"</code></p>
<h2>Source</h2>
<p>To write those commands the following pages were useful:</p>
<ul>
<li><a href="http://ss64.com/nt/for.html">FOR looping command</a> at SS64.com Command line reference</li>
<li><a href="http://stackoverflow.com/questions/280969/windows-batch-loop-over-folder-string-and-parse-out-last-folder-name">Windows batch &#8211; loop over folder string and parse out last folder name</a> at stackoverflow</li>
<li><a href="http://sourceforge.net/projects/sevenzip/forums/forum/45797/topic/3703877">7-zip multiple files into multiple .zip</a> and <a href="http://sourceforge.net/projects/sevenzip/forums/forum/45797/topic/3776094">Batch compressing help</a> on SourceForge.net 7-Zip forums</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://notepad.patheticcockroach.com/857/some-7-zip-command-line-examples/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>A bit on regular expressions: my .htaccess files</title>
		<link>http://notepad.patheticcockroach.com/237/a-bit-on-regular-expressions-my-htaccess-files/</link>
		<comments>http://notepad.patheticcockroach.com/237/a-bit-on-regular-expressions-my-htaccess-files/#comments</comments>
		<pubDate>Sun, 11 Jan 2009 06:00:39 +0000</pubDate>
		<dc:creator>David Dernoncourt</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[regular expressions]]></category>
		<category><![CDATA[web development]]></category>

		<guid isPermaLink="false">http://notepad.patheticcockroach.com/?p=237</guid>
		<description><![CDATA[I totally hate regular expressions. I never managed to find a decent manual or reference properly explaining them. By properly I mean a manual that gives me all the details I need (which isn&#8217;t quite much indeed) while being short enough to not make me fall asleep in boredom (which for regex should mean something [...]]]></description>
			<content:encoded><![CDATA[<p>I totally hate regular expressions. I never managed to find a decent manual or reference properly explaining them. By properly I mean a manual that gives me all the details I need (which isn&#8217;t quite much indeed) while being short enough to not make me fall asleep in boredom (which for regex should mean something like less than 2 printed pages&#8230; or just something with tons of examples). This sounds easy enough. Well, it doesn&#8217;t seem to exist though. So I&#8217;ll be posting some regexp that I eventually managed to find around, or even to create myself (woo!).<br />
Let&#8217;s start with:<br />
<code>^http://[A-Za-z0-9]*\.patheticcockroach\.com/.*$</code></p>
<p>I needed this one for various anti-leech protections, including on this very site (notably for the img server), as used in this .htaccess file:</p>
<p><code>RewriteEngine on<br />
RewriteCond %{HTTP_REFERER} !^http://patheticcockroach\.com/.*$      [NC]<br />
RewriteCond %{HTTP_REFERER} !^http://patheticcockroach\.com$      [NC]<br />
RewriteCond %{HTTP_REFERER} !^http://[A-Za-z0-9]*\.patheticcockroach\.com/.*$      [NC]<br />
RewriteCond %{HTTP_REFERER} !^http://[A-Za-z0-9]*\.patheticcockroach\.com$      [NC]<br />
RewriteCond %{HTTP_REFERER} !^$      [NC]<br />
RewriteRule \.(jpg|jpeg|gif|png|bmp|7z|exe|xpi)$ - [F,NC]</code></p>
<ul>
<li>RewriteEngine on: loads mod_rewrite (NB: you still need to have mod_rewrite enabled in your Apache configuration, though)</li>
<li>RewriteCond %{HTTP_REFERER} !^http://patheticcockroach\.com$      [NC]: RewriteCond is a directive which defines a condition under which rewriting will take place. The syntax is RewriteCond $StringToTest $Regex [$flags].<br />
%{HTTP_REFERER} refers to the referrer HTTP header (variable names have to be used like: %{variable name}). &#8220;!&#8221; means (like usual) &#8220;not&#8221;.<br />
^http://patheticcockroach\.com$ is the regexp to which we compare the referrer. &#8220;^&#8221; means string start, &#8220;\&#8221; is used to escape the dots (which otherwise are part of regex syntax), &#8220;$&#8221; means string end.<br />
[NC] means we don&#8217;t care about the case.<br />
So this regex will match &#8220;http://patheticcockroach.com&#8221;, and with the additional mod_rewrite NC flag, this will also match, for instance &#8220;http://PATHETICcockroach.com&#8221;</li>
<li>RewriteCond %{HTTP_REFERER} !^http://patheticcockroach\.com/.*$      [NC]: almost the same, except for the &#8220;.*&#8221;. &#8220;.&#8221; (dot) means &#8220;any character&#8221;. &#8220;*&#8221; (asterisk) means &#8220;the preceding element can be there zero to an infinite number of times&#8221;.<br />
So this will match, for instance &#8220;http://patheticcockroach.com/mpam4/?p=4&#8243;.</li>
<li>RewriteCond %{HTTP_REFERER} !^http://[A-Za-z0-9]*\.patheticcockroach\.com$      [NC]: [A-Za-z0-9] means &#8220;one character in the range A to Z, a to z or 0 to 9&#8243;. As we saw earlier, &#8220;*&#8221; means &#8220;the preceding element can be there zero to an infinite number of times&#8221;.<br />
So this will match things like &#8220;http://notepad.patheticcockroach.com&#8221; or &#8220;http://ngfdg45FD.patheticcockroach.com&#8221;. Note that specifying A to Z AND a to z is redundant, since we specify at the end &#8220;[NC]&#8220;.</li>
<li>RewriteCond %{HTTP_REFERER} !^$      [NC]: ^$ is the empty string, so if the user uses a very old browser which doesn&#8217;t send referrers (or most likely a browser configured to not send referrers), we still accept it.</li>
<li>RewriteRule \.(jpg|jpeg|gif|png|bmp|7z|exe|xpi)$ &#8211; [F,NC]: RewriteRule is a directive which defines rules for the rewriting engine. The syntax is RewriteRule $Regex $Substitution [$flags].<br />
\.(jpg|jpeg|gif|png|bmp|7z|exe|xpi)$ matches &#8220;.jpg&#8221;, &#8220;.jpeg&#8221;, &#8220;.gif&#8221;, &#8220;.png&#8221;, &#8220;.bmp&#8221;, &#8220;.7z&#8221;, &#8220;.exe&#8221;, &#8220;.xpi&#8221;. We already saw the meanings of &#8220;\&#8221; (backslash), &#8220;.&#8221; and &#8220;$&#8221;. The parentheses are used the same way as most often, to group/sort operators. &#8220;|&#8221; (vertical bar) means &#8220;or&#8221;. So jpg|png means jpg or png. And \.(jpg|png) means .jpg or .png.<br />
&#8220;-&#8221; (dash) means we do no substitution. We already saw the NC flag. The F flag means the requested URL will be forbidden (if the RewriteConds are all true, eg if the URL doesn&#8217;t match our regex.</li>
</ul>
<p>The funny thing is that, as I wrote this post, I got a bit more friendly to regexp and mod_rewrite&#8230; well, that was part of the objective I guess. The references I used today:</p>
<ul>
<li><a href="http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html">mod_rewrite in the Apache 2.2 documentation</a> (talks about RewriteEngine, RewriteCond, RewriteRule and much more)</li>
<li><a href="http://en.wikipedia.org/wiki/Regular_expression">Regular expressions on Wikipedia</a>: not the &#8220;decent manual&#8221; I was talking about in the intro, but still decent indeed <img src='http://notepad.patheticcockroach.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </li>
<li><a href="http://msdn.microsoft.com/en-us/library/hs600312(VS.80).aspx">Some page on regex on Micro$oft</a>. I didn&#8217;t really use it, but this is what decided me to make this post, and there are some elements I&#8217;d like to check later&#8230; Okay, I&#8217;m just making a bookmark.</li>
<li><a href="http://www.regular-expressions.info/javascriptexample.html">A regex tester</a> (making another bookmark indeed).</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://notepad.patheticcockroach.com/237/a-bit-on-regular-expressions-my-htaccess-files/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A First Person Shooter in javascript?</title>
		<link>http://notepad.patheticcockroach.com/128/a-first-person-shooter-in-javascript/</link>
		<comments>http://notepad.patheticcockroach.com/128/a-first-person-shooter-in-javascript/#comments</comments>
		<pubDate>Sun, 14 Jan 2007 12:08:00 +0000</pubDate>
		<dc:creator>David Dernoncourt</dc:creator>
				<category><![CDATA[freewares]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[web development]]></category>

		<guid isPermaLink="false">http://notepad.patheticcockroach.com/?p=128</guid>
		<description><![CDATA[With the Canvas tag, it&#8217;s now possible. This article includes an emulator that loads roms and many proof of concept applications using this tag Read on]]></description>
			<content:encoded><![CDATA[<p>With the Canvas tag, it&#8217;s now possible. This article includes an emulator that loads roms and many proof of concept applications using this tag</p>
<p><a href="http://www.whenpenguinsattack.com/2007/01/10/5-cool-javascript-apps/">Read on</a></p>
]]></content:encoded>
			<wfw:commentRss>http://notepad.patheticcockroach.com/128/a-first-person-shooter-in-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Why not .NET?</title>
		<link>http://notepad.patheticcockroach.com/115/why-not-net/</link>
		<comments>http://notepad.patheticcockroach.com/115/why-not-net/#comments</comments>
		<pubDate>Mon, 18 Dec 2006 15:36:00 +0000</pubDate>
		<dc:creator>David Dernoncourt</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[web development]]></category>

		<guid isPermaLink="false">http://notepad.patheticcockroach.com/?p=115</guid>
		<description><![CDATA[From modernlifeisrubbish.co.uk : Why use PHP over ASP.NET?]]></description>
			<content:encoded><![CDATA[<p>From modernlifeisrubbish.co.uk : <a href="http://www.modernlifeisrubbish.co.uk/article/why-not-dot-net">Why use PHP over ASP.NET?</a></p>
]]></content:encoded>
			<wfw:commentRss>http://notepad.patheticcockroach.com/115/why-not-net/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WinZip serial number algorithm on Google CodeSearch !</title>
		<link>http://notepad.patheticcockroach.com/79/winzip-serial-number-algorithm-on-google-codesearch%c2%a0/</link>
		<comments>http://notepad.patheticcockroach.com/79/winzip-serial-number-algorithm-on-google-codesearch%c2%a0/#comments</comments>
		<pubDate>Sat, 07 Oct 2006 08:37:00 +0000</pubDate>
		<dc:creator>David Dernoncourt</dc:creator>
				<category><![CDATA[Google]]></category>
		<category><![CDATA[funnies]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://notepad.patheticcockroach.com/?p=79</guid>
		<description><![CDATA[Just by searching for &#8220;keygen&#8221;, &#8220;serial&#8221;, &#8220;name&#8221;, and some well known cracker groups you can come by the keygen sources (how serial numbers are generated) to some very popular programs. I found WinZip, Photoshop, mIRC, and a few others&#8230; Read more &#124; Digg it]]></description>
			<content:encoded><![CDATA[<p>Just by searching for &#8220;keygen&#8221;, &#8220;serial&#8221;, &#8220;name&#8221;, and some well known cracker groups you can come by the keygen sources (how serial numbers are generated) to some very popular programs. I found WinZip, Photoshop, mIRC, and a few others&#8230;</p>
<p><a href="http://www.google.com/codesearch?q=+keygen+name+serial+show:n7lzx83Fh-k:Z1tHhQiuqr0:5FzGruqYsUI&#038;sa=N&#038;cd=21&#038;ct=rc&#038;cs_p=www.cs.mcgill.ca/~cs520/JOOS1.1/joosbench2005-v2.tar.gz&#038;cs_f=joosbench05/01Benchmark/KeyGen.java#a0">Read more</a> | <a href="http://digg.com/programming/WinZip_Serial_Number_Algorithm_Found_on_NEW_Google_CodeSearch">Digg it</a></p>
]]></content:encoded>
			<wfw:commentRss>http://notepad.patheticcockroach.com/79/winzip-serial-number-algorithm-on-google-codesearch%c2%a0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Swears in the Source Code</title>
		<link>http://notepad.patheticcockroach.com/78/swears-in-the-source-code/</link>
		<comments>http://notepad.patheticcockroach.com/78/swears-in-the-source-code/#comments</comments>
		<pubDate>Sat, 07 Oct 2006 08:31:00 +0000</pubDate>
		<dc:creator>David Dernoncourt</dc:creator>
				<category><![CDATA[Google]]></category>
		<category><![CDATA[funnies]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://notepad.patheticcockroach.com/?p=78</guid>
		<description><![CDATA[We all know programmers swear a lot. Google recently released the Google Code search, which searches through open source tarballs and zips, and tries to find the number of occurences of a specific query. Guess what this guy was looking for&#8230; Read more &#124; Digg it]]></description>
			<content:encoded><![CDATA[<p>We all know programmers swear a lot. Google recently released the Google Code search, which searches through open source tarballs and zips, and tries to find the number of occurences of a specific query. Guess what this guy was looking for&#8230;</p>
<p><a href="http://blog.predius.org/2006/10/05/fucks-per-source-package-and-license/">Read more</a> | <a href="http://digg.com/programming/Swears_in_the_Source_Code">Digg it</a></p>
]]></content:encoded>
			<wfw:commentRss>http://notepad.patheticcockroach.com/78/swears-in-the-source-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
