<?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"?><rss 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/" version="2.0">

<channel>
	<title>Y4K Studios</title>
	
	<link>http://www.y4kstudios.com/wordpress</link>
	<description>Some blog by some geek.</description>
	<pubDate>Mon, 06 Jul 2009 16:53:24 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/y4kstudios" type="application/rss+xml" /><item>
		<title>Of School and iPods</title>
		<link>http://www.y4kstudios.com/wordpress/05152009/of-school-and-ipods/</link>
		<comments>http://www.y4kstudios.com/wordpress/05152009/of-school-and-ipods/#comments</comments>
		<pubDate>Sat, 16 May 2009 04:07:13 +0000</pubDate>
		<dc:creator>theY4Kman</dc:creator>
		
		<category><![CDATA[School]]></category>

		<guid isPermaLink="false">http://www.y4kstudios.com/wordpress/?p=76</guid>
		<description><![CDATA[As an avid follower of civil disobedience, like all teenagers, I disregard my school&#8217;s electronics policy when it makes no sense. For example, in between classes and during lunch, there is no reason why students shouldn&#8217;t be able to use their cell phones and PMPs. Of course, using cell phones and other devices in class [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://en.wikipedia.org/wiki/Henry_David_Thoreau"><img src="http://www.y4kstudios.com/wordpress/uploads/2009/05/henry_david_thoreau-150x150.jpg" alt="Henry David Thoreau" title="Henry David Thoreau" width="150" height="150" class="alignleft size-thumbnail wp-image-79" /></a>As an avid follower of civil disobedience, like all teenagers, I disregard my school&#8217;s electronics policy when it makes no sense. For example, in between classes and during lunch, there is no reason why students shouldn&#8217;t be able to use their cell phones and <abbr title="Portable Media Players">PMPs</abbr>. Of course, using cell phones and other devices in class is quite disruptive, and is grounds for some disciplinary action. Here&#8217;s the full text of the Sickles High School electronics policy:</p>
<blockquote><p>Cell Phones/Electronic Devices/Personal Property:</p>
<p>The cell phone/electronics policy is stated that a a student with a cell phone or electronic device out, the device may be confiscated and a parent must pick up the confiscated item when it is available for pick up, which is only on Thursdays from 2:00pm till 3:30pm. Personal electronic devices, i.e., beepers, CD players, radios, electronic games or any unnecessary devices deemed potentially disruptive shall not be allowed at school.</p>
<p>Cell phones shall not be activated or used during school hours or on school buses. The school shall not accept responsibility for cell phones, personal electronic devices or personal property of any kind including money. Failure to comply with these procedures may result in confiscation of cell phones, electronic devices or personal property and students will be subject to disciplinary action for repeated offenses.</p></blockquote>
<p>Wait, let&#8217;s back up there. A parent can pick up their child&#8217;s electronics &#8220;only on Thursdays from 2:00pm till 3:30pm.&#8221; What parent can make it to the school at that time? Most parents have work or job interviews to be at. And cell phones are not only a means for social interaction &#8212; they are necessary for communication between family and in emergency situations. What happens when a student&#8217;s phone is taken away on a Thursday? They can&#8217;t call their parents to come get it. It&#8217;ll be a week before they might be able to have their phone again.</p>
<p>Anyways, this post is not about the flaws in their policy. It&#8217;s about the flaws in following their policy.</p>
<p>In March, I was walking down the hall to lunch listening to my iPod. A Mr. Medvin pulled me aside, took my iPod, headphones, and my name (he didn&#8217;t write it down). For two Thursdays afterward, I went to the main office to get the iPod back. The first time I visited, I found out about the electronics policy. I&#8217;d hoped a simple phone call to my dad would allow them to relinquish my beautiful, shiny sound maker. However, that turned out not to be the case, as neither the man guarding the electronics (Luis Rodriguez) nor the principal would accept a phone call on the spot.</p>
<p>I then asked my dad to call in ahead of time, so the school could give my dad the whole spiel about how I&#8217;m a horrible kid and I should never bring my iPod into school, and they would finally hand it back to me. Instead, the administrator on the phone told him he needed to come into the main office between 2:30PM and 3:30PM on Thursday with photo ID. &#8220;Screw that,&#8221; my dad and I thought. I lived without music for a couple of months, which really sucked, but I made it through somehow. It probably forced me to interact a bit more socially, but that&#8217;s the only good consequence.</p>
<p>Finally, my dad was able to drive in &#8212; this was yesterday, Thursday, May 14, 2009. He met Mr. Luis Rodriguez in the main office and presented his photo ID. There was no talk about the school&#8217;s electronic policy. They just wanted to punish the parent for the student&#8217;s mistake by hassling the parent until it becomes such a bother that they make sure their kid doesn&#8217;t screw up again. Of course, this doesn&#8217;t work at all. It just breeds hatred and noncooperation between the parents and the school.</p>
<p>Mr. Rodriguez searched through the basket of assorted iPods, Sidekicks, and Zunes enclosed in brown clasp envelopes. Searching, searching, searching&#8230;&#8221;Nope. No iPod here registered to your son.&#8221;<br />
<strong>My dad</strong>: &#8220;Alright, what happens now?&#8221;<br />
<strong>Rodriguez</strong>: &#8220;Well, you can check in Student Affairs or talk to an administr&#8211;&#8221;<br />
<strong>My dad</strong>: &#8220;No, no. I followed your policies and instructions exactly as I was told. Where is my son&#8217;s iPod?&#8221;<br />
<strong>Rodriguez</strong>: &#8220;I just don&#8217;t know.&#8221;<br />
<strong>My dad</strong>: &#8220;Is there something I can sign to prove I was here to pick it up?&#8221;<br />
<strong>Rodriguez</strong>: &#8220;No, there&#8217;s only a log to be signed when I hand something back.&#8221;</p>
<p><img src="http://www.y4kstudios.com/wordpress/uploads/2009/05/ipod-nano-package-150x150.jpg" alt="iPod Nano" title="iPod Nano" width="150" height="150" class="alignright size-thumbnail wp-image-80" />That&#8217;s my secondary vision of the exchange that occurred from details provided by my dad. This happened roughly around 2:45PM. When the final bell rang at 3:00PM, I walked to the front office to make sure my dad received my iPod, completely unaware of my dad&#8217;s interaction with Mr. Rodriguez. I was in for a surprise when Mr. Rodriguez told me he couldn&#8217;t find it. This time, however, he redirected me to the Principal&#8217;s Secretary, a Ms. <a href="mailto:Beverly.Keeter@sdhc.k12.fl.us">Beverly Keeter</a>.</p>
<p>Ms. Keeter took down some of my contact information, including my name, student number, description of the iPod, and an estimated cost. She assured me that if the school was unable to locate my iPod, they would replace it. She asked me to print out the product from Best Buy to get an actual price.</p>
<p>The next day, I returned with a print out of the Best Buy page for iPod Nano of equal value to my iPod ($199, according to Apple&#8217;s original press release: <a href="http://www.apple.com/pr/library/2006/sep/12nano.html">http://www.apple.com/pr/library/2006/sep/12nano.html</a>). When school ended that day, I went to check the progress of Operation iPod Locate with Ms. Keeter. She informed me that Mr. Medvin never turned in my iPod, nor does he recall taking it away. She also said it was now up to the principal, Jake Russell, to decide what happens next.</p>
<p>I&#8217;m hoping they don&#8217;t ignore me. That&#8217;s why I&#8217;m writing this post. They can&#8217;t ignore it. I believe they have my <strike>stapler</strike> iPod.</p>
<p><strong>Edit 05/18/2009:</strong> They found my iPod. It was filed under the wrong kid&#8217;s name.<br />
<a href="http://www.y4kstudios.com/wordpress/uploads/2009/05/ipod_found.png"><img src="http://www.y4kstudios.com/wordpress/uploads/2009/05/ipod_found.png" alt="Eureka! They&#039;ve found it!" title="Eureka! They&#039;ve found it!" width="590" class="aligncenter size-full wp-image-88" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.y4kstudios.com/wordpress/05152009/of-school-and-ipods/feed/</wfw:commentRss>
		</item>
		<item>
		<title />
		<link>http://www.y4kstudios.com/wordpress/04072009/65/</link>
		<comments>http://www.y4kstudios.com/wordpress/04072009/65/#comments</comments>
		<pubDate>Tue, 07 Apr 2009 05:08:17 +0000</pubDate>
		<dc:creator>theY4Kman</dc:creator>
		
		<category><![CDATA[Funny]]></category>

		<category><![CDATA[Games]]></category>

		<category><![CDATA[gaben]]></category>

		<category><![CDATA[portal]]></category>

		<guid isPermaLink="false">http://www.y4kstudios.com/wordpress/?p=65</guid>
		<description><![CDATA[Gaben&#8217;s fat.
]]></description>
			<content:encoded><![CDATA[<p>Gaben&#8217;s fat.</p>
<div id="attachment_66" class="wp-caption alignnone" style="width: 585px"><img src="http://www.y4kstudios.com/wordpress/uploads/2009/04/gaben.jpg" alt="Almost there!" title="Gaben" width="575" height="632" class="size-full wp-image-66" /><p class="wp-caption-text">Almost there!</p></div>
]]></content:encoded>
			<wfw:commentRss>http://www.y4kstudios.com/wordpress/04072009/65/feed/</wfw:commentRss>
		</item>
		<item>
		<title>PS3 Rock Band Drums</title>
		<link>http://www.y4kstudios.com/wordpress/02112009/ps3-rock-band-drums/</link>
		<comments>http://www.y4kstudios.com/wordpress/02112009/ps3-rock-band-drums/#comments</comments>
		<pubDate>Wed, 11 Feb 2009 12:51:52 +0000</pubDate>
		<dc:creator>theY4Kman</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<category><![CDATA[Linux]]></category>

		<category><![CDATA[PS3]]></category>

		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.y4kstudios.com/wordpress/02112009/ps3-rock-band-drums/</guid>
		<description><![CDATA[I got Rock Band 1 for the PS3 this Christmas, and I&#8217;ve been loving it. The drums are my favorite, and I&#8217;m getting a lot better at them &#8212; I can play pretty much every song on hard, except for Foreplay/Long Time (DAMN YOU LOUD PART 1!). Unlike the guitar, when you play the drums [...]]]></description>
			<content:encoded><![CDATA[<p>I got <a href="http://en.wikipedia.org/wiki/Rock_Band_(video_game)">Rock Band</a> 1 for the PS3 this Christmas, and I&#8217;ve been loving it. The drums are my favorite, and I&#8217;m getting a lot better at them &#8212; I can play pretty much every song on hard, except for <a href="http://en.wikipedia.org/wiki/Foreplay/Long_Time">Foreplay/Long Time</a> (DAMN YOU LOUD PART 1!). Unlike the guitar, when you play the drums on Rock Band or Guitar Hero, one actually gains experience they can use to play <em>real</em> drums. Realizing this, I wanted to create my own beats and write my own songs. Naturally, I wanted to use them on the computer instead of the Freestyle Mode provided by the game.</p>
<p>I did a bit of research on programs for Linux that allowed the drums to be played. I didn&#8217;t find anything that looked too promising, but <a href="http://lovehateubuntu.blogspot.com/2008/09/rock-band-drums-in-linux.html">this post</a> opened my eye to a very useful detail: the Rock Band 1 drums are recognized as a joystick. That post goes on to display a C example of a drum sounds simulator using <a href="http://www.libsdl.org/">SDL</a>. I don&#8217;t like C, because of all the problems it tends to effect (linking errors, the verbosity it requires, etc), so I went about writing my own drum program in <strike>snakes</strike> <abbr title="YOU WILL USE IT!">Python</abbr>.</p>
<p>Using <a href="http://www.pygame.org/">pygame</a>, a Python SDL wrapper, I wrote a simple test program that associated drum pad hits with audio samples. When a pad or the pedal was hit, it would play a sound &#8212; quite basic. I Googled for drum sounds and discovered <a href="http://www.users.bigpond.com/prodigalson/drum.htm">this page</a> to my good fortune. With the drum samples found there, Yak&#8217;s Rock Band PS3 Drums was born. (I couldn&#8217;t think of a better name.)</p>
<p>Since writing that simple script, I have added the ability to record and replay beats and a rough GUI designed in Glade.</p>
<p>For the script and a screenshot, CLICK THE DAMN LINK!<br />
<span id="more-39"></span></p>
<p><img src='http://www.y4kstudios.com/wordpress/uploads/2009/02/screenshot1.png' alt='Rock Band PS3 Drums' /></p>
<p>As you can see, the GUI is mostly a picture of the PS3 drum set. When you hit a pad, it&#8217;s filled with its respective color. That&#8217;s all I can pull off in GIMP&#8230;</p>
<p>Anyways, I&#8217;ve zipped up the whole package, including the sound samples &#8212; I could not find any sort of copyright notice, so I&#8217;m going to assume that they are in the public domain *cough*. <em>Yak&#8217;s Rock Band PS3 Drums</em> requires Python, pygame, and GTK+2. While I have not tested the program on Windows, it <em>should</em> work.</p>
<p>Grab it here: <a href="http://y4kstudios.com/rockband.zip">http://y4kstudios.com/rockband.zip</a></p>
<p>Happy drumming!</p>
<p><strong>Edit (02/15/2009):</strong> There was a *slight* problem with the first GUI release: the main loop used 100% CPU. I remedied that by having an internal clock with 30FPS. I believe that&#8217;s a high enough rate that the delay between hitting the pads and the sound being played is unnoticeable, or at least very hard to notice. (30FPS == 1 update every 33.3ms)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.y4kstudios.com/wordpress/02112009/ps3-rock-band-drums/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Bread Clips</title>
		<link>http://www.y4kstudios.com/wordpress/01282009/bread-clips/</link>
		<comments>http://www.y4kstudios.com/wordpress/01282009/bread-clips/#comments</comments>
		<pubDate>Wed, 28 Jan 2009 20:59:14 +0000</pubDate>
		<dc:creator>theY4Kman</dc:creator>
		
		<category><![CDATA[Rant]]></category>

		<guid isPermaLink="false">http://www.y4kstudios.com/wordpress/01282009/bread-clips/</guid>
		<description><![CDATA[
Bread clips are the bane of my fridge-going experience. Most of the time our bags are sealed with twist ties, but occasionally these rotten crapples pop in to send salutations and a slap in the face.
When the bag has a twist tie, the usage is as simple as untwisting, retrieving the contents of the container, [...]]]></description>
			<content:encoded><![CDATA[<p><img width="530" alt="Bread Clip" src="http://www.y4kstudios.com/wordpress/uploads/2009/01/bread-clip.jpg"/></p>
<p>Bread clips are the bane of my fridge-going experience. Most of the time our bags are sealed with twist ties, but occasionally these rotten crapples pop in to send salutations and a slap in the face.</p>
<p>When the bag has a twist tie, the usage is as simple as untwisting, retrieving the contents of the container, and retwisting. Not for bread clips, though. Oh, no, they can&#8217;t be that easy. Trying to take them off yields ripped plastic and broken seals. One would be lucky to get the bag open enough to pull anything out. But if one is successful, failure is a sure shot when attempting to reapply the little buggers. However, if one somehow defies the Laws of the Kitchen and applies the clip, it&#8217;s already bent three ways to hell.</p>
<p>Basically, bread clipping is akin to waterboarding. Some may construe it as legal, but it hurts everyone in the end (possibly dead, too).</p>
<p>Fuck bread clips.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.y4kstudios.com/wordpress/01282009/bread-clips/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Bash Script Expo #2</title>
		<link>http://www.y4kstudios.com/wordpress/01182009/bash-script-expo-2/</link>
		<comments>http://www.y4kstudios.com/wordpress/01182009/bash-script-expo-2/#comments</comments>
		<pubDate>Sun, 18 Jan 2009 17:25:17 +0000</pubDate>
		<dc:creator>theY4Kman</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<category><![CDATA[Bash]]></category>

		<guid isPermaLink="false">http://www.y4kstudios.com/wordpress/01182009/bash-script-expo-2/</guid>
		<description><![CDATA[
This little bit here prints out the process ID and process name of the process with the specified open port.

#!/bin/bash
ps -p `netstat -pantu &#124; awk &#34;\\$4 ~ /$1$/ { split(\\$NF,pid,\&#34;/\&#34;); print pid[1]; }&#34;` -o comm= -o pid= 2&#62; /dev/null

`netstat -pantu` prints the open ports using the UDP or TCP protocol and the process IDs of [...]]]></description>
			<content:encoded><![CDATA[<div style="background-color: black; margin-bottom: 5px;"><img src='http://www.y4kstudios.com/wordpress/uploads/2009/01/openports.png' alt='Bash Script Expo #2 Screenshot' /></div>
<p>This little bit here prints out the process ID and process name of the process with the specified open port.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
<span style="color: #c20cb9; font-weight: bold;">ps</span> <span style="color: #660033;">-p</span> <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">netstat</span> <span style="color: #660033;">-pantu</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">&quot;\<span style="color: #000099; font-weight: bold;">\$</span>4 ~ /$1$/ { split(\<span style="color: #000099; font-weight: bold;">\$</span>NF,pid,<span style="color: #000099; font-weight: bold;">\&quot;</span>/<span style="color: #000099; font-weight: bold;">\&quot;</span>); print pid[1]; }&quot;</span><span style="color: #000000; font-weight: bold;">`</span> <span style="color: #660033;">-o</span> <span style="color: #007800;"><span style="color: #c20cb9; font-weight: bold;">comm</span></span>= <span style="color: #660033;">-o</span> <span style="color: #007800;">pid</span>= <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null</pre></div></div>

<p><em>`netstat -pantu`</em> prints the open ports using the UDP or TCP protocol and the process IDs of the processes that opened the ports. The <a href="http://en.wikipedia.org/wiki/Awk"><em>awk</em></a> line parses netstat so that it prints only the process ID. Then the <em>ps</em> line prints out the process name and PID. The ending <em>2> /dev/null</em> stops <em>ps</em> from printing out its help text when there is no process with the specified open port.</p>
<p>The warning that appears above explains that one must `sudo` to see all the processes.</p>
<p>However, if you&#8217;d like to just know the PID of the process with the open port, remove the <em>ps</em>, like so:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
<span style="color: #c20cb9; font-weight: bold;">netstat</span> <span style="color: #660033;">-pantu</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">&quot;\<span style="color: #000099; font-weight: bold;">\$</span>4 ~ /$1$/ { split(\<span style="color: #000099; font-weight: bold;">\$</span>NF,pid,<span style="color: #000099; font-weight: bold;">\&quot;</span>/<span style="color: #000099; font-weight: bold;">\&quot;</span>); print pid[1]; }&quot;</span></pre></div></div>

<p>Then you could do this:</p>
<div style="background-color: black; margin-bottom: 5px;"><img src='http://www.y4kstudios.com/wordpress/uploads/2009/01/openports_kill.png' alt='Bash Script Expo #2 Screenshot 2' /></div>
<p>Which will kill the process that opened the port. (When I ran that command, I ended up crashing Steam&#8230;)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.y4kstudios.com/wordpress/01182009/bash-script-expo-2/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Python’s max(arg1, arg2, …, key=func)</title>
		<link>http://www.y4kstudios.com/wordpress/01102009/python-maxarg1-arg2-keyfunc/</link>
		<comments>http://www.y4kstudios.com/wordpress/01102009/python-maxarg1-arg2-keyfunc/#comments</comments>
		<pubDate>Sat, 10 Jan 2009 17:22:39 +0000</pubDate>
		<dc:creator>theY4Kman</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.y4kstudios.com/wordpress/01102009/python-maxarg1-arg2-keyfunc/</guid>
		<description><![CDATA[I stumbled across a somewhat undocumented feature of Python&#8217;s max() function. I was trying to find the largest absolute item in a list, and just as I was about to create a generator list composition for it,

&#91;abs&#40;x&#41; for x in mylist&#93;

I looked at the documentation for max() in ipython, and found an argument not in [...]]]></description>
			<content:encoded><![CDATA[<p>I stumbled across a somewhat undocumented feature of Python&#8217;s max() function. I was trying to find the largest absolute item in a list, and just as I was about to create a <strike>generator</strike> list composition for it,</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: black;">&#91;</span><span style="color: #008000;">abs</span><span style="color: black;">&#40;</span>x<span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">for</span> x <span style="color: #ff7700;font-weight:bold;">in</span> mylist<span style="color: black;">&#93;</span></pre></div></div>

<p>I looked at the documentation for max() in <a href="http://ipython.scipy.org/moin/">ipython</a>, and found an argument not in the online Python documentation: key. &#8216;key&#8217; is a keyword parameter accepting a function with one argument. This function does whatever the hell it wants to every number passed to max() and then returns it. This simplified what I needed to do:</p>
<div style="background-color: black; padding-bottom: 5px;"><img src='http://www.y4kstudios.com/wordpress/uploads/2009/01/max_key.png' alt='max(arg1, arg2, …, key=func)' /></div>
]]></content:encoded>
			<wfw:commentRss>http://www.y4kstudios.com/wordpress/01102009/python-maxarg1-arg2-keyfunc/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Bash Script Expo #1</title>
		<link>http://www.y4kstudios.com/wordpress/12242008/bash-script-expo-1/</link>
		<comments>http://www.y4kstudios.com/wordpress/12242008/bash-script-expo-1/#comments</comments>
		<pubDate>Wed, 24 Dec 2008 05:13:48 +0000</pubDate>
		<dc:creator>theY4Kman</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<category><![CDATA[Bash]]></category>

		<guid isPermaLink="false">http://www.y4kstudios.com/wordpress/12242008/bash-script-expo-1/</guid>
		<description><![CDATA[Print out all the processes with a certain file open.


#!/bin/sh
for pid in `ps -eo pid=`; do 
    if `ls -l /proc/$pid/fd 2&#62;-&#124; awk '{print $10}' &#124; grep -q &#34;$@&#34;`; then 
        ps -p $pid -o comm= -o pid=
    fi
done

ps -eo pid= prints [...]]]></description>
			<content:encoded><![CDATA[<p>Print out all the processes with a certain file open.</p>
<div style="background-color:black;margin-bottom:5px;"><img src="http://www.y4kstudios.com/wordpress/uploads/2008/12/openfiles.png" alt="Bash Script Expo #1 Screenshot" /></div>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
<span style="color: #000000; font-weight: bold;">for</span> pid <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">ps</span> <span style="color: #660033;">-eo</span> <span style="color: #007800;">pid</span>=<span style="color: #000000; font-weight: bold;">`</span>; <span style="color: #000000; font-weight: bold;">do</span> 
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #660033;">-l</span> <span style="color: #000000; font-weight: bold;">/</span>proc<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$pid</span><span style="color: #000000; font-weight: bold;">/</span>fd <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&gt;</span>-<span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $10}'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-q</span> <span style="color: #ff0000;">&quot;$@&quot;</span><span style="color: #000000; font-weight: bold;">`</span>; <span style="color: #000000; font-weight: bold;">then</span> 
        <span style="color: #c20cb9; font-weight: bold;">ps</span> <span style="color: #660033;">-p</span> <span style="color: #007800;">$pid</span> <span style="color: #660033;">-o</span> <span style="color: #007800;"><span style="color: #c20cb9; font-weight: bold;">comm</span></span>= <span style="color: #660033;">-o</span> <span style="color: #007800;">pid</span>=
    <span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #000000; font-weight: bold;">done</span></pre></div></div>

<p><em>ps -eo pid=</em> prints out all the process IDs.  <em>/proc/PID/fd</em> contains the file descriptors of all the files opened by that process ID. <em>ps -p $pid -o comm= -o pid=</em> then prints out the process name and PID of that process. Simple as pie!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.y4kstudios.com/wordpress/12242008/bash-script-expo-1/feed/</wfw:commentRss>
		</item>
		<item>
		<title>LinkDestruct</title>
		<link>http://www.y4kstudios.com/wordpress/12232008/linkdestruct/</link>
		<comments>http://www.y4kstudios.com/wordpress/12232008/linkdestruct/#comments</comments>
		<pubDate>Tue, 23 Dec 2008 08:33:45 +0000</pubDate>
		<dc:creator>theY4Kman</dc:creator>
		
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://www.y4kstudios.com/wordpress/12232008/linkdestruct/</guid>
		<description><![CDATA[


&#60;e_fermi&#62;
hey edteller


&#60;e_fermi&#62;
i just figured out a great way to use a small fission bomb to ignite a thermonuclear fusion bomb


&#60;edteller&#62;
Wow!


&#60;e_fermi&#62;
Yeah, I published it on my wobsite: http://totallyexistedin1941.mil/~fermi/thermonuclearbomb.htm


&#60;[NaZi]hitler&#62;
MWUAHAHAHA! Your secrets are mine!


 * [NaZi]hitler destroys America, Britain, and Canada



Has this ever happened to you? It wouldn&#8217;t have, if only you had used a self-destructing link!
What&#8217;s a [...]]]></description>
			<content:encoded><![CDATA[<table style="font-family: monospace, Courier New; font-size: 12px; text-align: left;">
<tbody valign="top">
<tr>
<td align="right">&lt;<span style="color:#0000AA;">e_fermi</span>&gt;</td>
<td>hey edteller</td>
</tr>
<tr>
<td align="right">&lt;<span style="color:#0000AA;">e_fermi</span>&gt;</td>
<td>i just figured out a great way to use a small fission bomb to ignite a thermonuclear fusion bomb</td>
</tr>
<tr>
<td align="right">&lt;<span style="color:#0000AA;">edteller</span>&gt;</td>
<td>Wow!</td>
</tr>
<tr>
<td align="right">&lt;<span style="color:#0000AA;">e_fermi</span>&gt;</td>
<td>Yeah, I published it on my wobsite: <a href="http://google.com">http://totallyexistedin1941.mil/~fermi/thermonuclearbomb.htm</a></td>
</tr>
<tr>
<td align="right">&lt;<span style="color:#0000AA;">[NaZi]hitler</span>&gt;</td>
<td>MWUAHAHAHA! Your secrets are mine!</td>
</tr>
<tr>
<td colspan="2"> * <span style="color:#0000AA;">[NaZi]hitler</span> destroys America, Britain, and Canada</td>
</tr>
</tbody>
</table>
<p>Has this ever happened to you? It wouldn&#8217;t have, if only you had used a self-destructing link!</p>
<p><em>What&#8217;s a self-destructing link</em>, you say?<br />
A self-destructing link is a URL that redirects to a specified hidden URL until certain limits are reached, such as amount of views or time. If X amount of people have visited the URL or Y amount of seconds/minutes/hours/days/eons have passed, the URL will no longer redirect to the hidden URL.</p>
<p><em>Boy, theY4Kman, that sounds even cooler than falling and missing the ground. How do I create my own self-destroyerzing thingamadoodads?</em><br />
Well, avid reader, I&#8217;m pleased to inform you that I&#8217;ve created such a site for your eyes only! Just head on over to <a href="http://linkdestruct.com">LinkDestruct (http://linkdestruct.com)</a>, follow the instructions, and you&#8217;ll be off in no time <strike>growing</strike> generating your very own <strike>ch-ch-chia</strike> self-destructing links.</p>
<p><em>What was that link again?</em><br />
<a href="http://linkdestruct.com">http://linkdestruct.com</a></p>
<p><em>Er?</em><br />
That number again was <a href="http://linkdestruct.com">1-800-DESTROY</a> (<a href="http://linkdestruct.com">1-800-337-8769</a>)</p>
<p>Don&#8217;t forget to <strong>Share and Enjoy</strong>!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.y4kstudios.com/wordpress/12232008/linkdestruct/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Priority Queue Using a Heap</title>
		<link>http://www.y4kstudios.com/wordpress/11192008/priority-queue-using-a-heap/</link>
		<comments>http://www.y4kstudios.com/wordpress/11192008/priority-queue-using-a-heap/#comments</comments>
		<pubDate>Wed, 19 Nov 2008 22:04:31 +0000</pubDate>
		<dc:creator>theY4Kman</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<category><![CDATA[Algorithms]]></category>

		<category><![CDATA[C++]]></category>

		<guid isPermaLink="false">http://www.y4kstudios.com/wordpress/11192008/priority-queue-using-a-heap/</guid>
		<description><![CDATA[Recently, I picked up Algorithms in C++, by Robert Sedgewick, again. I bought the book a few months ago, and started reading it then, but I never got anywhere. The first time around, I did nothing but look at the text and try to understand it. My current stab at it involves reading the book, [...]]]></description>
			<content:encoded><![CDATA[<p>Recently, I picked up <a href="http://www.amazon.com/Algorithms-C-Robert-Sedgewick/dp/0201510596">Algorithms in C++</a>, by Robert Sedgewick, again. I bought the book a few months ago, and started reading it then, but I never got anywhere. The first time around, I did nothing but look at the text and try to understand it. My current stab at it involves reading the book, marking it (that little &#8220;strategy&#8221; English teachers try to persuade students to use, but fail miserably), and now, because I understand the algorithms that much better, actually implementing them.</p>
<p>I tried to implement some algorithms far into the book, such as Huffman data compression, but after attempting that, I realized the need for lower-level data structures; those data structures introduced at the very beginning of the book. I restarted my perusal from the first few chapters, and I&#8217;ve now successfully implemented a <a href="http://en.wikipedia.org/wiki/Priority_Queue">Priority Queue</a> using a <a href="http://en.wikipedia.org/wiki/Heap_(data_structure)">Heap data structure</a>. Code after the jump (I&#8217;ve always wanted to say that, but I&#8217;ve also always wanted to punch people in the face for saying that. I&#8217;m gonna have a hard time explaining this black eye to my friends.)<br />
<span id="more-28"></span></p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">class</span> HeapPriorityQueue
<span style="color: #008000;">&#123;</span>
<span style="color: #0000ff;">private</span><span style="color: #008080;">:</span>
    <span style="color: #666666;">/// Our heap/array.</span>
    <span style="color: #0000ff;">int</span> <span style="color: #000040;">*</span>m_pHeap<span style="color: #008080;">;</span>
    <span style="color: #666666;">/// Length of our array/heap.</span>
    <span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">int</span> m_iMax<span style="color: #008080;">;</span>
    <span style="color: #666666;">/// The largest used index in the heap at the moment</span>
    <span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">int</span> m_iN<span style="color: #008080;">;</span>
&nbsp;
    <span style="color: #ff0000; font-style: italic;">/**
     * Uses the passed index to sort the item up the tree.
     * @param   k: index to the internal array
     */</span>
    <span style="color: #0000ff;">void</span> upheap<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">int</span> k<span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>k <span style="color: #000080;">&gt;</span> m_iN<span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">return</span><span style="color: #008080;">;</span>
&nbsp;
        <span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">int</span> j <span style="color: #000080;">=</span> k<span style="color: #008080;">;</span>
        <span style="color: #0000ff;">int</span> val <span style="color: #000080;">=</span> m_pHeap<span style="color: #008000;">&#91;</span>j<span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span>
&nbsp;
        <span style="color: #0000ff;">while</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>k <span style="color: #000040;">/</span><span style="color: #000080;">=</span> <span style="color: #0000dd;">2</span><span style="color: #008000;">&#41;</span> <span style="color: #000080;">&gt;</span> <span style="color: #0000dd;">0</span> <span style="color: #000040;">&amp;&amp;</span> val <span style="color: #000080;">&gt;</span> m_pHeap<span style="color: #008000;">&#91;</span>k<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            m_pHeap<span style="color: #008000;">&#91;</span>j<span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> m_pHeap<span style="color: #008000;">&#91;</span>k<span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span>
            m_pHeap<span style="color: #008000;">&#91;</span>k<span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> val<span style="color: #008080;">;</span>
            j <span style="color: #000080;">=</span> k<span style="color: #008080;">;</span>
        <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span>
&nbsp;
    <span style="color: #ff0000; font-style: italic;">/**
     * Uses the passed index to sort the item down the tree.
     * @param   k: index to the internal array
     */</span>
    <span style="color: #0000ff;">void</span> downheap<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">int</span> k<span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>k <span style="color: #000080;">&gt;</span> m_iN<span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">return</span><span style="color: #008080;">;</span>
&nbsp;
        <span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">int</span> j<span style="color: #008080;">;</span>
        <span style="color: #0000ff;">int</span> val <span style="color: #000080;">=</span> m_pHeap<span style="color: #008000;">&#91;</span>k<span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span>
&nbsp;
        <span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">int</span> limit <span style="color: #000080;">=</span> m_iN <span style="color: #000040;">/</span> <span style="color: #0000dd;">2</span><span style="color: #008080;">;</span>
&nbsp;
        <span style="color: #0000ff;">while</span><span style="color: #008000;">&#40;</span>k <span style="color: #000080;">&lt;</span> <span style="color: #000080;">=</span> limit<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            j <span style="color: #000080;">=</span> k <span style="color: #000040;">+</span> k<span style="color: #008080;">;</span>
&nbsp;
            <span style="color: #666666;">// Move to the right child if it is larger than the left child</span>
            <span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>j <span style="color: #000080;">&lt;</span> m_iN <span style="color: #000040;">&amp;&amp;</span> m_pHeap<span style="color: #008000;">&#91;</span>j<span style="color: #008000;">&#93;</span> <span style="color: #000080;">&lt;</span> m_pHeap<span style="color: #008000;">&#91;</span>j<span style="color: #000040;">+</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span> j<span style="color: #000040;">++</span><span style="color: #008080;">;</span>
&nbsp;
            <span style="color: #666666;">// If `val` is larger than both children of `k`, we're done.</span>
            <span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>val <span style="color: #000080;">&gt;=</span> m_pHeap<span style="color: #008000;">&#91;</span>j<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">break</span><span style="color: #008080;">;</span>
&nbsp;
            m_pHeap<span style="color: #008000;">&#91;</span>k<span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> m_pHeap<span style="color: #008000;">&#91;</span>j<span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span>
            k <span style="color: #000080;">=</span> j<span style="color: #008080;">;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        m_pHeap<span style="color: #008000;">&#91;</span>k<span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> val<span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #0000ff;">public</span><span style="color: #008080;">:</span>
    <span style="color: #ff0000; font-style: italic;">/**
     * @param   max: The amount of items to be stored in the queue.
     */</span>
    HeapPriorityQueue<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">int</span> max<span style="color: #008000;">&#41;</span> <span style="color: #008080;">:</span> m_iMax<span style="color: #008000;">&#40;</span>max<span style="color: #008000;">&#41;</span>, m_iN<span style="color: #008000;">&#40;</span><span style="color: #0000dd;">0</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        m_pHeap <span style="color: #000080;">=</span> <span style="color: #0000dd;">new</span> <span style="color: #0000ff;">int</span><span style="color: #008000;">&#91;</span>m_iMax<span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span>
&nbsp;
    ~HeapPriorityQueue<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0000dd;">delete</span> <span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> m_pHeap<span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span>
&nbsp;
    <span style="color: #ff0000; font-style: italic;">/**
     * Insert an item into the queue.
     * @param   val: Item to add.
     */</span>
    <span style="color: #0000ff;">void</span> insert<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> val<span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>m_iN <span style="color: #000080;">&gt;=</span> m_iMax<span style="color: #000040;">-</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">return</span><span style="color: #008080;">;</span>
&nbsp;
        m_pHeap<span style="color: #008000;">&#91;</span><span style="color: #000040;">++</span>m_iN<span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> val<span style="color: #008080;">;</span>
        upheap<span style="color: #008000;">&#40;</span>m_iN<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #ff0000; font-style: italic;">/**
     * Removes the largest item from the queue and returns it.
     * @return: Largest item from the queue.
     */</span>
    <span style="color: #0000ff;">int</span> <span style="color: #0000dd;">remove</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>m_iN <span style="color: #000080;">&lt;</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">1</span><span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">return</span> <span style="color: #000040;">-</span><span style="color: #0000dd;">1</span><span style="color: #008080;">;</span>
&nbsp;
        <span style="color: #0000ff;">int</span> val <span style="color: #000080;">=</span> m_pHeap<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span>
        m_pHeap<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> m_pHeap<span style="color: #008000;">&#91;</span>m_iN<span style="color: #000040;">--</span><span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span>
        downheap<span style="color: #008000;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
        <span style="color: #0000ff;">return</span> val<span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span></pre></div></div>

</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.y4kstudios.com/wordpress/11192008/priority-queue-using-a-heap/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Playlog Displayer</title>
		<link>http://www.y4kstudios.com/wordpress/07242008/playlog-displayer/</link>
		<comments>http://www.y4kstudios.com/wordpress/07242008/playlog-displayer/#comments</comments>
		<pubDate>Thu, 24 Jul 2008 10:23:28 +0000</pubDate>
		<dc:creator>theY4Kman</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.y4kstudios.com/wordpress/07242008/playlog-displayer/</guid>
		<description><![CDATA[I never did show you the full source code for the playlog page, so here you go! One day I&#8217;ll comment it for you 


from mod_python import apache, util
from PIL import Image
import eyeD3 as id3
import MySQLdb, time, cStringIO
&#160;
def handler&#40;req&#41;:
	args = util.parse_qs&#40;req.args or &#34;&#34;&#41;
	if args.has_key&#40;&#34;pic&#34;&#41;:
		return pic&#40;req, args&#91;&#34;pic&#34;&#93;&#41;
&#160;
	return main&#40;req&#41;
&#160;
def main&#40;req&#41;:
	req.content_type = &#34;text/html&#34;
	req.write&#40;&#34;&#34;&#34;
&#60; !DOCTYPE html PUBLIC &#34;-//W3C//DTD XHTML [...]]]></description>
			<content:encoded><![CDATA[<p>I never did show you the full source code for the playlog page, so here you go! One day I&#8217;ll comment it for you <img src='http://www.y4kstudios.com/wordpress/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /><br />
<span id="more-27"></span></p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">from</span> mod_python <span style="color: #ff7700;font-weight:bold;">import</span> apache, util
<span style="color: #ff7700;font-weight:bold;">from</span> PIL <span style="color: #ff7700;font-weight:bold;">import</span> Image
<span style="color: #ff7700;font-weight:bold;">import</span> eyeD3 <span style="color: #ff7700;font-weight:bold;">as</span> id3
<span style="color: #ff7700;font-weight:bold;">import</span> MySQLdb, <span style="color: #dc143c;">time</span>, <span style="color: #dc143c;">cStringIO</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> handler<span style="color: black;">&#40;</span>req<span style="color: black;">&#41;</span>:
	args = util.<span style="color: black;">parse_qs</span><span style="color: black;">&#40;</span>req.<span style="color: black;">args</span> <span style="color: #ff7700;font-weight:bold;">or</span> <span style="color: #483d8b;">&quot;&quot;</span><span style="color: black;">&#41;</span>
	<span style="color: #ff7700;font-weight:bold;">if</span> args.<span style="color: black;">has_key</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;pic&quot;</span><span style="color: black;">&#41;</span>:
		<span style="color: #ff7700;font-weight:bold;">return</span> pic<span style="color: black;">&#40;</span>req, args<span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;pic&quot;</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
&nbsp;
	<span style="color: #ff7700;font-weight:bold;">return</span> main<span style="color: black;">&#40;</span>req<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> main<span style="color: black;">&#40;</span>req<span style="color: black;">&#41;</span>:
	req.<span style="color: black;">content_type</span> = <span style="color: #483d8b;">&quot;text/html&quot;</span>
	req.<span style="color: black;">write</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;&quot;&quot;
&lt; !DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;theY4Kman's Playlog&lt;/title&gt;
&lt;link rel=&quot;stylesheet&quot; href=&quot;style.css&quot; /&gt;
&lt;/head&gt;
&nbsp;
&lt;body&gt;&quot;&quot;&quot;</span><span style="color: black;">&#41;</span>
&nbsp;
	db = MySQLdb.<span style="color: black;">connect</span><span style="color: black;">&#40;</span>host=<span style="color: #483d8b;">&quot;localhost&quot;</span>, <span style="color: #dc143c;">user</span>=<span style="color: #483d8b;">&quot;root&quot;</span>, passwd=<span style="color: #483d8b;">&quot;fooledu&quot;</span>, db=<span style="color: #483d8b;">&quot;amarok&quot;</span><span style="color: black;">&#41;</span>
	crs = db.<span style="color: black;">cursor</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
	crs.<span style="color: black;">execute</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;&quot;&quot;SELECT playlog.play_time, song_paths.song_path, song_paths.song_id
	FROM playlog, song_paths
	WHERE playlog.song_id = song_paths.song_id
	ORDER BY playlog.play_time DESC
	LIMIT 0,20&quot;&quot;&quot;</span><span style="color: black;">&#41;</span>
&nbsp;
	grey = <span style="color: #008000;">False</span>
	res = crs.<span style="color: black;">fetchone</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
	<span style="color: #ff7700;font-weight:bold;">while</span> res:
		title = artist = album = <span style="color: #483d8b;">&quot;&lt;none&gt;&quot;</span>
		year = <span style="color: #483d8b;">&quot;&quot;</span>
&nbsp;
		tag = id3.<span style="color: black;">Tag</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
		<span style="color: #ff7700;font-weight:bold;">try</span>:
			tag.<span style="color: black;">link</span><span style="color: black;">&#40;</span>res<span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
			title = tag.<span style="color: black;">getTitle</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
			artist = tag.<span style="color: black;">getArtist</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
			album = tag.<span style="color: black;">getAlbum</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
			year = tag.<span style="color: black;">getYear</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
		<span style="color: #ff7700;font-weight:bold;">except</span>:
			res = crs.<span style="color: black;">fetchone</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
			<span style="color: #ff7700;font-weight:bold;">continue</span>
&nbsp;
		req.<span style="color: black;">write</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;&quot;&quot;
&lt;div class=&quot;track %s&quot;&gt;
	&lt;div class=&quot;basicinfo&quot;&gt;
		&lt;div class=&quot;extendedinfo&quot;&gt;
			&lt;br /&gt;
		&lt;/div&gt;
&nbsp;
		&lt;em class=&quot;time&quot;&gt;%s&lt;/em&gt;
		&lt;div class=&quot;cover&quot;&gt;
			&lt;img class=&quot;coverimg&quot; src=&quot;music.py?pic=%s&quot; /&gt;
		&lt;/div&gt;
		&lt;div class=&quot;trackinfo&quot;&gt;
			&lt;strong&gt;%s&lt;/strong&gt;%s%s
		&lt;/div&gt;
	&lt;/div&gt;
&lt;/div&gt;
&nbsp;
&quot;&quot;&quot;</span>
		<span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span> <span style="color: black;">&#40;</span> grey <span style="color: #66cc66;">!</span>= <span style="color: #008000;">False</span> <span style="color: #ff7700;font-weight:bold;">and</span> <span style="color: #483d8b;">&quot;bg1&quot;</span> <span style="color: #ff7700;font-weight:bold;">or</span> <span style="color: #483d8b;">&quot;bg2&quot;</span> <span style="color: black;">&#41;</span>,
		<span style="color: #dc143c;">time</span>.<span style="color: black;">strftime</span><span style="color: black;">&#40;</span> <span style="color: #483d8b;">&quot;%Z %I:%M%p %A, %B %d&quot;</span>, <span style="color: #dc143c;">time</span>.<span style="color: black;">localtime</span><span style="color: black;">&#40;</span>res<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span> <span style="color: black;">&#41;</span>,
		res<span style="color: black;">&#91;</span><span style="color: #ff4500;">2</span><span style="color: black;">&#93;</span>,
		title,
		artist <span style="color: #66cc66;">!</span>= <span style="color: #483d8b;">&quot;&quot;</span> <span style="color: #ff7700;font-weight:bold;">and</span> <span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;&lt;br /&gt; by &lt;strong&gt;%s&lt;/strong&gt;&quot;</span> <span style="color: #66cc66;">%</span> artist<span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">or</span> <span style="color: #483d8b;">&quot;&quot;</span>,
		album <span style="color: #66cc66;">!</span>= <span style="color: #483d8b;">&quot;&quot;</span> <span style="color: #ff7700;font-weight:bold;">and</span> <span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;&lt;br /&gt; on &lt;strong&gt;%s&lt;/strong&gt;&quot;</span> <span style="color: #66cc66;">%</span> album<span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">or</span> <span style="color: #483d8b;">&quot;&quot;</span> <span style="color: black;">&#41;</span> <span style="color: black;">&#41;</span>
&nbsp;
		grey = <span style="color: #ff7700;font-weight:bold;">not</span> grey	<span style="color: #808080; font-style: italic;"># Toggle between grey and white backgrounds.</span>
&nbsp;
		res = crs.<span style="color: black;">fetchone</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
	req.<span style="color: black;">write</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;&lt;/none&gt;&lt;/body&gt;n&lt;/html&gt;&quot;</span><span style="color: black;">&#41;</span>
&nbsp;
	<span style="color: #ff7700;font-weight:bold;">return</span> apache.<span style="color: black;">OK</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> pic<span style="color: black;">&#40;</span>req, <span style="color: #008000;">id</span><span style="color: black;">&#41;</span>:
	req.<span style="color: black;">content_type</span> = <span style="color: #483d8b;">&quot;text/html&quot;</span>
&nbsp;
	db = MySQLdb.<span style="color: black;">connect</span><span style="color: black;">&#40;</span>host=<span style="color: #483d8b;">&quot;localhost&quot;</span>, <span style="color: #dc143c;">user</span>=<span style="color: #483d8b;">&quot;root&quot;</span>, passwd=<span style="color: #483d8b;">&quot;fooledu&quot;</span>, db=<span style="color: #483d8b;">&quot;playlog&quot;</span><span style="color: black;">&#41;</span>
	crs = db.<span style="color: black;">cursor</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
	crs.<span style="color: black;">execute</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;SELECT song_path FROM songs WHERE song_id = %s LIMIT 1&quot;</span>, <span style="color: #008000;">id</span><span style="color: black;">&#41;</span>
&nbsp;
	res = crs.<span style="color: black;">fetchone</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
	<span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #ff7700;font-weight:bold;">not</span> res: <span style="color: #ff7700;font-weight:bold;">return</span> defaultpic<span style="color: black;">&#40;</span>req<span style="color: black;">&#41;</span>
&nbsp;
	tag = id3.<span style="color: black;">Tag</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
	<span style="color: #ff7700;font-weight:bold;">try</span>:
		tag.<span style="color: black;">link</span><span style="color: black;">&#40;</span>res<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
		imgs = tag.<span style="color: black;">getImages</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
		<span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #ff7700;font-weight:bold;">not</span> tag <span style="color: #ff7700;font-weight:bold;">or</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>imgs<span style="color: black;">&#41;</span> <span style="color: #66cc66;">&lt;</span> <span style="color: #ff4500;">1</span>: <span style="color: #ff7700;font-weight:bold;">return</span> defaultpic<span style="color: black;">&#40;</span>req<span style="color: black;">&#41;</span>
&nbsp;
		req.<span style="color: black;">content_type</span> = imgs<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>.<span style="color: black;">mimeType</span>
&nbsp;
		im_str = <span style="color: #dc143c;">cStringIO</span>.<span style="color: #dc143c;">StringIO</span><span style="color: black;">&#40;</span>imgs<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>.<span style="color: black;">imageData</span><span style="color: black;">&#41;</span>
		im = Image.<span style="color: #008000;">open</span><span style="color: black;">&#40;</span>im_str<span style="color: black;">&#41;</span>
&nbsp;
		<span style="color: #ff7700;font-weight:bold;">if</span> im.<span style="color: black;">size</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span> <span style="color: #66cc66;">&gt;</span> <span style="color: #ff4500;">130</span>:
			im = im.<span style="color: black;">resize</span><span style="color: black;">&#40;</span> <span style="color: black;">&#40;</span><span style="color: #ff4500;">130</span>, <span style="color: #ff4500;">130</span><span style="color: black;">&#41;</span>, Image.<span style="color: black;">ANTIALIAS</span> <span style="color: black;">&#41;</span>
&nbsp;
		im_str.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
		im_str = <span style="color: #dc143c;">cStringIO</span>.<span style="color: #dc143c;">StringIO</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
		im.<span style="color: black;">save</span><span style="color: black;">&#40;</span>im_str, <span style="color: #483d8b;">&quot;JPEG&quot;</span><span style="color: black;">&#41;</span>
&nbsp;
		req.<span style="color: black;">write</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;%s&quot;</span> <span style="color: #66cc66;">%</span> im_str.<span style="color: black;">getvalue</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
		im_str.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
	<span style="color: #ff7700;font-weight:bold;">except</span>:
		<span style="color: #ff7700;font-weight:bold;">return</span> defaultpic<span style="color: black;">&#40;</span>req<span style="color: black;">&#41;</span>
&nbsp;
	<span style="color: #ff7700;font-weight:bold;">return</span> apache.<span style="color: black;">OK</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> defaultpic<span style="color: black;">&#40;</span>req<span style="color: black;">&#41;</span>:
	img = <span style="color: #008000;">open</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;/home/they4kman/site/music/covers/__default.png&quot;</span>, <span style="color: #483d8b;">&quot;rb&quot;</span><span style="color: black;">&#41;</span>
	<span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #ff7700;font-weight:bold;">not</span> img: <span style="color: #ff7700;font-weight:bold;">return</span> apache.<span style="color: black;">OK</span>
&nbsp;
	req.<span style="color: black;">content_type</span> = <span style="color: #483d8b;">&quot;image/png&quot;</span>
	req.<span style="color: black;">write</span><span style="color: black;">&#40;</span>img.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
	img.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
	<span style="color: #ff7700;font-weight:bold;">return</span> apache.<span style="color: black;">OK</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.y4kstudios.com/wordpress/07242008/playlog-displayer/feed/</wfw:commentRss>
		</item>
	</channel>
</rss><!-- Dynamic Page Served (once) in 2.046 seconds -->
