<?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>Andrei Zmievski &#187; Hacks</title>
	<atom:link href="http://zmievski.org/category/hacks/feed" rel="self" type="application/rss+xml" />
	<link>http://zmievski.org</link>
	<description>Life, technology, and other good things</description>
	<lastBuildDate>Thu, 01 Dec 2011 17:14:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>NetflixQueueShuffler is Updated</title>
		<link>http://gravitonic.com/2006/09/netflixqueueshuffler-is-updated</link>
		<comments>http://zmievski.org/2006/09/netflixqueueshuffler-is-updated#comments</comments>
		<pubDate>Sat, 02 Sep 2006 22:25:09 +0000</pubDate>
		<dc:creator>Andrei</dc:creator>
				<category><![CDATA[Hacks]]></category>
		<category><![CDATA[Movies]]></category>

		<guid isPermaLink="false">http://www.gravitonic.com/n/?p=160</guid>
		<description><![CDATA[An eagle-eyed user Mike Ryan noticed that Netflix changed the structure of the Queue page and sent in a patch. Download the updated NetflixQueueShuffler.]]></description>
			<content:encoded><![CDATA[<p>An eagle-eyed user Mike Ryan noticed that Netflix changed the structure of the Queue page and sent in a patch. Download the updated <a href="http://www.gravitonic.com/software/other/#NetflixQueueShuffler">NetflixQueueShuffler</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://zmievski.org/2006/09/netflixqueueshuffler-is-updated/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Un-probable Sentences</title>
		<link>http://gravitonic.com/2006/04/un-probable-sentences</link>
		<comments>http://zmievski.org/2006/04/un-probable-sentences#comments</comments>
		<pubDate>Thu, 13 Apr 2006 05:43:14 +0000</pubDate>
		<dc:creator>Andrei</dc:creator>
				<category><![CDATA[Hacks]]></category>

		<guid isPermaLink="false">http://www.gravitonic.com/n/?p=139</guid>
		<description><![CDATA[I decided to start a section on Language and Linguistics, since it&#8217;s one of my passions and I am, after all, pursuing a graduate degree in it. So, I will be posting some interesting tidbits and such from the classes, the Web, and my own experiments. This semester&#8217;s class is Computers and Written Language. It [...]]]></description>
			<content:encoded><![CDATA[<p>I decided to start a section on Language and Linguistics, since it&#8217;s one of my passions and I am, after all, pursuing a graduate degree in it. So, I will be posting some interesting tidbits and such from the classes, the Web, and my own experiments.</p>
<p>This semester&#8217;s class is <a href="http://info.sjsu.edu/web-dbgen/catalog/courses/LING165.html">Computers and Written Language</a>. It basically deals with introductory computational linguistics. Last week we covered <em>n</em>-gram language models, which are statistical models of word sequences. They are called <em>n</em>-gram because <em>n</em>-1 previous words are used to predict the probability of the next one. Such models are useful for a variety of tasks, including speech recognition (&#8220;The sign says key pout&#8221; vs. &#8220;The sign says keep out&#8221;), handwriting recognition, spellchecking, document identification, etc.</p>
<p>The programming assignment we had from the class required us to build a trigram (<em>n</em>=3) model of a given corpus of text. This involves counting occurrences of each trigram and calculating the probability of the final word following two preceding ones. For example, probability of <strong>see</strong> following <strong>want to</strong> can be calculated as:</p>
<blockquote style="font-family: arial,helvetica; text-align: center"><p>Ρ(<em>see</em>|<em>want to</em>)  = C(<em>want to see</em>) / C(<em>want to</em>)</p></blockquote>
<p>That is, probability of <strong>see</strong> given <strong>want to</strong> is the number of times we&#8217;ve seen <strong>want to see</strong> trigram divided by the number of times we&#8217;ve seen <strong>want to</strong> bigram, and it turns out to be low, since <strong>want to</strong> can be followed by many different verbs. P(<em>tonic</em>|<em>gin and</em>), on the other hand, is much higher. You also want to take sentence boundaries into account, since <strong>I</strong> is very likely to begin a sentence in a fiction corpus, but not so much in a financial one.</p>
<p>So the idea is: read corpus, tokenize, count, calculate probabilities. Probably 30-40 lines of code in a language like PHP or Ruby (which is what I used, just for fun). Once I was done though, I thought, well, I have this nice trigram model, what else can I do with it? Ah, apply it in reverse, to generate sentences!</p>
<p>This is also a fairly simple task. Take a pair of words, then look in the list of the words that can possibly follow them, as learned from corpus, pick a probabilty at random and use it to make a selection from the list. Shift the sequence, so that the last word becomes next to last and the current one becomes last, rinse, repeat. The whole process is basically a <a href="http://en.wikipedia.org/wiki/Markov_chain">Markov chain</a>. I added some heuristics for comma insertion, a couple of controls, and called the resulting generator <a href="http://en.wikipedia.org/wiki/Furby"><em>furby</em></a> because it reminded me of that weird little toy from a few years ago that would sit there, absorb the sounds of the outside world, and regurgitate them back in a mangled, but eeriely recognizable manner.</p>
<p>So what kind of sentences did I obtain? Let me quote good old Chomsky first:</p>
<blockquote class="cite"><p><em>The notion &#8220;probability of a sentence&#8221; is an entirely useless one…</em> — Noam Chomsky, 1969</p></blockquote>
<p>I am not going to argue against his statement here, but I will apply it for my own purposes. You see, the sentences that furby generates are not improbable. They are… un-probable. Sometimes they are poetry, sometimes they are normal sentences you&#8217;d find in a book, but mostly they feel like someone who knows English as a second language had a hit of LSD and was asked to write down his thoughts. It&#8217;s English, with a big dollop of whoa-a-ah.</p>
<p>I got a few texts from <a href="http://www.gutenberg.org/">Project Gutenberg</a> site and fed them to furby. Everything from Sherlock Holmes stories to Alice in Wonderland to Robinson Crusoe. Here are some samples of what it spit out:</p>
<blockquote class="cite" style="border-left: 0; line-height: 1.2em"><p>&#8220;I never have had a considerable household, he murmured.&#8221; <em>(sane)</em><br />
&#8220;I remember most vividly, three smashed bicycles in a fury of misery.&#8221; <em>(poetry)</em><br />
&#8220;He put his lips tight, and I wrote to the suspicion that the things had been shattered by his eager face.&#8221; <em>(LSD)</em></p></blockquote>
<p>The cool thing is that the results are in the style of the original text. Here are a couple generated from Twain&#8217;s <em>Huckleberry Finn</em>:</p>
<blockquote class="cite" style="border-left: 0; line-height: 1.2em"><p>&#8220;There was them kind of a whoop nowheres.&#8221;<br />
&#8220;You know bout dat chile stannin mos right in the night-time, sometimes another.&#8221;</p></blockquote>
<p>Note that these are original sentence that do not occur in the texts. It was a lot of fun just running furby over and over again and seeing what it would come up with. But why not mix two authors? I tried a couple, but the best combination seemed to be DH Lawrence&#8217;s <em>Sons and Lovers</em> and the aforementioned Huckleberry Finn. Once it sucked in this unlikely duet, furby decided to become a comedian with a streak of soft-core pornography. Here are some gems:</p>
<blockquote class="cite" style="border-left: 0; line-height: 1.2em"><p>&#8220;She wanted him and a half a sovereign.&#8221;<br />
&#8220;Goodness man don&#8217;t be a fine woman.&#8221;<br />
&#8220;Her mouth to begin working, till pretty late to-night.&#8221;<br />
&#8220;She heard him buy threepennyworth of hot-cross buns, he talked to barmaids,<br />
to almost any woman whom he felt.&#8221;<br />
&#8220;He shoved his muzzle in the wet.&#8221;<br />
&#8220;Joking, laughing with their shafts lying idle on the downward track.&#8221;<br />
&#8220;As the lads enjoyed it when i realised that she was warm, on the pavement<br />
then Dawes then Clara.&#8221;<br />
&#8220;She had never been shaved.&#8221;<br />
&#8220;He lay pressed hard against her and the electric light vanished, and I saw<br />
the wrist and the coconut, and shook her head.&#8221;<br />
&#8220;She could think of the body as it were, prowling abroad.&#8221;<br />
&#8220;The three brothers sat with his finger-tips.&#8221;<br />
&#8220;Eh, dear, if i&#8217;m a trying to get as drunk as a bubble of foam.&#8221;</p></blockquote>
<p>Priceless.</p>
<p>My next goal is to feed it <a href="http://marc.theaimsgroup.com/?l=php-general">php-general</a> archives and see if furby can be more intelligent that most of the postings on that list. Stay tuned.</p>
]]></content:encoded>
			<wfw:commentRss>http://zmievski.org/2006/04/un-probable-sentences/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>NetflixQueueShuffler Update</title>
		<link>http://gravitonic.com/2006/01/netflixqueueshuffler-update</link>
		<comments>http://zmievski.org/2006/01/netflixqueueshuffler-update#comments</comments>
		<pubDate>Fri, 13 Jan 2006 05:34:17 +0000</pubDate>
		<dc:creator>Andrei</dc:creator>
				<category><![CDATA[Hacks]]></category>
		<category><![CDATA[Movies]]></category>

		<guid isPermaLink="false">http://www.gravitonic.com/n/?p=135</guid>
		<description><![CDATA[I upgraded to Firefox 1.5 and found out that my NetflixQueueShuffler GreaseMonkey script no longer worked. So after some digging, I fixed it up and it&#8217;s available for your downloading pleasure.]]></description>
			<content:encoded><![CDATA[<p>I upgraded to Firefox 1.5 and found out that my <a href="http://www.gravitonic.com/software/other/#NetflixQueueShuffler">NetflixQueueShuffler</a> GreaseMonkey script no longer worked. So after some digging, I fixed it up and it&#8217;s available for your downloading pleasure.</p>
]]></content:encoded>
			<wfw:commentRss>http://zmievski.org/2006/01/netflixqueueshuffler-update/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Recognize This</title>
		<link>http://gravitonic.com/2005/10/recognize-this</link>
		<comments>http://zmievski.org/2005/10/recognize-this#comments</comments>
		<pubDate>Wed, 05 Oct 2005 18:29:24 +0000</pubDate>
		<dc:creator>Andrei</dc:creator>
				<category><![CDATA[Hacks]]></category>
		<category><![CDATA[Tech]]></category>

		<guid isPermaLink="false">http://www.gravitonic.com/n/?p=123</guid>
		<description><![CDATA[Face recognition technology is getting really good. Yesterday I saw a link to Intel&#8217;s OpenCV library float through the mailing list at work and a note that someone wrote a PHP extension for it. &#8220;Interesting&#8221;, I thought. I hacked up a simple PHP script that would take an image and process it slightly to make [...]]]></description>
			<content:encoded><![CDATA[<p>Face recognition technology is getting really good. Yesterday I saw a link to Intel&#8217;s <a href="http://www.intel.com/technology/computing/opencv/index.htm">OpenCV</a> library float through the mailing list at work and a note that someone wrote a PHP extension for it. <em>&#8220;Interesting&#8221;</em>, I thought. I hacked up a simple PHP script that would take an image and process it slightly to make detected regions more obvious. <a href="http://www.gravitonic.com/images/blog/facedetect1.jpg">Here&#8217;s</a> an example of the output. Not bad, huh? Then <a href="http://jcole.us/blog/">Jeremy</a> tried another <a href="http://www.gravitonic.com/images/blog/facedetect2.jpg">image</a>, with some spooky results. Note that aside from the person, there are a couple more regions that the library thought was a face. If you look closer, the larger rectangle on the carpet encloses something that does have vague face-like features. Nice job, Intel.</p>
]]></content:encoded>
			<wfw:commentRss>http://zmievski.org/2005/10/recognize-this/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Shuffle My Queue!</title>
		<link>http://gravitonic.com/2005/06/shuffle-my-queue</link>
		<comments>http://zmievski.org/2005/06/shuffle-my-queue#comments</comments>
		<pubDate>Sun, 05 Jun 2005 00:59:51 +0000</pubDate>
		<dc:creator>Andrei</dc:creator>
				<category><![CDATA[Hacks]]></category>
		<category><![CDATA[Movies]]></category>

		<guid isPermaLink="false">http://www.gravitonic.com/n/?p=104</guid>
		<description><![CDATA[This is a random world. And people seem to like randomness: witness the popularity of iPod Shuffle. I am no different. I also watch a lot of movies: my Netflix queue has 72 DVDs in it currently. Recently I wondered whether it was possible to randomize my queue, so that the next DVD that comes [...]]]></description>
			<content:encoded><![CDATA[<p>This is a random world. And people seem to like randomness: witness the popularity of <a href="http://www.apple.com/ipodshuffle/">iPod Shuffle</a>. I am no different. I also watch a lot of movies: my <a id="P9489488503418822129059188164573348" href="http://rss.netflix.com/QueueRSS?id=P9489488503418822129059188164573348">Netflix queue</a> has 72 DVDs in it currently. Recently I wondered whether it was possible to randomize my queue, so that the next DVD that comes in is somewhat of a surprise. After emailing the Netflix customer support and getting back a completely unhelpful reply telling me that I can re-order the queue by changing the priority numbers and clicking a button, I decided that it was time to take matters into my own hands.</p>
<p>Input: <a href="http://greasemonkey.mozdev.org/">GreaseMonkey</a>, Javascript, and a couple of hours of hacking. Output: <a href="http://www.gravitonic.com/software/other/#NetflixQueueShuffler">NetflixQueueShuffler</a>. I know that GreaseMonkey scripts site already has a Netflix queue randomizer, but I think that one is lame, since all it does is change the priority numbers and click the submit button for you. Mine actually re-orders the table rows visually and lets you do it a few times until you are satisfied with the randomness.</p>
]]></content:encoded>
			<wfw:commentRss>http://zmievski.org/2005/06/shuffle-my-queue/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Music Hunger Satisfied</title>
		<link>http://gravitonic.com/2005/05/music-hunger-satisfied</link>
		<comments>http://zmievski.org/2005/05/music-hunger-satisfied#comments</comments>
		<pubDate>Sun, 29 May 2005 05:04:22 +0000</pubDate>
		<dc:creator>Andrei</dc:creator>
				<category><![CDATA[Hacks]]></category>

		<guid isPermaLink="false">http://www.gravitonic.com/n/?p=102</guid>
		<description><![CDATA[Well, I am happy to report that I resolved my problem of how to play YME music through my stereo. Norbert Mocsnik set me on the right track but he lamented that it was not a software-only solution. So how did I accomplish this? Install and configure ShoutCast Server on my Windows machine. Install WinAmp [...]]]></description>
			<content:encoded><![CDATA[<p>Well, I am happy to report that I resolved my problem of how to play <a href="http://music.yahoo.com/musicengine/">YME</a> music through my stereo. Norbert Mocsnik <a id="101" href="http://www.gravitonic.com/blog/scripts/mt-comments.cgi?entry_id=101">set me on the right track</a> but he lamented that it was not a software-only solution. So how did I accomplish this?</p>
<ol>
<li>Install and configure <a href="http://www.shoutcast.com/download/serve.phtml">ShoutCast Server</a> on my Windows machine.</li>
<li>Install <a href="http://www.shoutcast.com/download/broadcast.phtml">WinAmp DSP ShoutCast plug-in</a>.</li>
<li>Open the mixer and select Wave under recording panel.</li>
<li>Open WinAmp preferences, select the ShoutCast plug-in in the DSP section. A control panel will pop-up.</li>
<li>Go to Input tab and select Souncard Input under Input Device. This means that instead of using WinAmp to play the audio, the plug-in will record the data being played through soundcard&#8217;s output and re-broadcast it.</li>
<li>Configure Output and Encoder tabs per DSP plug-in&#8217;s docs, and connect to ShoutCast server.</li>
<li>Start YME and hit play.</li>
<li>Point the XboxMediaCenter at the ShoutCast stream.</li>
</ol>
<p>Bingo. All that is required are a couple of pieces of software and a full-duplex soundcard capable of recording its own playback (basically, a loopback mechanism). While it&#8217;s a not a one-button solution, it works well enough and now I can enjoy my custom Yahoo! radio station in full glory of 5.1 audio.</p>
]]></content:encoded>
			<wfw:commentRss>http://zmievski.org/2005/05/music-hunger-satisfied/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>mod_auth_sqlite</title>
		<link>http://gravitonic.com/2003/05/mod_auth_sqlite</link>
		<comments>http://zmievski.org/2003/05/mod_auth_sqlite#comments</comments>
		<pubDate>Mon, 19 May 2003 17:40:41 +0000</pubDate>
		<dc:creator>Andrei</dc:creator>
				<category><![CDATA[Hacks]]></category>

		<guid isPermaLink="false">http://www.gravitonic.com/n/?p=14</guid>
		<description><![CDATA[I wrote a module for Apache 1.3.x to perform user and group authentication from an SQLite database. You can check it out here.]]></description>
			<content:encoded><![CDATA[<p>I wrote a module for Apache 1.3.x to perform user and group authentication from an SQLite database. You can check it out <a href="/software/other/index.php">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://zmievski.org/2003/05/mod_auth_sqlite/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

