<?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>Craig Russell Web n That &#187; Tutorials</title>
	<atom:link href="http://www.craig-russell.co.uk/category/tutorials/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.craig-russell.co.uk</link>
	<description>Web developement, identity management, federated access, web tech, geekery and the odd bit of paper folding</description>
	<lastBuildDate>Fri, 27 Jan 2012 21:57:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Kindle 4 Custom Screen Savers</title>
		<link>http://www.craig-russell.co.uk/kindle-4-custom-screen-savers/</link>
		<comments>http://www.craig-russell.co.uk/kindle-4-custom-screen-savers/#comments</comments>
		<pubDate>Sat, 31 Dec 2011 14:39:32 +0000</pubDate>
		<dc:creator>Craig</dc:creator>
				<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.craig-russell.co.uk/?p=1006</guid>
		<description><![CDATA[Early Kindles allowed you to use your own images as screen savers, this feature was removed in later models. Thankfully people much smarter than me had written custom firmware giving you this feature back. Unfortunately this firmware hack doesn&#8217;t work with the latest 4th generation non-touch (NT) Kindle. There is however, still a way of&#8230;]]></description>
			<content:encoded><![CDATA[<p>Early Kindles allowed you to use your own images as screen savers, this feature was removed in later models. Thankfully people much smarter than me had written custom firmware giving you this feature back. Unfortunately this firmware hack doesn&#8217;t work with the latest 4th generation non-touch (NT) Kindle.</p>
<p>There is however, still a way of getting this functionality on the Kindle 4 NT, but it is quite fiddly and requires you to have some knowledge of Linux file systems, basic networking and SSH. I achieved this using a Linux (Ubuntu) PC, there instructions are probably largely similar for MACs too. Windows users will have to install some extra software tools and the networking bit will be different too (Don&#8217;t ask &#8211; I won&#8217;t know).</p>
<p>Basically all we&#8217;re going to do is move the screensaver images folder to the part of the kindle that is accessible over USB and creating a symbolic link to this location. However, the route from here to there is a bit contrived. If you&#8217;re not sure what you&#8217;re doing it&#8217;s best to ask a techo-literate friend to help out. Oh, it should also go without saying that this probably invalidates your warranty too.</p>
<h2>Diagnostic Mode</h2>
<p>The first thing we need to do is put the Kindle in to Diagnostic Mode.</p>
<ol>
<li>Connect the Kindle to your PC with the USB cable.</li>
<li>Create a file on the Kindle called <code>ENABLE_DIAGS</code></li>
<li>Unmount the Kindle and disconnect the USB cable.</li>
<li>Restart the Kindle<br/><br />
  <em>[MENU] Settings [MENU] Restart</em> <br/><br />
  This will take a few minutes.</li>
<li>You should now be in Diagnostic Mode.</li>
</ol>
<h2>Gaining Root Access</h2>
<p>Next we need to connect to the Kindle as root which will allow us to fiddle around with it.</p>
<ol>
<li>Connect the Kindle to your PC with the USB cable. It should <em>NOT</em> mount.</li>
<li>Enable USB Networking from the menu.<br/><br />
    <em>Misc individual diagnostics > Utilities > Enable USBNet</em></li>
<li>The Kindle should now be a network device on your PC. <br/><br />
    <code>ifconfig</code></li>
<li>Configure a IP address for the device. <br/><br />
    <code>ip addr add 192.168.15.241/24 dev usb0</code></li>
<li>You should now be able to SSH in to the Kindle as root. <br/><br />
    <code>ssh root@192.168.15.244</code> <br/><br />
    The password is &#8220;mario&#8221;.<br/><br />
    <strong>Edit:</strong> If &#8220;mario&#8221; doesn&#8217;t work <a href="http://members.ping.de/~sven/kindle.html" target="_blank">try this tool</a>.</li>
<li>You now have root access to your Kindle</li>
</ol>
<h2>Moving the Screen Savers</h2>
<p>Now we&#8217;re going to move the screensavers from their existing location to a new folder in <code>/mnt/us/</code>, which is the folder accessible via USB.</p>
<ol>
<li>First mount the required partition.<br/><br />
    <code>mount /dev/mmcblk0p1 /mnt/base-mmc</code></li>
<li>Backup the existing screensavers.<br/><br />
    <code>mv /mnt/base-mmc/opt/amazon/screen_saver/600x800 /mnt/base-mmc/opt/amazon/screen_saver/600x800.bak</code></li>
<li>Create a folder for custom screen savers.<br/><br />
    <code>mkdir /mnt/us/screensaver</code></li>
<li>Create a link from the screen saver location to the new folder.<br/><br />
    <code>ln -sfn /mnt/us/screensaver /mnt/base-mmc/opt/amazon/screen_saver/600x800</code></li>
<li>You can optionally copy the existing screen savers to the new folder if you want to keep them.<br/><br />
    <code>cp /mnt/base-mmc/opt/amazon/screen_saver/600x800.bak/* /mnt/us/screensaver/</code></li>
<li>End the SSH session.<br/><br />
    <code>exit</code></li>
<li>Exit Diagnostic Mode<br/><br />
    <em>Exit, Reboot or Disable Diags > Disable Diagnostics > To continue &#8211; FW LEFT</em></li>
<li>Wait a few minutes for the Kindle to reboot.</li>
<li>That&#8217;s the screen savers moved!</li>
</ol>
<h2>Setting Custom Screen Savers</h2>
<p>Now you can copy your own screen saver images to your Kindle. All you need to do is connect your Kindle to your PC with the USB cable and copy the images you want in to the <code>screensaver</code> folder.</p>
<p>The images files must be 600&#215;800 pixels. I think they also have to be PNG files and 72dpi in 32bit indexed greyscale. Some people on the forums have said that this isn&#8217;t necessary, others say it is. But this format works fine for me where others didn&#8217;t.</p>
<p>There are various sites out there with Kindle screen savers to download, you may or may not need to do some image conversion. I leave it to you to experiment.</p>
<p>You also have to researt the Kindle fully (<em>[MENU] Settings [MENU] Restart</em>) before the new screen savers will work.</p>
<p>Have fun!</p>
<p><strong>Edit:</strong> <a href="http://www.craig-russell.co.uk/downloads/Kindle4OriginalScreensavers.zip">Here&#8217;s the original Kindle 4 Screen Savers</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.craig-russell.co.uk/kindle-4-custom-screen-savers/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<item>
		<title>How To Create and Test a Ruby on Rails Plugin</title>
		<link>http://www.craig-russell.co.uk/how-to-create-and-test-a-ruby-on-rails-plugin/</link>
		<comments>http://www.craig-russell.co.uk/how-to-create-and-test-a-ruby-on-rails-plugin/#comments</comments>
		<pubDate>Wed, 09 Nov 2011 15:27:05 +0000</pubDate>
		<dc:creator>Craig</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.craig-russell.co.uk/?p=976</guid>
		<description><![CDATA[I&#8217;ve been learning how to create a plugin in Ruby on Rails 3.1 and test it using RSpec. I haven&#8217;t been able to find a tutorial for this anywhere, so I&#8217;ll share what I&#8217;ve done here. First up, use rails to generate a new plugin. ]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been learning how to create a plugin in Ruby on Rails 3.1 and test it using RSpec. I haven&#8217;t been able to find a tutorial for this anywhere, so I&#8217;ll share what I&#8217;ve done here.</p>
<p>First up, use rails to generate a new plugin.</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">$ rails generate plugin HelloWorld</pre></div></div>

<p>This will create a folder in <code>/vendor/plugins/hello_world</code> containing template files for the plugin. What it won&#8217;t do is create a test file for RSpec, so we&#8217;ll create it manually later. This is a <a href="https://github.com/rspec/rspec-rails/issues/258" target="_blank">known issue</a>.</p>
<p>In the plugin folder there&#8217;s a few files, most of which are self-explanatory. We&#8217;re only going to be interested in <code>hello_world/init.rb</code> and <code>hello_world/lib/hello_world.rb</code>.</p>
<p><code>hello_world/init.rb</code> tells Rails what to do with the plugin. We&#8217;re not going to do too much, so we just need to require the main class file.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># Include hook code here</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'hello_world'</span></pre></div></div>

<p>Next we create the main class in <code>hello_world/lib/hello_world.rb</code>.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># HelloWorld</span>
<span style="color:#9966CC; font-weight:bold;">class</span> HelloWorld
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Before we go any further we should set up a test, because we do things properly. RSpec tests live in <code>/spec</code> so we&#8217;ll create a folder for plugin tests and create a spec file for our plugin there.</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">$ mkdir /spec/plugins
$ touch /spec/plugins/hello_world_spec.rb</pre></div></div>

<p>Lets define a simple test for our plugin in <code>/spec/plugins/hello_world_spec.rb</code></p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'spec_helper'</span>
describe HelloWorld <span style="color:#9966CC; font-weight:bold;">do</span>
  describe <span style="color:#996600;">&quot;should have method&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    it <span style="color:#996600;">&quot;'hi'&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
      response = HelloWorld.<span style="color:#9900CC;">instance_methods</span>.<span style="color:#9966CC; font-weight:bold;">include</span>? <span style="color:#ff3333; font-weight:bold;">:hi</span>
      response.<span style="color:#9900CC;">should</span> == <span style="color:#0000FF; font-weight:bold;">true</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>We&#8217;ve done a few things here, firstly we&#8217;ve required the RSpec helper file, all RSpec tests need this. The first describe block is defined with the name of the class we are testing. Then we&#8217;ve added a test to check that a method exists. If you run the test, it should fail.</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">$ rspec /spec/plugins/hello_world_spec.rb</pre></div></div>

<p>Now we can add a method to the <code>HelloWorld</code> class, which should get the test to pass.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># HelloWorld</span>
<span style="color:#9966CC; font-weight:bold;">class</span> HelloWorld
  <span style="color:#9966CC; font-weight:bold;">def</span> hi
    <span style="color:#996600;">&quot;Hello World!&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>That&#8217;s it!</p>
<p>Now you have a working plugin, you can use it in your Rails application. You can create objects in controllers and call functions from views, there&#8217;s no need to explicitly require the plugin anywhere.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># app/controllers/pages_controller.rb</span>
<span style="color:#9966CC; font-weight:bold;">class</span> PagesController <span style="color:#006600; font-weight:bold;">&lt;</span> ApplicationController
  <span style="color:#9966CC; font-weight:bold;">def</span> hello
    <span style="color:#0066ff; font-weight:bold;">@hw</span> = HelloWorld.<span style="color:#9900CC;">new</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;!-- app/views/pages/hello.html.erb --&gt;
&lt;p&gt;&lt;%= @hw.hi %&gt;&lt;/p&gt;</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.craig-russell.co.uk/how-to-create-and-test-a-ruby-on-rails-plugin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Samsung Galaxy S2 Tweaks</title>
		<link>http://www.craig-russell.co.uk/samsung-galaxy-s2-tweaks/</link>
		<comments>http://www.craig-russell.co.uk/samsung-galaxy-s2-tweaks/#comments</comments>
		<pubDate>Sat, 03 Sep 2011 09:40:20 +0000</pubDate>
		<dc:creator>Craig</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.craig-russell.co.uk/?p=917</guid>
		<description><![CDATA[I love the Galaxy S2, It is a really well built piece of kit. There are, however, a few little annoyances with it, some of which can be fixed if you don&#8217;t mind getting your hands dirty. Here&#8217;s what you need to do to get going. Root the phone (this is very easy). Follow the&#8230;]]></description>
			<content:encoded><![CDATA[<p>I love the Galaxy S2, It is a really well built piece of kit. There are, however, a few little annoyances with it, some of which can be fixed if you don&#8217;t mind getting your hands dirty.</p>
<p>Here&#8217;s what you need to do to get going.</p>
<ol>
<li>Root the phone (this is very easy). Follow the <a href="http://lifehacker.com/5789397/the-always-up+to+date-guide-to-rooting-any-android-phone">instructions on Lifehacker</a>.
<li>Download ES File Explorer from the market</li>
<li>Enable these settings<br/>
<ul>
<li>Settings>Root Explorer</li>
<li>Settings>Mount File System</li>
</ul>
</ol>
<p>This will give you writeable access to the file system, now you can fix those annoyances.</p>
<h2>Disable the Start Up Sound</h2>
<ol>
<li>Rename <code>/etc/PowerOn.wav</code> to <code>/etc/PowerOn.wav.old</code></li>
</ol>
<h2>Disable Camera Shutter Sound</h2>
<ol>
<li>Create a text file <code>/data/local.prop</code></li>
<li>Add this line <code>ro.camera.sound.forced=0</code></li>
<li>Restart your phone</li>
</ol>
<h2>Disable Battery Full Sound</h2>
<ol>
<li>Rename <code>/system/media/audio/ui/LowBattery.ogg</code> to <code>/system/media/audio/ui/LowBattery.ogg.bak</code></li>
</ol>
<h2>More Tips</h2>
<p>If you know of any other tweaks, let me know. I&#8217;ll be keeping this list updated.</p>
<p>There&#8217;s also lots of power user features built in, so <a href="http://thehandheldblog.com/2011/06/14/galaxy-s2-tips-tricks/">check them out too</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.craig-russell.co.uk/samsung-galaxy-s2-tweaks/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Git Tip: Custom Config Parameters</title>
		<link>http://www.craig-russell.co.uk/git-tip-custom-config-parameters/</link>
		<comments>http://www.craig-russell.co.uk/git-tip-custom-config-parameters/#comments</comments>
		<pubDate>Wed, 24 Aug 2011 12:06:04 +0000</pubDate>
		<dc:creator>Craig</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.craig-russell.co.uk/?p=898</guid>
		<description><![CDATA[Git is lovely. You know this. Here&#8217;s another bit of Gitty loveliness for you: Custom Config Parameters. The primary configuration file in Git is found in .git/config. In here are the configuration parameters for your repository. Git provides a tool to manage this file &#8211; git config. Handily this tool lets you store your own&#8230;]]></description>
			<content:encoded><![CDATA[<p>Git is lovely. You know this. </p>
<p>Here&#8217;s another bit of Gitty loveliness for you: Custom Config Parameters.</p>
<p>The primary configuration file in Git is found in <code>.git/config</code>. In here are the configuration parameters for your repository. Git provides a tool to manage this file &#8211; <a href="http://kernel.org/pub/software/scm/git/docs/git-config.html">git config</a>. Handily this tool lets you store your own configuration parameters too.</p>
<h2>How to do it</h2>
<p>If you have a look inside <code>.git/config</code> you&#8217;ll see that data is structured in key-value pairs grouped in to sections.</p>

<div class="wp_syntax"><div class="code"><pre class="plain" style="font-family:monospace;">[branch &quot;master&quot;]
	remote = origin
	merge = refs/heads/master</pre></div></div>

<p>Which is accessed by running a command like this&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">-&gt; git config branch.master.remote
origin</pre></div></div>

<p>And modified like this&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">-&gt; git config branch.master.remote newValue</pre></div></div>

<p>You can define a new section to store your own data like this&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">-&gt; git config mydata.mykey valueA</pre></div></div>

<p>You can store multiple values too&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">-&gt; git config --add mydata.mykey valueB</pre></div></div>

<p>And fetch them all like this&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">-&gt; git config --get-all mydata.mykey
valueA
valueB</pre></div></div>

<p>Delete a single value like this&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">-&gt; git config --unset mydata.mykey valueB</pre></div></div>

<p>Delete all key values like this&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">-&gt; git config --unset-all mydata.mykey</pre></div></div>

<p>And to remove a whole section&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">-&gt; git config --remove-section mydata</pre></div></div>

<h2>What to do with it</h2>
<p>That&#8217;s great, but what can you do with it?</p>
<p>Why not use it to store parameters for your workflow scripts? Here&#8217;s some ideas.</p>
<ul>
<li>The locations of CSS and JS files to be minified</li>
<li>Compilation output directory</li>
<li>The latest version release number (if your not a tag fan)</li>
<li>Feature branch meta data (owner, decription, etc.)</li>
<li>A list of deployment servers</li>
</ul>
<p>If you use this feature in your scripts, drop a comment below.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.craig-russell.co.uk/git-tip-custom-config-parameters/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Samsung Galaxy S2 USB Storage and Tethering with Ubuntu</title>
		<link>http://www.craig-russell.co.uk/samsung-galaxy-s2-usb-storage-and-tethering-with-ubuntu/</link>
		<comments>http://www.craig-russell.co.uk/samsung-galaxy-s2-usb-storage-and-tethering-with-ubuntu/#comments</comments>
		<pubDate>Thu, 16 Jun 2011 10:58:44 +0000</pubDate>
		<dc:creator>Craig</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.craig-russell.co.uk/?p=874</guid>
		<description><![CDATA[I&#8217;ve just got myself a shiny new Samsung Galaxy S2. I&#8217;m not going to write a big old review of the whole thing here, there&#8217;s plenty of others elsewhere. Ubuntu users may have difficulty mounting the phone via USB. Getting ugly errors like this&#8230; "Unable to mount SAMSUNG_Android Error initialising camera: -60: Could not lock&#8230;]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve just got myself a shiny new Samsung Galaxy S2. I&#8217;m not going to write a big old review of the whole thing here, there&#8217;s plenty of others elsewhere. Ubuntu users may have difficulty mounting the phone via USB. Getting ugly errors like this&#8230;</p>
<p><code>"Unable to mount SAMSUNG_Android Error initialising camera: -60: Could not lock the device"</code></p>
<p>Samsung uses it&#8217;s own software to sync and update the phone called Kies. Kies is only available for Windows (naturally), not Mac or Linux. But you can still use the USB storage and USB tethering, you just have to enable USB debug mode.</p>
<p><code>Settings &gt; Applications &gt; Development &gt; USB Debugging</code></p>
<p>Now when you connect the phone with the USB cable, you can choose to mount the USB storage from the status bar.<br />
Alternatively, you can use the USB tethering.</p>
<p><code>Settings &gt; Wireless and Network &gt; Tethering and Portable Hotspot Settings &gt; USB Tethering.</code></p>
<p><strong>Edit</strong> also check out my post on <a href="http://www.craig-russell.co.uk/samsung-galaxy-s2-tweaks/">Galaxy S2 tweaks</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.craig-russell.co.uk/samsung-galaxy-s2-usb-storage-and-tethering-with-ubuntu/feed/</wfw:commentRss>
		<slash:comments>26</slash:comments>
		</item>
		<item>
		<title>Command Line Arguments in Java</title>
		<link>http://www.craig-russell.co.uk/command-line-arguments-in-java/</link>
		<comments>http://www.craig-russell.co.uk/command-line-arguments-in-java/#comments</comments>
		<pubDate>Thu, 28 Apr 2011 10:02:05 +0000</pubDate>
		<dc:creator>Craig</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.craig-russell.co.uk/?p=863</guid>
		<description><![CDATA[Commonly, programs can be configured by passing arguments on the command line. ]]></description>
			<content:encoded><![CDATA[<p>Commonly, programs can be configured by passing arguments on the command line.</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">$ myprogram -i /input/file.txt -o /output/file.txt</pre></div></div>

<p>This is easy enough to achieve in Java, the snippet of code below shows you how.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> getArgs <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// Set defaults</span>
        <span style="color: #003399;">Integer</span> i <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
        <span style="color: #003399;">Double</span>  d <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0.0</span><span style="color: #339933;">;</span>
        <span style="color: #003399;">String</span>  s <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// Get input arguments from command line</span>
        <span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> j<span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> j<span style="color: #339933;">&lt;</span>args.<span style="color: #006633;">length</span><span style="color: #339933;">;</span> j<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">try</span><span style="color: #009900;">&#123;</span>
                <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> args<span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span>.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;-i&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> i  <span style="color: #339933;">=</span> <span style="color: #003399;">Integer</span>.<span style="color: #006633;">parseInt</span><span style="color: #009900;">&#40;</span>args<span style="color: #009900;">&#91;</span>j<span style="color: #339933;">+</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> args<span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span>.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;-d&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> d  <span style="color: #339933;">=</span> <span style="color: #003399;">Double</span>.<span style="color: #006633;">parseDouble</span><span style="color: #009900;">&#40;</span>args<span style="color: #009900;">&#91;</span>j<span style="color: #339933;">+</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> args<span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span>.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;-s&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> s  <span style="color: #339933;">=</span> args<span style="color: #009900;">&#91;</span>j<span style="color: #339933;">+</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span><span style="color: #000000; font-weight: bold;">catch</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Exception</span> e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Usage: getArgs &lt;options&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Options:&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; -i  An Integer Value&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; -d  A Double Value&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; -s  A String Value&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #003399;">System</span>.<span style="color: #006633;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Exit with error code 1</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// Print arguments</span>
        <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Integer &quot;</span> <span style="color: #339933;">+</span> i.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Double  &quot;</span> <span style="color: #339933;">+</span> d.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;String  &quot;</span> <span style="color: #339933;">+</span> s<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>This program has three parameters for an integer, a double and a string. If the value provided is incompatible, the help message is displayed.</p>
<p>Spaces in strings can be handled with backslash escape characters or by enclosing the whole string in quotes.</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">$ java getArgs -i 4 -d 3.14 -s 'Hello World'
Integer 4
Double  3.14
String  Hello World</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.craig-russell.co.uk/command-line-arguments-in-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WordPress Widgets Alpha and Omega Classes</title>
		<link>http://www.craig-russell.co.uk/wordpress-widgets-alpha-and-omega-classes/</link>
		<comments>http://www.craig-russell.co.uk/wordpress-widgets-alpha-and-omega-classes/#comments</comments>
		<pubDate>Wed, 16 Mar 2011 16:05:58 +0000</pubDate>
		<dc:creator>Craig</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.craig-russell.co.uk/?p=769</guid>
		<description><![CDATA[If your using a CSS grid system like the 960 Grid, you’ll recognise the need for styling the first and last column on a row a bit differently from the rest (probably removing some margins or clearing floats). CSS3 lets us do this easily with nth-child. This is great for modern browsers but not so&#8230;]]></description>
			<content:encoded><![CDATA[<p>If your using a CSS grid system like the <a href=”http://960.gs/”>960 Grid</a>, you’ll recognise the need for styling the first and last column on a row a bit differently from the rest (probably removing some margins or clearing floats). CSS3 lets us do this easily with <a href=”http://css-tricks.com/how-nth-child-works/”><code>nth-child</code></a>. This is great for modern browsers but not so hot for sad old ones. To keep the old browsers sweet you’ve probably manually added extra classes to the first and last element on each row. In the 960 Grid (and many others) these classes are usually <code>alpha</code> and <code>omega</code>.</p>
<p>When using a grid based layout for a <a href=”http://wordpress.org/”>WordPress</a> theme that has a horizontal row of widgets (perhaps in the footer) you’ll want to be able to apply <code>alpha</code> and <code>omega</code> classes to the first and last widgets. The problem is that <a href=”http://codex.wordpress.org/Function_Reference/register_sidebar”><code>register_sidebar</code></a> function only allows you to specify classes that are applied to all widgets in the sidebar. Fortunately a <a href=”http://codex.wordpress.org/Plugin_API/Filter_Reference”>filter</a> exists at just the right place to make this happen.</p>
<p><span id="more-769"></span>The WordPress filter <a href=”http://www.theenglishguy.co.uk/2010/02/02/using-dynamic_sidebar_params-in-wordpress-themes/”><code>dynamic_sidebar_params</code></a> (which is oddly undocumented in the Codex) is called before each widget is drawn. It allows you to modify the parameters used to draw the widget, for example adding targeted classes, which is what the function below does.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">add_filter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'dynamic_sidebar_params'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'widget_alpha_omega'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">function</span> widget_alpha_omega<span style="color: #009900;">&#40;</span><span style="color: #000088;">$params</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">/* Get the ids of this sidebar and widget*/</span>
    <span style="color: #000088;">$sidebar</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$params</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'id'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$widget</span>   <span style="color: #339933;">=</span> <span style="color: #000088;">$params</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'widget_id'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">/* Get number of widgets in this sidebar */</span>
    <span style="color: #000088;">$num_widgets</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$params</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'number'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">/* Get data for all registered widgets */</span>
    <span style="color: #000088;">$all_widgets</span> <span style="color: #339933;">=</span> wp_get_sidebars_widgets<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">/* Finish if no widgets set in this sidebar */</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$all_widgets</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$sidebar</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #339933;">!</span><span style="color: #990000;">is_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$all_widgets</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$sidebar</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #b1b100;">return</span> <span style="color: #000088;">$params</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">/* Set alpha class for first widget */</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$all_widgets</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$sidebar</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$widget</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$params</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'before_widget'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'/class=&amp;quot;/'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'class=&amp;quot;alpha '</span><span style="color: #339933;">,</span> <span style="color: #000088;">$params</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'before_widget'</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">/* Set omega class for last widget */</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$all_widgets</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$sidebar</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$num_widgets</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$widget</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$params</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'before_widget'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'/class=&amp;quot;/'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'class=&amp;quot;omega '</span><span style="color: #339933;">,</span> <span style="color: #000088;">$params</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'before_widget'</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">/* Return modified params */</span>   
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$params</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>The function takes an array of parameters as input. This is mostly the parameters defined in <a href=”http://codex.wordpress.org/Function_Reference/register_sidebar”><code>register_sidebar</code></a> (or the defaults) plus a few bits and bobs.</p>
<p>The first thing the filter function does is get the ids of the widget that is being created and the sidebar it is being created in. You could use this information to apply different filters to different sidebars and widgets. I haven’t done that here.</p>
<p>Next it gets the total number of widgets in the sidebar, it’ll need this later. Then it gets an array of all the sidebars and the registered widgets in each. A quick sanity check makes sure that the sidebar actually contains some widgets, before continuing.</p>
<p>Then the <code>before_widget</code> strings are modified to add the <code>alpha</code> and <code>omega</code> classes to the first and last widgets in the sidebar. Note the use of <code>$all_widgets[$sidebar][0]</code> for the first and <code>$all_widgets[$sidebar][$num_widgets-1]</code> for the last.</p>
<p>Finally the modified parameters array is returned back to WordPress.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.craig-russell.co.uk/wordpress-widgets-alpha-and-omega-classes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Refresh Manifest Cache Without .htaccess</title>
		<link>http://www.craig-russell.co.uk/refresh-manifest-cache-without-htaccess/</link>
		<comments>http://www.craig-russell.co.uk/refresh-manifest-cache-without-htaccess/#comments</comments>
		<pubDate>Fri, 04 Feb 2011 14:50:38 +0000</pubDate>
		<dc:creator>Craig</dc:creator>
				<category><![CDATA[Internet]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[WebApps]]></category>

		<guid isPermaLink="false">http://www.craig-russell.co.uk/?p=684</guid>
		<description><![CDATA[Manifest caching is one of the lovely new features of HTML5. It allows you to define a list of files to be cached for off-line access (among other nice features). One of the points to consider when making changes to cached files, is that the browser won&#8217;t know to download the modified file without being&#8230;]]></description>
			<content:encoded><![CDATA[<p>Manifest caching is one of the <a href="http://www.w3.org/TR/offline-webapps/">lovely new features of HTML5</a>. It allows you to define a list of files to be cached for off-line access (among other nice features).</p>
<p>One of the points to consider when making changes to cached files, is that the browser won&#8217;t know to download the modified file without being prompted to re-fetch the manifest file.</p>
<p><a href="http://html5doctor.com/go-offline-with-application-cache/#trigger-refresh">A common workaround</a> is to make some change to the manifest file to force an update, typically using a version number. This works fine in most instances, but Firefox stubbornly ignores this. The usual workaround for Firefox is to set the manifest file to expire by using the following rule in the .htaccess file.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;</span>IfModule mod_expires.c<span style="color: #000000; font-weight: bold;">&gt;</span>
ExpiresActive On
ExpiresByType text<span style="color: #000000; font-weight: bold;">/</span>cache-manifest <span style="color: #ff0000;">&quot;access plus 0 seconds&quot;</span>
<span style="color: #000000; font-weight: bold;">&lt;/</span>IfModule<span style="color: #000000; font-weight: bold;">&gt;</span></pre></td></tr></table></div>

<p>While this works, it&#8217;s not much good if your&#8217;re not using Apache, or if your host has blocked .htaccess usage.</p>
<p>However, you can achieve the same effect by setting the HTTP headers in PHP. Put the following lines in to top of your manifest file, and change the extension to <code>.php</code>.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Content-type: text/cache-manifest&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Cache-Control: no-cache, must-revalidate&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Expires: &quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span>DATE_RFC1123<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>The first line sets the content type to text/cache-manifest, this is a requirement for manifest caching to function. The second tells the browser not to cache the file. And in case the browser ignores that, the third line expires the file immediately.</p>
<p>Now the browser will keep the manifest cache up-to-date, but still cache the files you want.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.craig-russell.co.uk/refresh-manifest-cache-without-htaccess/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Get Twitter API Data in to a PHP Array</title>
		<link>http://www.craig-russell.co.uk/get-twitter-api-data-in-to-a-php-array/</link>
		<comments>http://www.craig-russell.co.uk/get-twitter-api-data-in-to-a-php-array/#comments</comments>
		<pubDate>Tue, 04 Jan 2011 16:12:13 +0000</pubDate>
		<dc:creator>Craig</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.craig-russell.co.uk/?p=656</guid>
		<description><![CDATA[I&#8217;ve been playing around with the Twitter API a bit today. Here&#8217;s a handy little code snippet to get data from the api in to a php array. 1 2 3 4 5 6 &#60;?php ]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been playing around with the <a href="http://dev.twitter.com/doc">Twitter API</a> a bit today.<br />
Here&#8217;s a handy little code snippet to get data from the api in to a php array.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$url</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;http://api.twitter.com/1/statuses/public_timeline.json&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$json</span> <span style="color: #339933;">=</span> <span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #990000;">json_decode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$json</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">print_r</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.craig-russell.co.uk/get-twitter-api-data-in-to-a-php-array/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

