<?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>Jon Todd &#187; Computers</title>
	<atom:link href="http://www.jontodd.com/tag/computers/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.jontodd.com</link>
	<description>Optimal</description>
	<lastBuildDate>Tue, 03 Nov 2009 22:33:26 +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>How To Control iTunes remotely with SSH</title>
		<link>http://www.jontodd.com/2007/11/19/how-to-control-itunes-remotely-with-ssh/</link>
		<comments>http://www.jontodd.com/2007/11/19/how-to-control-itunes-remotely-with-ssh/#comments</comments>
		<pubDate>Mon, 19 Nov 2007 15:56:00 +0000</pubDate>
		<dc:creator>Jon Todd</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[command-line]]></category>
		<category><![CDATA[Computers]]></category>
		<category><![CDATA[iTunes]]></category>
		<category><![CDATA[remote]]></category>
		<category><![CDATA[ssh]]></category>
		<category><![CDATA[terminal]]></category>

		<guid isPermaLink="false">http://www.jontodd.com/2007/11/20/how-to-control-itunes-remotely-with-ssh/</guid>
		<description><![CDATA[After chatting with [ my buddy Dave ](http://mortysworld.blogspot.com) about how awesome it is to show off using terminal to !1337 computer users I realized how often I&#8217;m sitting at command-line listening to music in iTunes and wondered how to control iTunes with a shell script. I searched around an found [ this ](http://www.macosxhints.com/article.php?story=20011108211802830) article on [...]]]></description>
			<content:encoded><![CDATA[<p>After chatting with [ my buddy Dave ](http://mortysworld.blogspot.com)<br />
about how awesome it is to show off using terminal to !1337 computer<br />
users I realized how often I&#8217;m sitting at command-line listening to music<br />
in iTunes and wondered how to control iTunes with a shell script.</p>
<p>I searched around an found [ this ](http://www.macosxhints.com/article.php?story=20011108211802830)<br />
article on the topic but of course wanted many tweaks of my own so I&#8217;ve<br />
wrote the following script that should allow anyone to control iTunes in terminal<br />
or via SSH remotely.</p>
<p>### Possible Uses ###<br />
The implications are pretty neat if you think about it. </p>
<ul>
<li>DJ a party from a laptop, iPhone, or mobile with SSH</li>
<li>Control your home or office music server remotely</li>
<li>Scare the heck out of your roommates</li>
</ul>
<p><span id="more-123"></span></p>
<p>### The Code ###</p>
<pre name="code" class="php">
#!/bin/sh
#
####################################
# iTunes Command Line Control v1.0
# written by David Schlosnagle
# created 2001.11.08
# edited by Jon Todd 2007.11.20
####################################

showHelp () {
echo "-----------------------------";
echo "iTunes Command Line Interface";
echo "-----------------------------";
echo "Usage: `basename $0`
<option>";
echo;
echo "Options:";
echo " status   = Current state of iTunes.";
echo " play     = Start playing iTunes.";
echo " pause    = Pause iTunes.";
echo " next     = Go to the next track.";
echo " prev     = Go to the previous track.";
echo " mute     = Mute iTunes' volume.";
echo " unmute   = Unmute iTunes' volume.";
echo " vol up   = Increase iTunes' volume by 10%";
echo " vol down = Increase iTunes' volume by 10%";
echo " vol #    = Set iTunes' volume to # [0-100]";
#echo " playlist "@" = Play iTunes' playlist named @";
echo " shuf = Shuffle current playlist";
echo " nosh = Do not shuffle current playlist";
echo " stop     = Stop iTunes.";
echo " quit     = Quit iTunes.";
}

showError ()
{
echo ;
echo "ERROR:";
echo $1;
}

if [ $# = 0 ]; then
  showHelp;
fi

while [ $# -gt 0 ]; do
  action=$1;
  case $action in
  "status" ) state=`osascript -e 'tell application "iTunes" to player state as string'`;
  # State
  echo "State: \t\t$state";

  # Volume
  vol=`osascript -e 'tell application "iTunes" to sound volume as integer'`;
  echo "Volume: \t$vol";

  # Playlist
  playlist=`osascript -e 'tell application "iTunes" to name of current playlist as string'`;
  echo "Playlist: \t$playlist";

  # Shuffle
  shuffle=`osascript -e 'tell application "iTunes" to shuffle of current playlist as string'`;
  echo "Shuffle: \t$shuffle";

  # Current Song
  if [ $state = "playing" ]; then

    # Artist
    artist=`osascript -e 'tell application "iTunes" to artist of current track as string'`;
    echo "Artist: \t$artist";

    # Artist
    album=`osascript -e 'tell application "iTunes" to album of current track as string'`;
    echo "Album: \t\t$album";

    # Track
    track=`osascript -e 'tell application "iTunes" to name of current track as string'`;
    echo "Track: \t\t$track";
  fi
  break ;;

  # TODO: Figure out how to get this working
  # "playlist" ) echo "Changing iTunes playlist.";
  # osascript -e 'tell application \"iTunes\" to play playlist "Combo" ';
  # break ;; 

  "play"    ) echo "Playing iTunes.";
  osascript -e 'tell application "iTunes" to play';
  break ;;

  "pause"    ) echo "Pausing iTunes.";
  osascript -e 'tell application "iTunes" to pause';
  break ;;

  "next"    ) echo "Going to next track." ;
  osascript -e 'tell application "iTunes" to next track';
  break ;;

  "prev"    ) echo "Going to previous track.";
  osascript -e 'tell application "iTunes" to previous track';
  break ;;

  "mute"    ) echo "Muting iTunes volume level.";
  osascript -e 'tell application "iTunes" to set mute to true';
  break ;;

  "unmute" ) echo "Unmuting iTunes volume level.";
  osascript -e 'tell application "iTunes" to set mute to false';
  break ;;

  "vol"    ) echo "Changing iTunes volume level.";
  if [  "$#" -gt 1 ]; then
    vol=`osascript -e 'tell application "iTunes" to sound volume as integer'`;
    if [ $2 = "up" ]; then
      newvol=$(( vol+10 ));

    elif [ $2 = "down" ]; then
      newvol=$(( vol-10 ));

    elif [ $2 -gt 0 ]; then
      newvol=$2;
    fi
    osascript -e "tell application \"iTunes\" to set sound volume to $newvol";
    else
    showError "No volume level specified";
  fi
  break;;

  "stop"    ) echo "Stopping iTunes.";
  osascript -e 'tell application "iTunes" to stop';
  break ;;

  "quit"    ) echo "Quitting iTunes.";
  osascript -e 'tell application "iTunes" to quit';
  exit 1 ;;

  "shuf" ) echo "Shuffle is ON.";
  osascript -e 'tell application "iTunes" to set shuffle of current playlist to 1';
  break ;; 

  "nosh" ) echo "Shuffle is OFF.";
  osascript -e 'tell application "iTunes" to set shuffle of current playlist to 0';
  break ;;

  "help" | * ) echo "help:";
  showHelp;
  break ;;
esac
done
</pre>
<p>### Installation ###</p>
<p>Write this code to a file called &#8220;itunes&#8221; and put it in your bin directory</p>
<pre name="code" class='shell'>
mkdir ~/bin
mv pathToFile/itunes.sh ~/bin
chmod u+x ~/bin/itunes
</pre>
<p>Ensure ~/bin is in your path</p>
<p>### Run it ###</p>
<pre name="code" class='shell'>
[jtodd@local:~]$ itunes status
State: 		stopped
Volume: 	100
Playlist: 	Combo
Shuffle: 	false
[jtodd@local:~]$ itunes play
Playing iTunes.
[jtodd@local:~]$ itunes status
State: 		playing
Volume: 	100
Playlist: 	Combo
Shuffle: 	false
Artist: 	Jamiroquai
Album: 		synkronized
Track: 		Canned Heat
[jtodd@local:~]$ itunes vol 50
Changing iTunes volume level.
[jtodd@local:~]$ itunes pause
Pausing iTunes.
[jtodd@local:~]$ itunes vol 100
Changing iTunes volume level.
[jtodd@local:~]$ itunes play
Playing iTunes.
</pre>
<p>### Remote Control ###</p>
<pre name="code" class='shell'>
[jtodd@remote:~]$ ssh local
[jtodd@local:~]$ itunes status
State: 		playing
Volume: 	100
Playlist: 	Combo
Shuffle: 	false
Artist: 	Jamiroquai
Album: 		synkronized
Track: 		Canned Heat
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.jontodd.com/2007/11/19/how-to-control-itunes-remotely-with-ssh/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Curl Multi Php Download How-To</title>
		<link>http://www.jontodd.com/2007/11/08/curl-multi-php-download-how-to/</link>
		<comments>http://www.jontodd.com/2007/11/08/curl-multi-php-download-how-to/#comments</comments>
		<pubDate>Thu, 08 Nov 2007 08:49:21 +0000</pubDate>
		<dc:creator>Jon Todd</dc:creator>
				<category><![CDATA[Computers]]></category>
		<category><![CDATA[Curl Multi Php Download How-To]]></category>

		<guid isPermaLink="false">http://www.jontodd.com/2007/11/09/curl-multi-php-download-how-to/</guid>
		<description><![CDATA[This article will show you an example of how to download multiple files concurrently using the curl_multi commands in PHP 5.While php itself doesn&#8217;t support multi threading and concurrency, libcurl does and php allows us to download multiple filesat the same time from php. // Files to download $urls = array('http://static.scribd.com/docs/cdbwpohq0ayey.pdf', 'http://static.scribd.com/docs/8wyxlxfufftas.pdf', 'http://static.scribd.com/docs/9q29bbglnc2gk.pdf',); // Path [...]]]></description>
			<content:encoded><![CDATA[<p>This article will show you an example of how to download multiple files concurrently using the curl_multi commands in PHP 5.While php itself doesn&#8217;t support multi threading and concurrency, libcurl does and php allows us to download multiple filesat the same time from php.</p>
<p><span id="more-117"></span></p>
<pre name="code" class="php">
// Files to download
$urls = array('http://static.scribd.com/docs/cdbwpohq0ayey.pdf',
              'http://static.scribd.com/docs/8wyxlxfufftas.pdf',
              'http://static.scribd.com/docs/9q29bbglnc2gk.pdf',);

// Path to save files in
$save_path = '/tmp';

$multi_handle = curl_multi_init();
$file_pointers = array();
$curl_handles = array();

// Add curl multi handles, one per file we don't already have
foreach ($urls as $key => $url) {
  $file = $save_path.'/'.basename($url);
  if(!is_file($file)){
    $curl_handles[$key]=curl_init($url);
    $file_pointers[$key]=fopen ($file, "w");
    curl_setopt ($curl_handles[$key], CURLOPT_FILE,           $file_pointers[$key]);
    curl_setopt ($curl_handles[$key], CURLOPT_HEADER ,        0);
    curl_setopt ($curl_handles[$key], CURLOPT_CONNECTTIMEOUT, 60);
    curl_multi_add_handle ($multi_handle,$curl_handles[$key]);
  }
}

// Download the files
do {
  curl_multi_exec($multi_handle,$running);
}
while($running > 0);

// Free up objects
foreach ($urls as $key => $url) {
  curl_multi_remove_handle($multi_handle,$curl_handles[$key]);
  curl_close($curl_handles[$key]);
  fclose ($file_pointers[$key]);
}
curl_multi_close($multi_handle);
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.jontodd.com/2007/11/08/curl-multi-php-download-how-to/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Two Geeks, One Company: Adventex Design</title>
		<link>http://www.jontodd.com/2007/07/03/two-geeks-one-company-adventex-design/</link>
		<comments>http://www.jontodd.com/2007/07/03/two-geeks-one-company-adventex-design/#comments</comments>
		<pubDate>Tue, 03 Jul 2007 17:02:12 +0000</pubDate>
		<dc:creator>Jon Todd</dc:creator>
				<category><![CDATA[Bowdoin]]></category>
		<category><![CDATA[Computers]]></category>
		<category><![CDATA[Personal]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.jontodd.com/2007/07/03/two-geeks-one-company-adventex-design/</guid>
		<description><![CDATA[So Tom pointed me to [some photos](http://www.bowdoin.edu/~ltoma/honors05-pics/Sites.html) from the good old days working long hours in the computer science lab at Bowdoin. I guess I always thought I was a pretty chill/normal CS kid but the truth is in the photos and I&#8217;m not going to lie, we look like total dorks. Tom&#8217;s going to [...]]]></description>
			<content:encoded><![CDATA[<p>So Tom pointed me to [some photos](http://www.bowdoin.edu/~ltoma/honors05-pics/Sites.html) from the good old days working long hours in the computer science lab at Bowdoin. I guess I always thought I was a pretty chill/normal CS kid but the truth is in the photos and I&#8217;m not going to lie, we look like total dorks. Tom&#8217;s going to kill me for putting this up here but it&#8217;s a nice segue into what we&#8217;re both doing now.</p>
<p>This past winter Tom and I went into the web consulting biz together under the company Adventex Design which I started back in 2000. Currently we&#8217;re working on some top secret projects which we hope you&#8217;ll be hearing about soon <img src='http://www.jontodd.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  If you or someone you know has some programming talent and experience with web applications we&#8217;d be interested in chatting with you.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jontodd.com/2007/07/03/two-geeks-one-company-adventex-design/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How To use Cookies with RSSFeed Scanner &amp; Azureus</title>
		<link>http://www.jontodd.com/2006/10/10/how-to-use-cookies-with-rssfeed-scanner-azureus/</link>
		<comments>http://www.jontodd.com/2006/10/10/how-to-use-cookies-with-rssfeed-scanner-azureus/#comments</comments>
		<pubDate>Wed, 11 Oct 2006 03:49:55 +0000</pubDate>
		<dc:creator>Jon Todd</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Computers]]></category>

		<guid isPermaLink="false">http://www.jontodd.com/2006/10/10/how-to-use-cookies-with-rssfeed-scanner-azureus/</guid>
		<description><![CDATA[For those of you who use bit torrent to download various tv shows, podcasts, videocasts or any other type of periodicly updated media there is now a way to automate the process. I use azureus for my bit torrent download client and have added the RSSFeed Scanner Plugin which you can learn about how to [...]]]></description>
			<content:encoded><![CDATA[<p>For those of you who use bit torrent to download various tv shows, podcasts, videocasts or any other type of periodicly updated media there is now a way to automate the process. I use <a href="http://azureus.sourceforge.net/"title="Azureus"  onclick="javascript:pageTracker._trackPageview('/outbound/article/azureus.sourceforge.net');">azureus</a> for my bit torrent download client and have added the RSSFeed Scanner Plugin which you can learn about how to install from <a href="http://www.zeropaid.com/news/6411/Azureus+RSS+Feed+Made+Easy " onclick="javascript:pageTracker._trackPageview('/outbound/article/www.zeropaid.com');">zeropaid</a>. While they certainly do a great job of telling you how to install the plugin they leave out the details of how to download from a site that requires a login. I&#8217;ll explain how this can be done with cookies.</p>
<p><span id="more-102"></span></p>
<p><strong>How to download with RSSFeed Scanner on a site that requires a login</strong></p>
<ol>
<li>Site that require a login many times use cookies to store your session so that after you login your credentials are remembered as you browse the site. The bit torrent site you are using requires a login and does not use cookies this method won&#8217;t help</li>
<li>Download Firefox if you don&#8217;t have it.</li>
<li>Download the <a href="https://addons.mozilla.org/firefox/60/" onclick="javascript:pageTracker._trackPageview('/outbound/article/addons.mozilla.org');">Web Developer Toolbar</a> for firefox. This is handy for all kinds of hacks!!!</li>
<li>Once installed, visit your favorite bit torrent site with firefox and login</li>
<li>Click the cookies tab on the developer toolbar and choose &#8220;View Cookie Information&#8221;</li>
<li>Now a list of cookies will come up each with various data fields. Among all the various cookies we need to find th one used by the site that is your user name or uid. There is no standard name. For demonoid.com the user id is stored in a cookie called &#8220;uid&#8221; and the password hash is stored in a cookie named &#8220;uhsh&#8221;</li>
<li>copy and paste the user and password name and value pairs into the form:<br />
<code>name=value;name=value</code><br />
In the case of demonoid.com it was of the form:<br />
<code>uid=XXXXXX;uhsh=YYYYYYYYYYYYYYYYYYYYYYYY</code><br />
The hash was even longer then that actually and had many HTML encoded charaters as a password hash tends to be.</li>
<li>Go into azureus&#8217;s RSSFeed Scanner and select or add a url in the option tab.</li>
<li>Check the option for passing cookies &#8220;Pass Cookies&#8217;s&#8221; and paste your string in the box.</li>
<li>Click the status tab and double click one of the files to see if you can download it. With any luck it will start downloading.</li>
</ol>
<p><strong>A Note About Cookie Expiration</strong></p>
<p>Some cookies maybe set to expire rather quickly after login. You can check the expire time when you view your cookie in step 6. If the expiration is anytime in the near furture you will have to redo this hack again after that date. Luckily demonoid.com was set for 2011 so I&#8217;ve still got some time <img src='http://www.jontodd.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><strong>Other Sites Cookie Info</strong></p>
<p>As there may be some interest in having this info readily available I will compile a list of cookie info from other bit torrent sites as I find them or you submit them.</p>
<p>Demonoid.com<br />
<code>uid=XXXXXX;uhsh=YYYYYYYYYYYYYYYYYYYYYYYY</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.jontodd.com/2006/10/10/how-to-use-cookies-with-rssfeed-scanner-azureus/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Remove last comma of string in PHP</title>
		<link>http://www.jontodd.com/2006/09/11/remove-last-comma-of-string-in-php/</link>
		<comments>http://www.jontodd.com/2006/09/11/remove-last-comma-of-string-in-php/#comments</comments>
		<pubDate>Mon, 11 Sep 2006 06:06:07 +0000</pubDate>
		<dc:creator>Jon Todd</dc:creator>
				<category><![CDATA[Computers]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.jontodd.com/2006/09/11/remove-last-comma-of-string-in-php/</guid>
		<description><![CDATA[After building a list of items in a string (ie &#8220;x1,x2,x3,x4,&#8221;) I typically find myself needing to remove the last comma. After using this for the longest time: $str = substr($str,0,strlen($str)-1); I found: $str = substr($str,'',-1); This will actually remove the last character whatever it is so be careful, for my uses it&#8217;s perfect. I [...]]]></description>
			<content:encoded><![CDATA[<p>After building a list of items in a string (ie &#8220;x1,x2,x3,x4,&#8221;) I typically find myself needing to remove the last comma. After using this for the longest time:</p>
<p><code> $str = substr($str,0,strlen($str)-1); </code></p>
<p>I found:</p>
<p><code> $str = substr($str,'',-1);</code></p>
<p>This will actually remove the last character whatever it is so be careful, for my uses it&#8217;s perfect.</p>
<p>I know this is not novel but it&#8217;s elegant and these are the things that make my day.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jontodd.com/2006/09/11/remove-last-comma-of-string-in-php/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Creating and ISO image on a Mac in OSX</title>
		<link>http://www.jontodd.com/2006/09/10/creating-and-iso-image-on-a-mac-in-osx/</link>
		<comments>http://www.jontodd.com/2006/09/10/creating-and-iso-image-on-a-mac-in-osx/#comments</comments>
		<pubDate>Mon, 11 Sep 2006 02:13:59 +0000</pubDate>
		<dc:creator>Jon Todd</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Computers]]></category>
		<category><![CDATA[OS X]]></category>

		<guid isPermaLink="false">http://www.jontodd.com/2006/09/10/creating-and-iso-image-on-a-mac-in-osx/</guid>
		<description><![CDATA[Creating disk images on a mac is easy. If you have an older version of OS X you should see a program called Disk Copy in your Utilities folder. If you use OS X > 10.4 your Disk Utility will do the trick. Just go to File > New and create an image of any [...]]]></description>
			<content:encoded><![CDATA[<p>Creating disk images on a mac is easy. If you have an older version of OS X you should see a program called Disk Copy in your Utilities folder. If you use OS X > 10.4 your Disk Utility will do the trick.</p>
<p>Just go to File > New and create an image of any volume on your computer. That&#8217;s the easy part.</p>
<p><span id="more-97"></span><strong>How to turn the Disk Utility created image from .dmg to .iso</strong></p>
<p>Right so for some reason they don&#8217;t give you the option to output to an iso directly so you&#8217;ll need to do some hacker. Assuming your newly created .dmg or .cdr image in on your desktop, open the ol&#8217; terminal and run this snazy prog that should already be on your machine:</p>
<p><code>hdiutil makehybrid -iso -joliet -o ~/Desktop/file.iso ~/Desktop/file.dmg</code></p>
<p><strong>Why might you need to do this?</strong></p>
<p>Heck I don&#8217;t know. If your image ever needs to be compatible for your lowley windows using friends then you&#8217;ll probably need to know this.</p>
<p>I *NEEDED* to do it for use with Virtual PC. That&#8217;s right, in order to create a .iso disk image that you can capture with Virtual PC you need the image format to be in a windows compatible iso. The only reason I need to use Virtual PC is that Kaplan and ETS still don&#8217;t support Mac. If grad schools require the test they should make the study material accessable to everyone!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jontodd.com/2006/09/10/creating-and-iso-image-on-a-mac-in-osx/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

