<?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>Misanthropic Geek Dot Net</title>
	<atom:link href="http://www.misanthropicgeek.net/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://www.misanthropicgeek.net</link>
	<description>This should say something witty, shouldn&#039;t it?</description>
	<lastBuildDate>Sat, 14 Aug 2010 06:40:03 +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>App-Fu: VLC Plays Youtube Clips</title>
		<link>http://www.misanthropicgeek.net/?p=784</link>
		<comments>http://www.misanthropicgeek.net/?p=784#comments</comments>
		<pubDate>Thu, 12 Aug 2010 06:34:25 +0000</pubDate>
		<dc:creator>Vhati</dc:creator>
				<category><![CDATA[App-Fu]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[OSX]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.misanthropicgeek.net/?p=784</guid>
		<description><![CDATA[VLC 1.1.x accepts youtube urls in its &#8220;Open Network Stream&#8230;&#8221; dialog. It&#8217;ll opt for the highest resolution available, so if you want to force a less taxing quality, add this to your url. http://www.youtube.com/watch?v=yadda&#038;fmt=5 This means you can save it to a file without a separate downloader tool/site. And/or you can watch at 2x speed [...]]]></description>
			<content:encoded><![CDATA[<p>VLC 1.1.x accepts youtube urls in its &#8220;Open Network Stream&#8230;&#8221; dialog.</p>
<p>It&#8217;ll opt for the highest resolution available, so if you want to force a <a href="http://en.wikipedia.org/wiki/YouTube#Quality_and_codecs" target="_blank">less taxing quality</a>, add this to your url.</p>
<blockquote><p>http://www.youtube.com/watch?v=yadda<b>&#038;fmt=5</b></p></blockquote>
<p>This means you can save it to a file without a separate downloader tool/site. And/or you can watch at 2x speed or crank up the volume to 400% with the mouse wheel. Unless you save before watching, it&#8217;s subject to buffering, so seeking is best avoided.<br />
&nbsp;<br />
&nbsp;<br />
It relies on an external script to scrape the page and fetch the video. That&#8217;s what needs fixing when youtube&#8217;s site changes.</p>
<blockquote><p>VLC_Dir\App\vlc\lua\playlist\youtube.lua</p></blockquote>
<p>Judging from the dir listing, several other sites are understood too.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.misanthropicgeek.net/?feed=rss2&amp;p=784</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sed One-Liner to Mass-Rename</title>
		<link>http://www.misanthropicgeek.net/?p=740</link>
		<comments>http://www.misanthropicgeek.net/?p=740#comments</comments>
		<pubDate>Tue, 20 Jul 2010 10:45:15 +0000</pubDate>
		<dc:creator>Vhati</dc:creator>
				<category><![CDATA[App-Fu]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[OSX]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.misanthropicgeek.net/?p=740</guid>
		<description><![CDATA[Linux&#8217;s perl package has a command called &#8220;rename&#8221; which understands regular expressions. Windows lacks that, of course. I&#8217;ll recreate it using sed, in a way that&#8217;s consistent across platforms&#8230; It won&#8217;t spring to mind when you need it (unless you&#8217;re really familiar with sed), but the exercise is a decent excuse to demonstrate the oft-neglected [...]]]></description>
			<content:encoded><![CDATA[<p>Linux&#8217;s perl package has a command called &#8220;<a href="http://tips.webdesign10.com/how-to-bulk-rename-files-in-linux-in-the-terminal" target="_blank">rename</a>&#8221; which understands regular expressions.</p>
<p>Windows lacks that, <em>of course</em>. I&#8217;ll recreate it using sed, in a way that&#8217;s consistent across platforms&#8230;</p>
<p>It won&#8217;t spring to mind when you need it (unless you&#8217;re really familiar with sed), but the exercise is a decent excuse to demonstrate the oft-neglected hold buffer.<br />
&nbsp;<br />
<span id="more-740"></span><br />
I&#8217;ll start by echoing a test string in and letting the shell catch what comes out (REGEX_HERE is a pseudocode placeholder).</p>
<blockquote><pre>ECHO zzz|
sed "h; REGEX_HERE ;s/.*/\x22&#038;\x22/;x;s/.*/rename \x22&#038;\x22/;G;s/\n/ /"</pre>
</blockquote>
<p>&nbsp;<br />
Here&#8217;s what sed&#8217;s doing step-by-step.</p>
<table border='1' cellpadding='2'>
<tr>
<td><strong>Command</strong></td>
<td><strong>Pattern</strong></td>
<td><strong>Hold</strong></td>
</tr>
<tr>
<td></td>
<td>zzz</td>
<td></td>
</tr>
<tr>
<td>
<pre>h</pre>
</td>
<td>
<pre>zzz</pre>
</td>
<td>
<pre>zzz</pre>
</td>
</tr>
<tr>
<td>
<pre>REGEX_HERE</pre>
</td>
<td>
<pre>NEW_NAME</pre>
</td>
<td>
<pre>zzz</pre>
</td>
</tr>
<tr>
<td>
<pre>s/.*/\x22&#038;\x22/</pre>
</td>
<td>
<pre>"NEW_NAME"</pre>
</td>
<td>
<pre>zzz</pre>
</td>
</tr>
<tr>
<td>
<pre>x</pre>
</td>
<td>
<pre>zzz</pre>
</td>
<td>
<pre>"NEW_NAME"</pre>
</td>
</tr>
<tr>
<td>
<pre>s/.*/rename \x22&#038;\x22/</pre>
</td>
<td>
<pre>rename "zzz"</pre>
</td>
<td>
<pre>"NEW_NAME"</pre>
</td>
</tr>
<tr>
<td>
<pre>G</pre>
</td>
<td>
<pre>rename "zzz"{newline}"NEW_NAME"</pre>
</td>
<td>
<pre>"NEW_NAME"</pre>
</td>
</tr>
<tr>
<td>
<pre>s/\n/ /</pre>
</td>
<td>
<pre>rename "zzz" "NEW_NAME"</pre>
</td>
<td>
<pre>"NEW_NAME"</pre>
</td>
</tr>
</table>
<p>&nbsp;<br />
&#8220;&#038;&#8221; in a regex replacement means whatever string was matched.<br />
&#8220;\x22&#8243; is the hex character code for a double-quote, to avoid nesting complications.<br />
&#8220;h&#8221; copies the pattern buffer into the hold.<br />
&#8220;x&#8221; swaps pattern and hold.<br />
&#8220;G&#8221; appends a newline and the hold to the end of the pattern buffer.<br />
&nbsp;<br />
&nbsp;<br />
Replace REGEX_HERE with whatever you want done to each name, like &#8220;s/z/y/g&#8221; to globally change all z&#8217;s to y&#8217;s. Swap out the echo to &#8220;DIR /B&#8221;. And pipe sed into &#8220;CMD /Q&#8221;.</p>
<blockquote><pre>DIR /B |
sed "h; s/z/y/g ;s/.*/\x22&#038;\x22/;x;s/.*/rename \x22&#038;\x22/;G;s/\n/ /" |
CMD /Q</pre>
</blockquote>
<p>Everything in the current folder has been renamed.<br />
&nbsp;<br />
&nbsp;<br />
Linux and OSX would use basically the same thing, but with mv, ls, and sh.</p>
<blockquote><pre>ls |
sed "h; s/z/y/g ;s/.*/\x22&#038;\x22/;x;s/.*/mv \x22&#038;\x22/;G;s/\n/ /" |
sh</pre>
</blockquote>
<p>&nbsp;<br />
&nbsp;<br />
Further reading: As plugged in an earlier sed romp, CatOnMat&#8217;s <a href="http://www.catonmat.net/blog/sed-stream-editor-cheat-sheet" target="_blank">cheatsheet</a> and Bruce Barnett&#8217;s <a href="http://www.grymoire.com/Unix/Sed.html" target="_blank">guide</a> are incredibly informative.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.misanthropicgeek.net/?feed=rss2&amp;p=740</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>RancidMeat: Grub4Dos</title>
		<link>http://www.misanthropicgeek.net/?p=717</link>
		<comments>http://www.misanthropicgeek.net/?p=717#comments</comments>
		<pubDate>Mon, 19 Jul 2010 09:51:59 +0000</pubDate>
		<dc:creator>Vhati</dc:creator>
				<category><![CDATA[RancidMeat]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.misanthropicgeek.net/?p=717</guid>
		<description><![CDATA[Delayed whim I followed up on this week: a fork of GNU Grub.* Once I settled on one of the myriad riggings that clutter the docs, it was easy to set up from within Windows. No Linux necessary. &#160; Why didn&#8217;t I leave the MS bootloader be? I like flexibility. In this case the OS [...]]]></description>
			<content:encoded><![CDATA[<p>Delayed whim I followed up on this week: a <a href="http://grub4dos.sourceforge.net/wiki/index.php/Main_Page" target="_blank">fork</a> of GNU Grub.*</p>
<p>Once I settled on one of the myriad riggings that clutter the docs, it was easy to set up from within Windows. No Linux necessary.<br />
&nbsp;<br />
<span id="more-717"></span><br />
Why didn&#8217;t I leave the MS bootloader be? I like flexibility. In this case the OS is WinXP, and an occasional USB enclosure with Linux. The motherboard stopped seeing that as bootable after I migrated the Linux drive from a prior enclosure. And I got sick of bootstrapping it with a Grub CD. This fork can boot ISOs and disk images, which is handy too.<br />
&nbsp;<br />
&nbsp;<br />
1) Get the latest &#8220;<a href="http://download.gna.org/grub4dos/" target="_blank">grub4dos-x.x.x-xxxx-xx-xx.zip</a>&#8220;.<br />
2) Take &#8220;grldr&#8221; and &#8220;menu.lst&#8221; from the archive and put them in the root of a partition. Chuck the rest.<br />
3) Get the latest &#8220;<a href="http://download.gna.org/grubutil/" target="_blank">grubinst-x.x-bin-w32-xxxx-xx-xx.zip</a>&#8221;<br />
4) Extract that to a temporary folder to run this one time.<br />
5) Run &#8220;grubinst_gui.exe&#8221;<br />
&nbsp;&nbsp;Pick a device from the Disk dropdown list.<br />
&nbsp;&nbsp;Click &#8220;Install&#8221;</p>
<p>That&#8217;s enough to successfully reboot into various flavors of Windows.</p>
<p>It worked out of the box for me. According to the docs, if the bootloader panics, it&#8217;ll fall back to a relocated backup of the old MBR. Or you can cautiously dd your own copy under Knoppix beforehand. Or run &#8220;fixmbr&#8221;/&#8221;fixboot&#8221; from a Windows install CD&#8217;s recovery console afterward.</p>
<p>Now break out Wordpad and start playing with that example menu.lst. There&#8217;s a bit of help <a href="http://diddy.boot-land.net/grub4dos/Grub4dos.htm" target="_blank">here</a>.<br />
&nbsp;<br />
&nbsp;<br />
Here&#8217;s my pared down menu.</p>
<blockquote><p># This menu is for Grub4Dos<br />
# (Installed to the MBR, seeking /grldr)</p>
<p>color white/black<br />
timeout 8<br />
default 0</p>
<p>title Windows XP<br />
root (hd0,0)<br />
chainloader /ntldr</p>
<p>title Wanderer (Cold boot for this, MoBo quirk)<br />
root (hd1,0)<br />
kernel /boot/vmlinuz-2.6.26-2-686 root=LABEL=roam quiet vga=791<br />
initrd=/boot/initrd.img-2.6.26-2-686</p>
<p>title .</p>
<p>title Prompt<br />
commandline</p>
<p># For when I din&#8217;t feel like burning&#8230;<br />
title BootMe.iso<br />
find &#8211;set-root /BootMe.iso<br />
map /BootMe.iso (0xff) || map &#8211;mem /BootMe.iso (0xff)<br />
map &#8211;hook<br />
chainloader (0xff)</p></blockquote>
<p>&nbsp;<br />
&nbsp;<br />
* There&#8217;s an even fresher unstable Chinese fork of Grub4Dos by chenall, but I wasn&#8217;t <em>that</em> adventurous.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.misanthropicgeek.net/?feed=rss2&amp;p=717</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Switching Back to Google Classic</title>
		<link>http://www.misanthropicgeek.net/?p=690</link>
		<comments>http://www.misanthropicgeek.net/?p=690#comments</comments>
		<pubDate>Sun, 09 May 2010 13:30:00 +0000</pubDate>
		<dc:creator>Vhati</dc:creator>
				<category><![CDATA[Linkdump]]></category>
		<category><![CDATA[Tech]]></category>

		<guid isPermaLink="false">http://www.misanthropicgeek.net/?p=690</guid>
		<description><![CDATA[Edit (2010-05-20): &#8220;hl=all&#8221; no longer works. Assuming you don&#8217;t want pirate-speak (&#8220;hl=xx-pirate&#8221; which still does), I rewrote the post. &#160; &#160; If you can&#8217;t stand the new clutter on Google, there&#8217;s a blog devoted to reverting (the Opera userjs there worked): http://theoldgoogle.blogspot.com/ &#160; &#160; To disable suggestions, make this your homepage. http://www.google.com/webhp?complete=0&#038;hl=en]]></description>
			<content:encoded><![CDATA[<p><strong>Edit (2010-05-20):</strong> &#8220;hl=all&#8221; no longer works. Assuming you don&#8217;t want pirate-speak (&#8220;hl=xx-pirate&#8221; which still does), I rewrote the post.<br />
&nbsp;<br />
&nbsp;<br />
If you can&#8217;t stand the new clutter on Google, there&#8217;s a blog devoted to reverting (the Opera userjs there worked):</p>
<p><a href="http://theoldgoogle.blogspot.com/" target="_blank">http://theoldgoogle.blogspot.com/</a><br />
&nbsp;<br />
&nbsp;<br />
To disable suggestions, make this your homepage.</p>
<p><a href="http://www.google.com/webhp?complete=0&#038;hl=en" target="_blank">http://www.google.com/webhp?complete=0&#038;hl=en</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.misanthropicgeek.net/?feed=rss2&amp;p=690</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Peek at Pipes by Copying Stdout to Stderr</title>
		<link>http://www.misanthropicgeek.net/?p=662</link>
		<comments>http://www.misanthropicgeek.net/?p=662#comments</comments>
		<pubDate>Wed, 05 May 2010 17:32:46 +0000</pubDate>
		<dc:creator>Vhati</dc:creator>
				<category><![CDATA[App-Fu]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[OSX]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.misanthropicgeek.net/?p=662</guid>
		<description><![CDATA[I&#8217;m stringing commands together and want to see what&#8217;s passing through a particular point. Technically tee (Linux/UnixUtils) can do this. Its sole purpose is to duplicate stdout to a file, like a metaphorical &#8220;T&#8221; connector. echo hello &#124; tee somefile.txt &#124; sed &#34;s/e/a/&#34; &#160; Attentive readers will be thinking, &#8220;The post just started; what&#8217;s wrong [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m stringing commands together and want to see what&#8217;s passing through a particular point. Technically <strong>tee</strong> (Linux/UnixUtils) can do this. Its sole purpose is to duplicate stdout to a file, like a metaphorical &#8220;T&#8221; connector.</p>
<blockquote><p>echo hello | tee somefile.txt | sed &#34;s/e/a/&#34;</p></blockquote>
<p>&nbsp;<br />
Attentive readers will be thinking,<br />
&#8220;The post just started; what&#8217;s wrong with it?&#8221; :P<br />
&nbsp;<br />
*clickety-click*&#8230; Nothing, this works:</p>
<blockquote><p>echo hello | tee /dev/stderr | sed &#34;s/e/a/&#34;</p></blockquote>
<p>&nbsp;<br />
*drumroll*&#8230; on Linux, where everything&#8217;s a file.</p>
<p>While many MinGW ports on Windows internally translate the likes of &#8220;/dev/stderr&#8221;, the UnixUtils tee does not. A hyphen arg obediently makes a file named &#8220;-&#8221;. Linux guys can keep reading; this trick is nifty.<br />
&nbsp;<br />
<span id="more-662"></span><br />
Objective: Put a command in the pipeline that reads from stdin, and relays to both stdout and stderr.</p>
<blockquote><p>echo hello | gawk &#34;{print; print > \&#34;/dev/stderr\&#34;;}&#34; | sed &#34;s/e/a/&#34;</p></blockquote>
<p>Printing without an arg defaults to $0, incoming lines.<br />
Meh. The gawk part could be tucked into a batch script, but there&#8217;s a shorter way.<br />
&nbsp;<br />
&nbsp;</p>
<blockquote><p>echo hello | sed -u &#34;w /dev/stderr&#34; | sed &#34;s/e/a/&#34;</p></blockquote>
<p>There&#8217;s a lot <a href="http://www.grymoire.com/Unix/Sed.html" target="_blank">more to sed</a> than subtitution.* It can write files too. And by default, it already echoes to stdout. The optional -u makes it buffer less to keep the stream flowing.<br />
&nbsp;<br />
&nbsp;<br />
* When you&#8217;ve soaked up that sed guide, this <a href="http://www.catonmat.net/blog/sed-stream-editor-cheat-sheet" target="_blank">cheat sheet</a> will make sense.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.misanthropicgeek.net/?feed=rss2&amp;p=662</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>App-Fu: Viewing Compressed Traffic in Wireshark</title>
		<link>http://www.misanthropicgeek.net/?p=646</link>
		<comments>http://www.misanthropicgeek.net/?p=646#comments</comments>
		<pubDate>Fri, 30 Apr 2010 13:42:10 +0000</pubDate>
		<dc:creator>Vhati</dc:creator>
				<category><![CDATA[App-Fu]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[OSX]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.misanthropicgeek.net/?p=646</guid>
		<description><![CDATA[According to the preferences, the three sections of Wireshark are: Packet List &#8211; Rows of src/dest/protocol/info Packet Details &#8211; Collapsible tree Packet Bytes &#8211; Tabbed hex dumps Most of the time, if you&#8217;re sniffing text-based traffic, you&#8217;ll find interesting packets, right-click in the list, and &#8220;Follow TCP Stream&#8221;. The problem is Wireshark&#8217;s too honest sometimes, [...]]]></description>
			<content:encoded><![CDATA[<p>According to the preferences, the three sections of <a href="http://www.wireshark.org/" target="_blank">Wireshark</a> are:</p>
<ul>
<li>Packet List &#8211; Rows of src/dest/protocol/info</li>
<li>Packet Details &#8211; Collapsible tree</li>
<li>Packet Bytes &#8211; Tabbed hex dumps</li>
</ul>
<p>Most of the time, if you&#8217;re sniffing text-based traffic, you&#8217;ll find interesting packets, right-click in the list, and &#8220;Follow TCP Stream&#8221;. The problem is Wireshark&#8217;s too honest sometimes, and if the traffic is compressed, you&#8217;ll see the binary garbage that&#8217;s really flowing through the NIC.</p>
<blockquote><p>HTTP/1.1 200 OK<br />
Content-Encoding: gzip</p></blockquote>
<p>If you see this HTTP header, there&#8217;s another approach.<br />
&nbsp;<br />
<span id="more-646"></span><br />
Instead of following the stream, check out the &#8220;Packet Bytes&#8221; section at the bottom. There should be a tab there named &#8220;Uncompressed entity body&#8221;, which is the result of a dissector combining several packets and un-gzipping the message.</p>
<p>The ascii is squashed to the side by the hex dump, so you&#8217;d be tempted to right-click-copy or ctrl-c&#8230; won&#8217;t work.</p>
<p>The way to get the plaintext into the clipboard hides in the middle section, &#8220;Packet Details&#8221;. Collapse all the branches. The bottom branch should be &#8220;Line-based text data: text/html&#8221;. Right-click <em>that</em>, &#8220;Copy&#8221;, &#8220;Bytes (Printable Text Only).&#8221; *</p>
<p>If you want to try this out, start sniffing, and visit <a href="http://www.google.com" target="_blank">Google</a>. It&#8217;s consistently gzipped.<br />
&nbsp;<br />
&nbsp;<br />
This method works for regular traffic too, but following the stream is more convenient.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.misanthropicgeek.net/?feed=rss2&amp;p=646</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>RancidMeat: XMLStarlet</title>
		<link>http://www.misanthropicgeek.net/?p=591</link>
		<comments>http://www.misanthropicgeek.net/?p=591#comments</comments>
		<pubDate>Mon, 26 Apr 2010 11:14:31 +0000</pubDate>
		<dc:creator>Vhati</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[RancidMeat]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.misanthropicgeek.net/?p=591</guid>
		<description><![CDATA[Occasionally I have to parse xml, which is often not grep-friendly. Luckily, there&#8217;s XMLStarlet (the actual command&#8217;s named &#8216;xml&#8217;) to make it relatively easy, if longwinded for a prompt. It&#8217;s in Linux repositories, and there&#8217;s a Windows version. For this post, I&#8217;ll be referring to an example file that looks like this. &#60;?xml version=&#34;1.0&#34;?&#62; &#60;Cast&#62; [...]]]></description>
			<content:encoded><![CDATA[<p>Occasionally I have to parse xml, which is often not grep-friendly. Luckily, there&#8217;s <a href="http://xmlstar.sourceforge.net/" target="_blank">XMLStarlet</a> (the actual command&#8217;s named &#8216;xml&#8217;) to make it relatively easy, if longwinded for a prompt. It&#8217;s in Linux repositories, and there&#8217;s a Windows version.</p>
<p>For this post, I&#8217;ll be referring to an <a href="http://www.misanthropicgeek.net/Blog-Miscellany/futurama_cast.xml">example file</a> that looks like this.</p>
<blockquote><p>&lt;?xml version=&#34;1.0&#34;?&gt;<br />
&lt;Cast&gt;<br />
&lt;Character gender=&#39;M&#39;&gt;<br />
&nbsp;&nbsp;&lt;Name&gt;Fry&lt;/Name&gt;<br />
&nbsp;&nbsp;&lt;Job&gt;Delivery Boy&lt;/Job&gt;<br />
&nbsp;&nbsp;&lt;Species&gt;Human&lt;/Species&gt;<br />
&nbsp;&nbsp;&lt;From&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;Location&gt;Earth&lt;/Location&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;Location&gt;New York&lt;/Location&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;Location&gt;Brooklyn&lt;/Location&gt;<br />
&nbsp;&nbsp;&lt;/From&gt;<br />
&lt;/Character&gt;<br />
&#8230;<br />
&lt;/Cast&gt;</p></blockquote>
<p>&nbsp;<br />
&nbsp;<br />
1) Loop through all characters, printing the value of their name tag and a newline.</p>
<blockquote><p>xml sel -t -m &#34;/Cast/Character&#34; \<br />
-v &#34;Name&#34; \<br />
-n futurama_cast.xml</p></blockquote>
<blockquote><p># Zapp<br />
# Leela<br />
# Amy<br />
# Zoidberg<br />
# Fry<br />
# Bender<br />
# Professor<br />
# Kif</p></blockquote>
<p>&nbsp;<br />
<span id="more-591"></span><br />
2) Count the characters (print the value returned by count()).</p>
<blockquote><p>xml sel -t -v &#34;count(/Cast/Character)&#34; futurama_cast.xml</p></blockquote>
<blockquote><p># 8</p></blockquote>
<p>&nbsp;<br />
&nbsp;<br />
3) Loop through characters based on an attribute.</p>
<blockquote><p>xml sel -t -m &#34;/Cast/Character[@gender=&#39;F&#39;]&#34; \<br />
-v &#34;Name&#34; \<br />
-n futurama_cast.xml</p></blockquote>
<blockquote><p># Leela<br />
# Amy</p></blockquote>
<p>&nbsp;<br />
&nbsp;<br />
4) Loop through characters based on a child tag.</p>
<blockquote><p>xml sel -t -m &#34;/Cast/Character[Job=&#39;Captain&#39;]&#34; \<br />
-v &#34;Name&#34; \<br />
-n futurama_cast.xml</p></blockquote>
<blockquote><p># Zapp<br />
# Leela</p></blockquote>
<p>&nbsp;<br />
&nbsp;<br />
5) Find doctors&#8217; home planets (loop over from tags that belong to characters with a certain job, and print the first location).</p>
<blockquote><p>xml sel -t -m &#34;/Cast/Character[Job=&#39;Doctor&#39;]/From&#34; \<br />
-v &#34;Location&#34; \<br />
-n futurama_cast.xml</p></blockquote>
<blockquote><p># Decapod 10</p></blockquote>
<p>&nbsp;<br />
&nbsp;<br />
6) Print multiple values, with a hardcoded string between them.*</p>
<blockquote><p>xml sel -t -m &#34;/Cast/Character&#34; \<br />
-v &#34;Name&#34; -o &#34;: &#34; \<br />
-v &#34;Species&#34; \<br />
-n futurama_cast.xml</p></blockquote>
<blockquote><p># Zapp: Human<br />
# Leela: Mutant Human<br />
# Amy: Human<br />
# Zoidberg: Decapodian<br />
# Fry: Human<br />
# Bender: Robot<br />
# Professor: Human<br />
# Kif: Amphibiosan</p></blockquote>
<p>&nbsp;<br />
&nbsp;<br />
7) For each character, print the name and a string, then begin a nested loop over any locations, printing their text and a string, then break out of that nest-level.</p>
<blockquote><p>xml sel -t -m &#34;/Cast/Character&#34; \<br />
-v &#34;Name&#34; -o &#34;: &#34; \<br />
-m &#34;From/Location&#34; -v &#34;text()&#34; -o &#34;,&#34; -b \<br />
-n futurama_cast.xml</p></blockquote>
<blockquote><p># Zapp: Earth,<br />
# Leela: Earth,New New York,New New York City,<br />
# Amy: Mars,<br />
# Zoidberg: Decapod 10,<br />
# Fry: Earth,New York,Brooklyn,<br />
# Bender: Earth,Mexico,Tijuana,<br />
# Professor: Earth,New New York,Manhattan,<br />
# Kif: Amphibios 9,</p></blockquote>
<p>&nbsp;<br />
&nbsp;<br />
8) Same as above, but this time nesting an IF to only print the hardcoded string on all except the last location, then break out of the IF.</p>
<blockquote><p>xml sel -t -m &#34;/Cast/Character&#34; \<br />
-v &#34;Name&#34; -o &#34;: &#34; \<br />
-m &#34;From/Location&#34; -v &#34;text()&#34; \<br />
-i &#34;not(position()=last())&#34; -o &#34;, &#34; -b \<br />
-b \<br />
-n futurama_cast.xml</p></blockquote>
<blockquote><p># Zapp: Earth<br />
# Leela: Earth, New New York, New New York City<br />
# Amy: Mars<br />
# Zoidberg: Decapod 10<br />
# Fry: Earth, New York, Brooklyn<br />
# Bender: Earth, Mexico, Tijuana<br />
# Professor: Earth, New New York, Manhattan<br />
# Kif: Amphibios 9</p></blockquote>
<p>&nbsp;<br />
&nbsp;<br />
The args are <a href="http://www.w3schools.com/XPath/xpath_syntax.asp" target="_blank">XPath 1.0</a>. -m takes a list of tags. -v takes the first or only tag/string/etc it sees. -i and [...] are also XPath, but they expect booleans. It&#8217;s a query grammar, so any serious text manipulation needs to be done with other commands/scripts later in the pipeline.<br />
&nbsp;<br />
&nbsp;<br />
* I normally go with -o &#34;\t&#34; as a delimiter; XMLStarlet prints a literal slash-t, necessitating a pipe through sed for real tabs.</p>
<p>Example: Parsing the Freshmeat RSS feed&#8230;<br />
Fetch (one try with a 2 sec timeout) the atom feed (whose tags have a namespace prefix, abbreviated to &#8216;x&#8217;), loop over the entries, and print the titles and links.</p>
<blockquote><p>wget -t 1 -T 2 -O &#45; -q \<br />
&#34;http://freshmeat.net/?format=atom&#34; \<br />
| xml sel -N x=&#34;http://www.w3.org/2005/Atom&#34; -t \<br />
-m &#34;/x:feed/x:entry&#34; \<br />
-v &#34;x:title&#34; -o &#34;\t&#34; -v &#34;x:link/@href&#34; -n \<br />
| sed &#34;s/\\t/\t/g&#34;</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.misanthropicgeek.net/?feed=rss2&amp;p=591</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Understanding People Complexly</title>
		<link>http://www.misanthropicgeek.net/?p=585</link>
		<comments>http://www.misanthropicgeek.net/?p=585#comments</comments>
		<pubDate>Mon, 19 Apr 2010 03:56:04 +0000</pubDate>
		<dc:creator>Kyle</dc:creator>
				<category><![CDATA[Life lessons]]></category>

		<guid isPermaLink="false">http://www.misanthropicgeek.net/?p=585</guid>
		<description><![CDATA[Last week's assignment touched on something I'd like to dive into a little deeper, which is the subject of understanding people complexly.  The basic idea here (despite the name of it) is quite simple.  To understand people complexly is to think of them in terms of their own life and experiences, and see them through the same frame of reference in which they see themselves.  In practice, this can be quite difficult (as I'm sure you already know).  ]]></description>
			<content:encoded><![CDATA[<p>Last week&#8217;s assignment touched on something I&#8217;d like to dive into a little deeper, which is the subject of understanding people complexly.  The basic idea here (despite the name of it) is quite simple.  To understand people complexly is to think of them in terms of their own life and experiences, and see them through the same frame of reference in which they see themselves.  In practice, this can be quite difficult (as I&#8217;m sure you already know).</p>
<p>You&#8217;re probably familiar with the old saying, &#8220;Put yourself in their shoes.&#8221;  What does this really mean, though?  To put yourself in that person&#8217;s shoes is to understand enough about them that you can recognize the reasons why they make the decisions that they do.  Very few (if any) behaviors that you encounter in everyday life are completely irrational.  There are reasons for everything.  These reasons obviously don&#8217;t always line up to our expectations, and often don&#8217;t even line up to the person&#8217;s stated values, but they exist.<br />
&nbsp;<br />
<span id="more-585"></span><br />
So, (you hypothetically ask) if a person&#8217;s reasons don&#8217;t line up with what they tell us about themselves, how are we to figure them out?  We observe their behavior.  You can tell a lot about what matters to someone by paying attention to what they do.  How do they spend their &#8220;me&#8221; time?  How do they react to situations?  How do they act around strangers?  How do they act around friends? How&#8230; well, you get the idea.  Paying attention and noting people&#8217;s behaviors can let you understand them more complexly, and understanding them more complexly can help you to get along with them better in almost any situation.</p>
<p>With all that in mind, this week&#8217;s assignment is to evoke three smiles, but each one must be created using actions/statements/etc. customized for the person you&#8217;re making smile.  This will require knowing what will make that person smile, and not just doing something general.  Obviously the very nature of this exercise requires that you know the person a least a little, so it doesn&#8217;t need to be strangers, but if you want to be an overachiever, you&#8217;re welcome to work on analyzing a stranger enough to do this.</p>
<p>P.S. My intent here is not for you to stalk people.  I just want you to consider other people&#8217;s perspectives and motivations more deeply.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.misanthropicgeek.net/?feed=rss2&amp;p=585</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Batch For Loop Over a List</title>
		<link>http://www.misanthropicgeek.net/?p=534</link>
		<comments>http://www.misanthropicgeek.net/?p=534#comments</comments>
		<pubDate>Thu, 15 Apr 2010 21:57:11 +0000</pubDate>
		<dc:creator>Vhati</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.misanthropicgeek.net/?p=534</guid>
		<description><![CDATA[Say you&#8217;ve got a Windows command to run over and over with a different arg each time. Wouldn&#8217;t it be nice if you could make a word list and loop over it the way bash does? &#160; Because Cmd is RetardedTM, the FOR loop it offers is only for line-oriented records. Imagine a spreadsheet. Records [...]]]></description>
			<content:encoded><![CDATA[<p>Say you&#8217;ve got a Windows command to run over and over with a different arg each time. Wouldn&#8217;t it be nice if you could make a word list and loop over it the way bash does?<br />
&nbsp;<br />
<span id="more-534"></span><br />
Because Cmd is Retarded<sup>TM</sup>, the FOR loop <i>it</i> offers is only for line-oriented records. Imagine a spreadsheet. Records are like rows, and fields are like cells.</p>
<p>FOR has delimiters to chop up a record into fields (aka tokens) and each gets its own letter of the alphabet. The problem there is you need to anticipate the number of fields you&#8217;ll need (capped at 26), your loop will only run once (useless for a list), and all the words will become variables simultaneously (awful).</p>
<blockquote><p>@ECHO OFF<br />
FOR /F &#34;tokens=1-4 delims= &#34; %%i IN (&#34;Hermes Zapp Leela Amy&#34;) DO (<br />
&nbsp;&nbsp;ECHO *%%i*<br />
&nbsp;&nbsp;ECHO *%%j*<br />
&nbsp;&nbsp;ECHO *%%k*<br />
&nbsp;&nbsp;ECHO *%%l*<br />
)</p></blockquote>
<p>&nbsp;<br />
&nbsp;<br />
A double-quoted string, however intuitive, isn&#8217;t gonna work. FOR <i>can</i> loop over the stdout from a command though (single quotes). We&#8217;ll just have to feed the loop multiple lines then (as mentioned in an <a href="http://www.misanthropicgeek.net/?p=469" target="_blank">earlier post</a>)&#8230;</p>
<p>Chaining echoes works, but it&#8217;s tedious and ugly, even for batch code.</p>
<blockquote><p>@ECHO OFF<br />
FOR /F &#34;delims=&#34; %%i IN (&#39;ECHO Hermes^&#038;ECHO Zapp^&#038;ECHO Leela^&#038;ECHO Amy&#39;) DO (<br />
&nbsp;&nbsp;ECHO *%%i*<br />
)</p></blockquote>
<p>&nbsp;<br />
&nbsp;<br />
Finally, the tidy equivalent&#8230;</p>
<blockquote><p>@ECHO OFF<br />
SET LIST=Hermes,Zapp,Leela,Amy,Zoidberg,Fry,Bender</p>
<p>SET LIST=ECHO %LIST:,=^^^&#038;ECHO %</p>
<p>FOR /F &#34;delims=&#34; %%i IN (&#39;%LIST%&#39;) DO (<br />
&nbsp;&nbsp;ECHO *%%i*<br />
)</p></blockquote>
<p>A new trick is introduced here. Batch can do some limited <a href="http://www.dostips.com/DtTipsStringManipulation.php" target="_blank">string manipulation</a> on the contents of variables (the %blah% kind, not the %1 or %i kind). In this case, each comma is getting replaced with &#8220;^&#038;ECHO &#8220;. The carets get interpreted away immediately on that line, then again when FOR first looks at it.<br />
&nbsp;<br />
&nbsp;<br />
If the list gets long, you can break it up into several concatenations.</p>
<blockquote><p>SET LIST=Hermes,Zapp,Leela,Amy,Zoidberg,Fry,Bender<br />
SET LIST=%LIST%,Professor,Kif
</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.misanthropicgeek.net/?feed=rss2&amp;p=534</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Why are you getting so worked up?</title>
		<link>http://www.misanthropicgeek.net/?p=531</link>
		<comments>http://www.misanthropicgeek.net/?p=531#comments</comments>
		<pubDate>Mon, 12 Apr 2010 00:13:19 +0000</pubDate>
		<dc:creator>Kyle</dc:creator>
				<category><![CDATA[Life lessons]]></category>

		<guid isPermaLink="false">http://www.misanthropicgeek.net/?p=531</guid>
		<description><![CDATA[A while back I was having a conversation with a friend of mine, and was recounting a bad encounter I had earlier that day.  The gist of it was that someone said some hurtful things to me, and it had hit me pretty hard.  This wise friend of mine said something that has stuck with me since then.  "When someone treats you poorly, it has at least as much to do with them as it does with you."]]></description>
			<content:encoded><![CDATA[<p>A while back I was having a conversation with a friend of mine, and was recounting a bad encounter I had earlier that day.  The gist of it was that someone said some hurtful things to me, and it had hit me pretty hard.  This wise friend of mine said something that has stuck with me since then.  &#8220;When someone treats you poorly, it has at least as much to do with them as it does with you.&#8221;</p>
<p>The brilliance of that statement didn&#8217;t fully sink in that afternoon, as I was still in my own head and being affected by the emotions of the earlier encounter.  As time went on, though, the truth of it really shone through.  In future bad encounters with people, I found myself thinking more analytically about what part of it was something I had truly done, and what part was that other person taking their own problems out on me.  This simple thought process saved me quite a bit of turmoil over the years, and I thought it only fitting that I share it with you.<br />
&nbsp;<br />
<span id="more-531"></span><br />
This advice has also popped up over the years in different forms.  One notable example is the circle of concern/circle of influence, as stated in The Seven Habits of Highly Effective People.  The idea is explained there as making concentric circles representing what you&#8217;re concerned about (bigger, outside circle) and what you have influence over (smaller, inside circle).  When your thoughts are in the space between these two (the area you are concerned about but can&#8217;t influence) you drive yourself a little bonkers.  The trick is to either expand your influence or shrink your concern.  You&#8217;ll never be able to perfectly line up the circles, as there&#8217;s always going to be something you can&#8217;t control that bothers you, but the closer you get them, the happier you are.  Also notable with this example is that they aren&#8217;t always truly concentric circles.  We all have influence over more than we recognize, and when our influence pokes outside our concern, that&#8217;s when we really become a menace.</p>
<p>So, with this in mind, let’s consider how this all plays out.  I&#8217;m talking here about nasty encounters, so we&#8217;ve got two scenarios.  In one, we&#8217;re the recipient, and in the other, we&#8217;re sending the hostility.  In one case someone is mad at you.  The first thing you&#8217;ve got to do is find out what they&#8217;re really upset about.  If it&#8217;s something that&#8217;s within your control, you have to decide whether or not it&#8217;s worth changing your behavior to avoid this conflict (hint: it isn&#8217;t always, but it&#8217;s much better to make that decision rationally).  If it&#8217;s something that&#8217;s outside of your control, then what good will it do to let them get you down about it?  It&#8217;s usually worth trying to explain to the person what they might be able to do to actually fix the situation, but it&#8217;s very rarely worth beating yourself up about it.</p>
<p>The other side is when you&#8217;re angry about something.  If you find yourself snapping at someone, I know it&#8217;s not the easiest thing in the world to try to force yourself to stop and be rational, but I promise it&#8217;s something you can learn to do.  Take a moment.  Figure out what all is really contributing to putting you in this state.  Is it your significant other&#8217;s fault that you had a bad day at work?  Is it that other driver&#8217;s fault that you overslept and are running late?  Is it the waiter&#8217;s fault that you&#8217;re not making a good first impression on your blind date?  Probably not.  Should they have to take the brunt of your anger when they didn&#8217;t cause it, and have little influence in fixing it?  Nope.</p>
<p>Your assignment this time around is to do your best to keep this in mind all week.  Any time conflict arises, or tempers flare, or you notice yourself or someone else getting upset, do everything in your power (jumper cables to the nipples excluded) to figure out the actual causes of that negativity, and determine if it&#8217;s something you can control.  If the causes are truly outside of your control (be honest here, you&#8217;re not helping anyone if you deny responsibility) then just let it go.  Life is too short to be worrying about things you can&#8217;t affect.<br />
&nbsp;<br />
&nbsp;<br />
Disclaimer: I&#8217;m not a psychologist, or a psychiatrist, or any other person who is recognized by the medical or scientific communities to have enough training to be all that helpful to your psychological state.  If you&#8217;re really in a bad way and thinking of doing something drastic, you&#8217;re probably best off talking to someone who *is* qualified.  That said, I&#8217;m not charging you anything for this, and I&#8217;ve found it to be useful in my life, so use it if you&#8217;re so inclined, and ignore it if you&#8217;re not, just don&#8217;t try to sue me.  :-P</p>
]]></content:encoded>
			<wfw:commentRss>http://www.misanthropicgeek.net/?feed=rss2&amp;p=531</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
