<?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>hocuspokus &#187; tutorial</title>
	<atom:link href="http://hocuspokus.net/tag/tutorial/feed" rel="self" type="application/rss+xml" />
	<link>http://hocuspokus.net</link>
	<description>the life and times of a code monkey</description>
	<lastBuildDate>Tue, 01 Jun 2010 16:40:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Using PostgreSQL With Ruby on Rails on OS&#160;X</title>
		<link>http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2008%2F11%2Fusing-postgresql-with-ruby-on-rails-on-os-x&amp;seed_title=Using+PostgreSQL+With+Ruby+on+Rails+on+OS%26%23160%3BX</link>
		<comments>http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2008%2F11%2Fusing-postgresql-with-ruby-on-rails-on-os-x&amp;seed_title=Using+PostgreSQL+With+Ruby+on+Rails+on+OS%26%23160%3BX#comments</comments>
		<pubDate>Sun, 16 Nov 2008 15:45:01 +0000</pubDate>
		<dc:creator>Daz</dc:creator>
				<category><![CDATA[postgresql]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[ruby-on-rails]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://hocuspokus.net/?p=274</guid>
		<description><![CDATA[Following on from my last post for getting PostgreSQL up and running nicely on Mac OS X, my next task was getting it playing nicely with ruby on rails - I&#8217;m off on a rails course next week so I&#8217;m &#8230; <a href="http://hocuspokus.net/feeder/?FeederAction=clicked&#38;feed=Articles+%28RSS2%29&#38;seed=http%3A%2F%2Fhocuspokus.net%2F2008%2F11%2Fusing-postgresql-with-ruby-on-rails-on-os-x&#38;seed_title=Using+PostgreSQL+With+Ruby+on+Rails+on+OS%26%23160%3BX">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Following on from my <a href="http://hocuspokus.net/2008/11/16/install-postgresql-on-mac-os-x-leopard/">last post</a> for getting PostgreSQL up and running nicely on Mac OS X, my next task was getting it playing nicely with ruby on rails - I&#8217;m off on a rails course next week so I&#8217;m getting stuff ready. <img src='http://hocuspokus.net/wp-content/plugins/smilies-themer/tango/face-smile.png' alt=':)' class='wp-smiley' /> </p>

<p>It appears that there is currently two/three gem packages for using postgresql with ruby: <code>postgres</code>, <code>ruby-pg</code>, and <code>pg</code> - and from what I can make out, they&#8217;re all maintained by the same team now, (<code>postgres</code> was the original package, but it got abandoned - <code>ruby-pg</code> and <code>pg</code> are the replacements).  As such, i&#8217;ll go with the newer <code>ruby-pg</code> gem&#8230;</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">env</span> <span style="color: #007800;">ARCHFLAGS</span>=<span style="color: #ff0000;">&quot;-arch i386&quot;</span> gem <span style="color: #c20cb9; font-weight: bold;">install</span> \
 ruby-pg <span style="color: #660033;">--</span> \
 <span style="color: #660033;">--with-pgsql-lib</span>=<span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>postgresql83 \
 <span style="color: #660033;">--with-pgsql-include</span>=<span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>include<span style="color: #000000; font-weight: bold;">/</span>postgresql83</pre></div></div>


<p>Then finally, when writing the <code>database.yml</code> entry for connecting to postgresql, we have to define our adapter as follows:</p>


<div class="wp_syntax"><div class="code"><pre class="yaml" style="font-family:monospace;">development:
  adapter: postgresql
  database: test_dev
  encoding: unicode
  host: localhost
  user: XXXXX
  password: XXXXX
  timeout: 5000</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2008%2F11%2Fusing-postgresql-with-ruby-on-rails-on-os-x&amp;seed_title=Using+PostgreSQL+With+Ruby+on+Rails+on+OS%26%23160%3BX/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Install PostgreSQL on Mac OS X&#160;Leopard</title>
		<link>http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2008%2F11%2Finstall-postgresql-on-mac-os-x-leopard&amp;seed_title=Install+PostgreSQL+on+Mac+OS+X%26%23160%3BLeopard</link>
		<comments>http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2008%2F11%2Finstall-postgresql-on-mac-os-x-leopard&amp;seed_title=Install+PostgreSQL+on+Mac+OS+X%26%23160%3BLeopard#comments</comments>
		<pubDate>Sun, 16 Nov 2008 10:57:42 +0000</pubDate>
		<dc:creator>Daz</dc:creator>
				<category><![CDATA[mac]]></category>
		<category><![CDATA[postgresql]]></category>
		<category><![CDATA[datbase]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://hocuspokus.net/?p=248</guid>
		<description><![CDATA[This type of guide is all over the internet, but I&#8217;m too lazy to search for one every time I want to do this. So here&#8217;s a brief overview of how I got PostgreSQL set-up nicely on Mac OS 10.5&#8230; &#8230; <a href="http://hocuspokus.net/feeder/?FeederAction=clicked&#38;feed=Articles+%28RSS2%29&#38;seed=http%3A%2F%2Fhocuspokus.net%2F2008%2F11%2Finstall-postgresql-on-mac-os-x-leopard&#38;seed_title=Install+PostgreSQL+on+Mac+OS+X%26%23160%3BLeopard">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>This type of guide is all over the internet, but I&#8217;m too lazy to search for one every time I want to do this. <img src='http://hocuspokus.net/wp-content/plugins/smilies-themer/tango/face-wink.png' alt=';)' class='wp-smiley' /> So here&#8217;s a brief overview of how I got PostgreSQL set-up nicely on Mac OS 10.5&#8230;</p>

<h4>Setting Up Our Environment</h4>

<p>Using a text editor of your choice, add the following lines to the bottom of the <code>/etc/profile</code> file (you&#8217;ll need to be an administrator to do this):</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># MacPorts</span>
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">PATH</span>=<span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin:<span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>sbin:<span style="color: #007800;">$PATH</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># PostgreSQL</span>
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">PATH</span>=<span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>postgresql83<span style="color: #000000; font-weight: bold;">/</span>bin:<span style="color: #007800;">$PATH</span></pre></div></div>


<p>Now before we move on, make sure that you have <a href="http://www.macports.org/">MacPorts</a> installed.</p>

<p><span id="more-248"></span></p>

<h4>Installing PostgreSQL with MacPorts</h4>

<p>I like MacPorts - it makes installing general Unix packages and keeping them up-to-date a snap.  As such, we&#8217;ll use it to do the heavy lifting for installing PostgreSQL.  Open up a terminal and hit up the following command:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> port <span style="color: #c20cb9; font-weight: bold;">install</span> postgresql83 postgresql83-server</pre></div></div>


<p>Sit back and wait a while&#8230;  That&#8217;s the basic install done.</p>

<p>Now to configure it, do the following:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #660033;">-p</span> <span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>db<span style="color: #000000; font-weight: bold;">/</span>postgresql83<span style="color: #000000; font-weight: bold;">/</span>defaultdb
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">chown</span> postgres:postgres <span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>db<span style="color: #000000; font-weight: bold;">/</span>postgresql83<span style="color: #000000; font-weight: bold;">/</span>defaultdb
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">su</span> postgres <span style="color: #660033;">-c</span> <span style="color: #ff0000;">'/opt/local/lib/postgresql83/bin/initdb -D /opt/local/var/db/postgresql83/defaultdb'</span></pre></div></div>


<p>This installs a default database instance for us to be getting on with.  Next, run this command to get PostgreSQL to start on system boot:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> launchctl load <span style="color: #660033;">-w</span> <span style="color: #000000; font-weight: bold;">/</span>Library<span style="color: #000000; font-weight: bold;">/</span>LaunchDaemons<span style="color: #000000; font-weight: bold;">/</span>org.macports.postgresql83-server.plist</pre></div></div>


<p>Reboot your Mac.</p>

<h4>Creating a User Account and Database</h4>

<p>Once your Mac is back up, we finally need to create an account for us to use (substitute &#8216;daz&#8217; for your username)&#8230;</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">createuser <span style="color: #660033;">--superuser</span> daz <span style="color: #660033;">-U</span> postgres</pre></div></div>


<p>Now a database to play with&#8230;</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">createdb test_db</pre></div></div>


<h4>Admin Your Database with pgAdmin 3</h4>

<p>Download <a href="http://www.pgadmin.org/">pgAdmin</a>, then run the following commands to set up some functions that allows pgAdmin to collect statistics about your databases:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>postgresql83<span style="color: #000000; font-weight: bold;">/</span>contrib<span style="color: #000000; font-weight: bold;">/</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">su</span> postgres <span style="color: #660033;">-c</span> psql <span style="color: #000000; font-weight: bold;">&lt;</span> adminpack.sql</pre></div></div>


<p>That&#8217;s it - job done!<sup id="fnref:1"><a href="#fn:1" rel="footnote">1</a></sup></p>

<div class="footnotes">
<hr />
<ol>

<li id="fn:1">
<p>For notes on making the database accessible over the network, please refer to one of my posts on <a href="http://hocuspokus.net/2008/05/13/install-postgresql-on-ubuntu-804/">PostgreSQL on Ubuntu</a>.&#160;<a href="#fnref:1" rev="footnote">&#8617;</a></p>
</li>

</ol>
</div>
]]></content:encoded>
			<wfw:commentRss>http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2008%2F11%2Finstall-postgresql-on-mac-os-x-leopard&amp;seed_title=Install+PostgreSQL+on+Mac+OS+X%26%23160%3BLeopard/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Sync Your Things Database via&#160;Dropbox</title>
		<link>http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2008%2F11%2Fsync-your-things-database-via-dropbox&amp;seed_title=Sync+Your+Things+Database+via%26%23160%3BDropbox</link>
		<comments>http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2008%2F11%2Fsync-your-things-database-via-dropbox&amp;seed_title=Sync+Your+Things+Database+via%26%23160%3BDropbox#comments</comments>
		<pubDate>Thu, 06 Nov 2008 10:03:09 +0000</pubDate>
		<dc:creator>Daz</dc:creator>
				<category><![CDATA[mac]]></category>
		<category><![CDATA[noteworthy]]></category>
		<category><![CDATA[dropbox]]></category>
		<category><![CDATA[gtd]]></category>
		<category><![CDATA[sync]]></category>
		<category><![CDATA[things]]></category>
		<category><![CDATA[to-do]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://hocuspokus.net/?p=241</guid>
		<description><![CDATA[Dropbox is a great service, I&#8217;m using it happily to keep my files in sync across multiple computers - I&#8217;m even using it to keep all of my passwords in sync, but I&#8217;ve thought of another great use&#8230; How about &#8230; <a href="http://hocuspokus.net/feeder/?FeederAction=clicked&#38;feed=Articles+%28RSS2%29&#38;seed=http%3A%2F%2Fhocuspokus.net%2F2008%2F11%2Fsync-your-things-database-via-dropbox&#38;seed_title=Sync+Your+Things+Database+via%26%23160%3BDropbox">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="https://www.getdropbox.com/">Dropbox</a> is a great service, I&#8217;m using it happily to keep my files in sync across multiple computers - I&#8217;m even using it to keep all of my <a href="http://www.switchersblog.com/2008/10/1password-29-br.html">passwords in sync</a>, but I&#8217;ve thought of another great use&#8230;  How about syncing my <a href="http://culturedcode.com/things/">Things</a> database between my macs (as this is my to-do list manager of choice)?</p>

<p>This is not fully tested yet, (just thought of it this morning) so i&#8217;ll update a bit later and report on as to wether things goes completely mental, but the way I&#8217;ve done this is as follows&#8230;</p>

<p>Make sure Things is completely shut down, then open up a terminal and type in the following commands:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> ~<span style="color: #000000; font-weight: bold;">/</span>Library<span style="color: #000000; font-weight: bold;">/</span>Application\ Support<span style="color: #000000; font-weight: bold;">/</span>Cultured\ Code<span style="color: #000000; font-weight: bold;">/</span></pre></div></div>


<p>This moves us into the correct directory.  First, to be on the safe side - we&#8217;ll take a backup of our files&#8230;</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">cp</span> <span style="color: #660033;">-R</span> Things Things.bak</pre></div></div>


<p>Now just move the Things directory into your dropbox and create a symbolic link in its place.</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">mv</span> Things ~<span style="color: #000000; font-weight: bold;">/</span>Dropbox<span style="color: #000000; font-weight: bold;">/</span>
<span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> ~<span style="color: #000000; font-weight: bold;">/</span>Dropbox<span style="color: #000000; font-weight: bold;">/</span>Things Things</pre></div></div>


<p>Fingers crossed this should have the desired results! <img src='http://hocuspokus.net/wp-content/plugins/smilies-themer/tango/face-smile.png' alt=':)' class='wp-smiley' /> </p>

<p><strong>Update:</strong> It works!!! <img src='http://hocuspokus.net/wp-content/plugins/smilies-themer/tango/face-smile-big.png' alt=':D' class='wp-smiley' />  On the second computer all you need to do to get the ball rolling is to close down Things, open up a terminal and type the following commands:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> ~<span style="color: #000000; font-weight: bold;">/</span>Library<span style="color: #000000; font-weight: bold;">/</span>Application\ Support<span style="color: #000000; font-weight: bold;">/</span>Cultured\ Code<span style="color: #000000; font-weight: bold;">/</span>
<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-rf</span> Things
<span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> ~<span style="color: #000000; font-weight: bold;">/</span>Dropbox<span style="color: #000000; font-weight: bold;">/</span>Things Things</pre></div></div>


<p>Note - my 2nd mac only had a fresh install of Things - <strong>no data</strong>.  I installed it, opened it up (so the initial database was created), then did the above.</p>
]]></content:encoded>
			<wfw:commentRss>http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2008%2F11%2Fsync-your-things-database-via-dropbox&amp;seed_title=Sync+Your+Things+Database+via%26%23160%3BDropbox/feed</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>SSH Shared-Key Setup - SSH Logins Without&#160;Passwords</title>
		<link>http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2008%2F01%2Fssh-shared-key-setup-ssh-logins-without-passwords&amp;seed_title=SSH+Shared-Key+Setup+-+SSH+Logins+Without%26%23160%3BPasswords</link>
		<comments>http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2008%2F01%2Fssh-shared-key-setup-ssh-logins-without-passwords&amp;seed_title=SSH+Shared-Key+Setup+-+SSH+Logins+Without%26%23160%3BPasswords#comments</comments>
		<pubDate>Thu, 10 Jan 2008 17:56:59 +0000</pubDate>
		<dc:creator>Daz</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[command-line]]></category>
		<category><![CDATA[geek]]></category>
		<category><![CDATA[os x]]></category>
		<category><![CDATA[terminal]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://hocuspokus.net/2008/01/10/ssh-shared-key-setup-ssh-logins-without-passwords/</guid>
		<description><![CDATA[SSH is a great tool for remotely accessing another machine, but entering your password every time you log into a remote box can be a pain if you would like to set-up some background scripts to connect to a server &#8230; <a href="http://hocuspokus.net/feeder/?FeederAction=clicked&#38;feed=Articles+%28RSS2%29&#38;seed=http%3A%2F%2Fhocuspokus.net%2F2008%2F01%2Fssh-shared-key-setup-ssh-logins-without-passwords&#38;seed_title=SSH+Shared-Key+Setup+-+SSH+Logins+Without%26%23160%3BPasswords">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>SSH is a great tool for remotely accessing another machine, but entering your password every time you log into a remote box can be a pain if you would like to set-up some background scripts to connect to a server and do something (i.e. a backup script running as a cron job).  Here&#8217;s how I set-up my Mac to be able to log into my server without the need for a password to be entered each time - the instructions should be good for any variant of Unix/Linux, but you need to take into account path names etc. on your machine.</p>

<p><span id="more-97"></span></p>

<p>The first thing we will do is generate a key for the SHH version 1 protocol (just in case you are connecting to an older machine):</p>

<pre><code>ssh-keygen -t rsa1
</code></pre>

<p>SSH-Keygen will respond with something like the following:</p>

<pre><code>Generating public/private rsa1 key pair.
Enter file in which to save the key (/Users/daz/.ssh/identity):
</code></pre>

<p>At this point hit enter then you will be prompted for a passphrase - this is a form of password that will be used to generate your unique keys and can contain any set of characters and spaces - something like <em>&quot;I&#8217;m really liking all of this geeky nonsense!&quot;</em> is a perfectly acceptable passphrase - just whatever you do, don&#8217;t use an empty passphrase.  After entering (and confirming) your passphrase you will get the following output:</p>

<pre><code>Your identification has been saved in /Users/daz/.ssh/identity.
Your public key has been saved in /Users/daz/.ssh/identity.pub.
</code></pre>

<p>This means that our identity keys have been generated.  Now we just need to create a pair of keys for the SSH2 protocol - you can use the same or different passphrases for these keys - it&#8217;s up to you&#8230;</p>

<pre><code>ssh-keygen -t dsa
</code></pre>

<p>Then</p>

<pre><code>ssh-keygen -t rsa
</code></pre>

<p>You should now have three sets of keys in your <code>~/.ssh</code> directory, the ones with the .pub extension are your public keys (what we need to put on your other machines) and the others are your private keys - these must be kept safe!</p>

<p>So, let&#8217;s use <code>scp</code> to copy the files across:</p>

<pre><code>scp ~/.ssh/*.pub daz@MyServer:/home/daz/
</code></pre>

<p>Then log into your server using <code>ssh</code> and issue the following commands:</p>

<pre><code>cat identity.pub &gt;&gt;~/.ssh/authorized_keys
cat id_dsa.pub &gt;&gt;~/.ssh/authorized_keys
cat id_rsa.pub &gt;&gt;~/.ssh/authorized_keys
rm identity.pub id_dsa.pub id_rsa.pub
</code></pre>

<p>This populates the <code>authorized_keys</code> file on our server with the three public keys that we have just transferred and then removes them as they&#8217;re no longer needed here.</p>

<p>That&#8217;s everything done, now all we have to do is log out of our server, and then try and log back in via ssh - a password should no longer be required!<sup id="fnref:1"><a href="#fn:1" rel="footnote">1</a></sup> <img src='http://hocuspokus.net/wp-content/plugins/smilies-themer/tango/face-smile.png' alt=':)' class='wp-smiley' /> </p>

<div class="footnotes">
<hr />
<ol>

<li id="fn:1">
<p>This isn&#8217;t strictly true - on OS X it asks you for the <code>id_rsa</code> passphrase that we established before, you will need to enter this, but you can then have it stored in the keychain for hassle free use from here.&#160;<a href="#fnref:1" rev="footnote">&#8617;</a></p>
</li>

</ol>
</div>
]]></content:encoded>
			<wfw:commentRss>http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2008%2F01%2Fssh-shared-key-setup-ssh-logins-without-passwords&amp;seed_title=SSH+Shared-Key+Setup+-+SSH+Logins+Without%26%23160%3BPasswords/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>A Better Ls for Mac OS&#160;X</title>
		<link>http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2008%2F01%2Fa-better-ls-for-mac-os-x&amp;seed_title=A+Better+Ls+for+Mac+OS%26%23160%3BX</link>
		<comments>http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2008%2F01%2Fa-better-ls-for-mac-os-x&amp;seed_title=A+Better+Ls+for+Mac+OS%26%23160%3BX#comments</comments>
		<pubDate>Fri, 04 Jan 2008 20:34:48 +0000</pubDate>
		<dc:creator>Daz</dc:creator>
				<category><![CDATA[mac]]></category>
		<category><![CDATA[noteworthy]]></category>
		<category><![CDATA[colour scheme]]></category>
		<category><![CDATA[command-line]]></category>
		<category><![CDATA[ego]]></category>
		<category><![CDATA[geek]]></category>
		<category><![CDATA[os x]]></category>
		<category><![CDATA[terminal]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://hocuspokus.net/2008/01/04/a-better-ls-for-mac-os-x/</guid>
		<description><![CDATA[I&#8217;m a bit of a command-line freak and like to spend a fair amount of time with the terminal open&#8230; As such I like to spend a small amount of time getting the terminal set-up nicely. Other than changing the &#8230; <a href="http://hocuspokus.net/feeder/?FeederAction=clicked&#38;feed=Articles+%28RSS2%29&#38;seed=http%3A%2F%2Fhocuspokus.net%2F2008%2F01%2Fa-better-ls-for-mac-os-x&#38;seed_title=A+Better+Ls+for+Mac+OS%26%23160%3BX">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m a bit of a command-line freak and like to spend a fair amount of time with the terminal open&#8230; As such  I like to spend a small amount of time getting the terminal set-up nicely.  Other than changing the default colour scheme and font, one (slightly) more drastic change is to replace the standard implementation of <code>ls</code> for one that is slightly more configurable.</p>

<p>The default <code>ls</code> on OS X comes from BSD and compared to the GNU/Linux alternative is slightly lacking when it comes to comes to changing how things look - so what I like to do is replace it with the GNU <code>ls</code> available in <a href="http://www.macports.org/">MacPorts</a> - this allows me to get a terminal setup like below:</p>

<div style="text-align:center;"><img src="http://hocuspokus.net/wp-content/uploads/2008/01/terminal.png" alt="terminal.png" /></div>

<p><span id="more-96"></span></p>

<p>To get this done is pretty simple, once you have MacPorts set up correctly (if you can type <code>man port</code> and get a manual page you&#8217;re ready), just run the following command:</p>

<pre><code>sudo port install coreutils +with_default_names
</code></pre>

<p>This installs the &#8216;GNU File, Shell, and Text utilities&#8217; which <code>ls</code> is part of - the extra option at the end <code>+with_default_names</code> makes it override (only override - not replace, this is totally removable) the default <code>ls</code> and other tools otherwise they will have a &#8216;g&#8217; prefix - i.e. <code>ls</code> would be <code>gls</code>.</p>

<p>Next we add some extra configuration to our <code>~/.bash_profile</code> file (i&#8217;ll include my MacPorts config in case you get stuck above)&#8230;</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
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># MacPorts</span>
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">PATH</span>=<span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin:<span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>sbin:<span style="color: #007800;">$PATH</span>
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">MANPATH</span>=<span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">man</span>:<span style="color: #007800;">$MANPATH</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Terminal colours (after installing GNU coreutils)</span>
<span style="color: #007800;">NM</span>=<span style="color: #ff0000;">&quot;\[\033[0;38m\]&quot;</span> <span style="color: #666666; font-style: italic;">#means no background and white lines</span>
<span style="color: #007800;">HI</span>=<span style="color: #ff0000;">&quot;\[\033[0;37m\]&quot;</span> <span style="color: #666666; font-style: italic;">#change this for letter colors</span>
<span style="color: #007800;">HII</span>=<span style="color: #ff0000;">&quot;\[\033[0;31m\]&quot;</span> <span style="color: #666666; font-style: italic;">#change this for letter colors</span>
<span style="color: #007800;">SI</span>=<span style="color: #ff0000;">&quot;\[\033[0;33m\]&quot;</span> <span style="color: #666666; font-style: italic;">#this is for the current directory</span>
<span style="color: #007800;">IN</span>=<span style="color: #ff0000;">&quot;\[\033[0m\]&quot;</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">PS1</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$NM</span>[ <span style="color: #007800;">$HI</span>\u <span style="color: #007800;">$HII</span>\h <span style="color: #007800;">$SI</span>\w<span style="color: #007800;">$NM</span> ] <span style="color: #007800;">$IN</span>&quot;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$TERM</span>&quot;</span> <span style="color: #000000; font-weight: bold;">!</span>= <span style="color: #ff0000;">&quot;dumb&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">LS_OPTIONS</span>=<span style="color: #ff0000;">'--color=auto'</span>
    <span style="color: #7a0874; font-weight: bold;">eval</span> <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">dircolors</span> ~<span style="color: #000000; font-weight: bold;">/</span>.dir_colors<span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Useful aliases</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;"><span style="color: #c20cb9; font-weight: bold;">ls</span></span>=<span style="color: #ff0000;">'ls $LS_OPTIONS -hF'</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">ll</span>=<span style="color: #ff0000;">'ls $LS_OPTIONS -lhF'</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">l</span>=<span style="color: #ff0000;">'ls $LS_OPTIONS -lAhF'</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> cd..=<span style="color: #ff0000;">&quot;cd ..&quot;</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">c</span>=<span style="color: #ff0000;">&quot;clear&quot;</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">e</span>=<span style="color: #ff0000;">&quot;exit&quot;</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;"><span style="color: #c20cb9; font-weight: bold;">ssh</span></span>=<span style="color: #ff0000;">&quot;ssh -X&quot;</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> ..=<span style="color: #ff0000;">&quot;cd ..&quot;</span></pre></td></tr></table></div>


<p>Then finally we need to create a file called <code>.dir_colors</code> in our home directory that allows us to configure the colours used by <code>ls</code>:</p>

<pre><code>touch ~/.dir_colors
</code></pre>

<p>Then add the contents of the file here:</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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># Configuration file for dircolors, a utility to help you set the</span>
<span style="color: #666666; font-style: italic;"># LS_COLORS environment variable used by GNU ls with the --color option.</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># The keywords COLOR, OPTIONS, and EIGHTBIT (honored by the</span>
<span style="color: #666666; font-style: italic;"># slackware version of dircolors) are recognized but ignored.</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Below, there should be one TERM entry for each termtype that is colorizable</span>
TERM linux
TERM linux-c
TERM mach-color
TERM console
TERM con132x25
TERM con132x30
TERM con132x43
TERM con132x60
TERM con80x25
TERM con80x28
TERM con80x30
TERM con80x43
TERM con80x50
TERM con80x60
TERM xterm
TERM xterm-color
TERM xterm-debian
TERM rxvt
TERM <span style="color: #c20cb9; font-weight: bold;">screen</span>
TERM screen-w
TERM vt100
&nbsp;
<span style="color: #666666; font-style: italic;"># Below are the color init strings for the basic file types. A color init</span>
<span style="color: #666666; font-style: italic;"># string consists of one or more of the following numeric codes:</span>
<span style="color: #666666; font-style: italic;"># Attribute codes:</span>
<span style="color: #666666; font-style: italic;"># 00=none 01=bold 04=underscore 05=blink 07=reverse 08=concealed</span>
<span style="color: #666666; font-style: italic;"># Text color codes:</span>
<span style="color: #666666; font-style: italic;"># 30=black 31=red 32=green 33=yellow 34=blue 35=magenta 36=cyan 37=white</span>
<span style="color: #666666; font-style: italic;"># Background color codes:</span>
<span style="color: #666666; font-style: italic;"># 40=black 41=red 42=green 43=yellow 44=blue 45=magenta 46=cyan 47=white</span>
NORMAL 00	<span style="color: #666666; font-style: italic;"># global default, although everything should be something.</span>
FILE 00 	<span style="color: #666666; font-style: italic;"># normal file</span>
DIR 01;<span style="color: #000000;">36</span> 	<span style="color: #666666; font-style: italic;"># directory</span>
LINK 01;<span style="color: #000000;">37</span> 	<span style="color: #666666; font-style: italic;"># symbolic link.  (If you set this to 'target' instead of a</span>
           	<span style="color: #666666; font-style: italic;"># numerical value, the color is as for the file pointed to.)</span>
FIFO <span style="color: #000000;">40</span>;<span style="color: #000000;">33</span>	<span style="color: #666666; font-style: italic;"># pipe</span>
SOCK 01;<span style="color: #000000;">35</span>	<span style="color: #666666; font-style: italic;"># socket</span>
DOOR 01;<span style="color: #000000;">35</span>	<span style="color: #666666; font-style: italic;"># door</span>
BLK <span style="color: #000000;">40</span>;<span style="color: #000000;">33</span>;01	<span style="color: #666666; font-style: italic;"># block device driver</span>
CHR <span style="color: #000000;">40</span>;<span style="color: #000000;">33</span>;01 	<span style="color: #666666; font-style: italic;"># character device driver</span>
ORPHAN <span style="color: #000000;">40</span>;<span style="color: #000000;">31</span>;01 <span style="color: #666666; font-style: italic;"># symlink to nonexistent file</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># This is for files with execute permission:</span>
EXEC 01;<span style="color: #000000;">35</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># List any file extensions like '.gz' or '.tar' that you would like ls</span>
<span style="color: #666666; font-style: italic;"># to colorize below. Put the extension, a space, and the color init string.</span>
<span style="color: #666666; font-style: italic;"># (and any comments you want to add after a '#')</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># If you use DOS-style suffixes, you may want to uncomment the following:</span>
<span style="color: #666666; font-style: italic;">#.cmd 01;32 # executables (bright green)</span>
<span style="color: #666666; font-style: italic;">#.exe 01;32</span>
<span style="color: #666666; font-style: italic;">#.com 01;32</span>
<span style="color: #666666; font-style: italic;">#.btm 01;32</span>
<span style="color: #666666; font-style: italic;">#.bat 01;32</span>
&nbsp;
.tar 01;<span style="color: #000000;">31</span> <span style="color: #666666; font-style: italic;"># archives or compressed (bright red)</span>
.tgz 01;<span style="color: #000000;">31</span>
.arj 01;<span style="color: #000000;">31</span>
.taz 01;<span style="color: #000000;">31</span>
.lzh 01;<span style="color: #000000;">31</span>
.zip 01;<span style="color: #000000;">31</span>
.z   01;<span style="color: #000000;">31</span>
.Z   01;<span style="color: #000000;">31</span>
.gz  01;<span style="color: #000000;">31</span>
.bz2 01;<span style="color: #000000;">31</span>
.deb 01;<span style="color: #000000;">31</span>
.rpm 01;<span style="color: #000000;">31</span>
.jar 01;<span style="color: #000000;">31</span>
.dmg 01;<span style="color: #000000;">31</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># image formats</span>
.jpg 01;<span style="color: #000000;">35</span>
.png 01;<span style="color: #000000;">35</span>
.gif 01;<span style="color: #000000;">35</span>
.bmp 01;<span style="color: #000000;">35</span>
.ppm 01;<span style="color: #000000;">35</span>
.tga 01;<span style="color: #000000;">35</span>
.xbm 01;<span style="color: #000000;">35</span>
.xpm 01;<span style="color: #000000;">35</span>
.tif 01;<span style="color: #000000;">35</span>
.png 01;<span style="color: #000000;">35</span>
.mpg 01;<span style="color: #000000;">35</span>
.avi 01;<span style="color: #000000;">35</span>
.fli 01;<span style="color: #000000;">35</span>
.gl 01;<span style="color: #000000;">35</span>
.dl 01;<span style="color: #000000;">35</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># source code files</span>
.pl 00;<span style="color: #000000;">33</span>
.PL 00;<span style="color: #000000;">33</span>
.pm 00;<span style="color: #000000;">33</span>
.tt 00;<span style="color: #000000;">33</span>
.yml 00;<span style="color: #000000;">33</span>
.sql 00;<span style="color: #000000;">33</span>
.html 00;<span style="color: #000000;">33</span>
.css 00;<span style="color: #000000;">33</span>
.js 00;<span style="color: #000000;">33</span></pre></td></tr></table></div>


<p>Finally, all you need to do is close and re-open the Terminal.  Now we should be sorted. <img src='http://hocuspokus.net/wp-content/plugins/smilies-themer/tango/face-smile.png' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2008%2F01%2Fa-better-ls-for-mac-os-x&amp;seed_title=A+Better+Ls+for+Mac+OS%26%23160%3BX/feed</wfw:commentRss>
		<slash:comments>42</slash:comments>
		</item>
		<item>
		<title>CSS Styled&#160;Tables</title>
		<link>http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2007%2F11%2Fcss-styled-tables&amp;seed_title=CSS+Styled%26%23160%3BTables</link>
		<comments>http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2007%2F11%2Fcss-styled-tables&amp;seed_title=CSS+Styled%26%23160%3BTables#comments</comments>
		<pubDate>Sun, 18 Nov 2007 11:42:29 +0000</pubDate>
		<dc:creator>Daz</dc:creator>
				<category><![CDATA[snippets]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://hocuspokus.net/2007/11/18/css-styled-tables/</guid>
		<description><![CDATA[Veerle comes up with another look at styling tables with CSS. A great read. In 2005 I wrote an article about styling a table with CSS. After receiving so many requests I finally decided to give in and write another &#8230; <a href="http://hocuspokus.net/feeder/?FeederAction=clicked&#38;feed=Articles+%28RSS2%29&#38;seed=http%3A%2F%2Fhocuspokus.net%2F2007%2F11%2Fcss-styled-tables&#38;seed_title=CSS+Styled%26%23160%3BTables">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Veerle comes up with another look at styling tables with CSS.  A great read.</p>

<blockquote>
  <p>In 2005 I wrote an article about styling a table with CSS. After receiving so many requests I finally decided to give in and write another tutorial. Seems like a popular topic and an interesting one to share some tricks on how you can nicely style them. This article is about the proper usage of tables, for tabular data. How you can implement them with accessibility in mind and how to make them appealing for the eye using CSS.</p>
</blockquote>

<p><a href="http://veerle.duoh.com/blog/comments/a_css_styled_table_version_2/" class="via">read more</a></p>
]]></content:encoded>
			<wfw:commentRss>http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2007%2F11%2Fcss-styled-tables&amp;seed_title=CSS+Styled%26%23160%3BTables/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Install phpPgAdmin on Ubuntu&#160;7.10</title>
		<link>http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2007%2F11%2Finstall-phppgadmin-on-ubuntu-710&amp;seed_title=Install+phpPgAdmin+on+Ubuntu%26%23160%3B7.10</link>
		<comments>http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2007%2F11%2Finstall-phppgadmin-on-ubuntu-710&amp;seed_title=Install+phpPgAdmin+on+Ubuntu%26%23160%3B7.10#comments</comments>
		<pubDate>Wed, 14 Nov 2007 20:14:32 +0000</pubDate>
		<dc:creator>Daz</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[postgresql]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://hocuspokus.net/2007/11/14/install-phppgadmin-on-ubuntu-710/</guid>
		<description><![CDATA[Update: These instructions have been tested and work fine in the latest version of Ubuntu (8.04, Hardy Heron). phpPgAdmin is a web based GUI for administrating a PostgreSQL database server. Here&#8217;s some quick notes on getting it installed easily on &#8230; <a href="http://hocuspokus.net/feeder/?FeederAction=clicked&#38;feed=Articles+%28RSS2%29&#38;seed=http%3A%2F%2Fhocuspokus.net%2F2007%2F11%2Finstall-phppgadmin-on-ubuntu-710&#38;seed_title=Install+phpPgAdmin+on+Ubuntu%26%23160%3B7.10">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p class="alert"><strong>Update:</strong> These instructions have been tested and work fine in the latest version of Ubuntu (8.04, Hardy Heron).</p>

<p><a href="http://www.phppgadmin.org/">phpPgAdmin</a> is a web based GUI for administrating a <a href="http://www.postgresql.org/">PostgreSQL</a> database server.</p>

<p>Here&#8217;s some quick notes on getting it installed easily on Ubuntu 7.10&#8230;</p>

<p>In the terminal enter the following:</p>

<pre><code>$ sudo apt-get install phppgadmin
</code></pre>

<p>This will set up and install all of the phpPgAdmin packages.  It will also set-up and configure Apache and php5 for you too if you haven&#8217;t installed these already.</p>

<p>Next we need to create a symlink to phpPgAdmin so that Apache can find it:</p>

<pre><code>$ sudo ln -s /etc/phppgadmin/apache.conf /etc/apache2/conf.d/phppgadmin.conf
</code></pre>

<p>Now if you navigate to <a href="http://localhost/phppgadmin">http://localhost/phppgadmin</a> you should be greeted with the phpPgAdmin screen.  If your user account has a PostgreSQL account however, you will be logged in automagically.</p>

<p>Optionally, if you would like to be able to use the phpPgAdmin interface as the default &#8216;postgres&#8217; administration account,<sup id="fnref:1"><a href="#fn:1" rel="footnote">1</a></sup> you will need to do the following<sup id="fnref:2"><a href="#fn:2" rel="footnote">2</a></sup>&#8230;</p>

<pre><code>$ sudo gedit /usr/share/phppgadmin/conf/config.inc.php
</code></pre>

<p>Now find and change the following line</p>

<pre><code>$conf['extra_login_security'] = true;
</code></pre>

<p>to</p>

<pre><code>$conf['extra_login_security'] = false;
</code></pre>

<p>Save and close gedit.  Now all you need to do is restart Apache.</p>

<pre><code>$ sudo /etc/init.d/apache2 reload
</code></pre>

<p>Now if you head on over to <a href="http://localhost/phppgadmin">http://localhost/phppgadmin</a> all should be ready for you.</p>

<div class="footnotes">
<hr />
<ol>

<li id="fn:1">
<p>I am assuming here that you have set-up your PostgreSQL server using my <a href="http://hocuspokus.net/2007/11/05/install-posgresql-on-ubuntu-710/">set-up instructions</a> and therefore have a password protected &#8216;postgres&#8217; account and that logins require passwords.&#160;<a href="#fnref:1" rev="footnote">&#8617;</a></p>
</li>

<li id="fn:2">
<p>Please make sure you have read the above footnote and understand the security implications of allowing this type of access to your database server - if you have not secured your administration accounts, do it now!&#160;<a href="#fnref:2" rev="footnote">&#8617;</a></p>
</li>

</ol>
</div>
]]></content:encoded>
			<wfw:commentRss>http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2007%2F11%2Finstall-phppgadmin-on-ubuntu-710&amp;seed_title=Install+phpPgAdmin+on+Ubuntu%26%23160%3B7.10/feed</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Creating New Accounts in&#160;PostgreSQL</title>
		<link>http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2007%2F11%2Fcreating-new-accounts-in-postgresql&amp;seed_title=Creating+New+Accounts+in%26%23160%3BPostgreSQL</link>
		<comments>http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2007%2F11%2Fcreating-new-accounts-in-postgresql&amp;seed_title=Creating+New+Accounts+in%26%23160%3BPostgreSQL#comments</comments>
		<pubDate>Mon, 05 Nov 2007 20:13:41 +0000</pubDate>
		<dc:creator>Daz</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[postgresql]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://hocuspokus.net/2007/11/05/creating-new-accounts-in-postgresql/</guid>
		<description><![CDATA[Getting a new account set up on PostgreSQL is a simple process&#8230; Create our new user: $ sudo su postgres -c createuser daz Then you have to give this new user role a name (I called it daz), and then &#8230; <a href="http://hocuspokus.net/feeder/?FeederAction=clicked&#38;feed=Articles+%28RSS2%29&#38;seed=http%3A%2F%2Fhocuspokus.net%2F2007%2F11%2Fcreating-new-accounts-in-postgresql&#38;seed_title=Creating+New+Accounts+in%26%23160%3BPostgreSQL">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Getting a new account set up on PostgreSQL is a simple process&#8230;</p>

<p>Create our new user:</p>

<pre><code>$ sudo su postgres -c createuser daz
</code></pre>

<p>Then you have to give this new user role a name (I called it daz), and then say &#8216;y&#8217; to the question &#8220;Shall the new role be a superuser?&#8221; if you want the user to be an administrator.</p>

<p>Give the user a database password (this does not have to be the same as their unix password):</p>

<pre><code>$ sudo su postgres -c psql
postgres=# ALTER USER daz WITH PASSWORD 'mypassword';
postgres=# \q
</code></pre>

<p>Finally, give the new user a database to play with:</p>

<pre><code>$ sudo su postgres -c createdb daz
</code></pre>

<p>Pretty straight forward&#8230; <img src='http://hocuspokus.net/wp-content/plugins/smilies-themer/tango/face-smile.png' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2007%2F11%2Fcreating-new-accounts-in-postgresql&amp;seed_title=Creating+New+Accounts+in%26%23160%3BPostgreSQL/feed</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Install PostgreSQL on Ubuntu&#160;7.10</title>
		<link>http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2007%2F11%2Finstall-postgresql-on-ubuntu-710&amp;seed_title=Install+PostgreSQL+on+Ubuntu%26%23160%3B7.10</link>
		<comments>http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2007%2F11%2Finstall-postgresql-on-ubuntu-710&amp;seed_title=Install+PostgreSQL+on+Ubuntu%26%23160%3B7.10#comments</comments>
		<pubDate>Mon, 05 Nov 2007 18:48:10 +0000</pubDate>
		<dc:creator>Daz</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[noteworthy]]></category>
		<category><![CDATA[postgresql]]></category>
		<category><![CDATA[geek]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://hocuspokus.net/2007/11/05/install-posgresql-on-ubuntu-710/</guid>
		<description><![CDATA[If you are using the latest version of Ubuntu (8.04 - Hardy Heron), you might find these slightly updated instructions useful. This quick walk-through are my notes for installing the PostgreSQL database server and the PgAdmin administration application on Ubuntu &#8230; <a href="http://hocuspokus.net/feeder/?FeederAction=clicked&#38;feed=Articles+%28RSS2%29&#38;seed=http%3A%2F%2Fhocuspokus.net%2F2007%2F11%2Finstall-postgresql-on-ubuntu-710&#38;seed_title=Install+PostgreSQL+on+Ubuntu%26%23160%3B7.10">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p class="alert">If you are using the latest version of Ubuntu (8.04 - Hardy Heron), you might find these <a href="http://hocuspokus.net/2008/05/13/install-postgresql-on-ubuntu-804/">slightly updated instructions</a> useful.</p>

<p>This quick walk-through are my notes for installing the PostgreSQL database server and the PgAdmin administration application on Ubuntu Linux, and also set up the server so it allows access to other PC&#8217;s on your network.</p>

<p>Before we move on, this guide was tested on the current release of Ubuntu Linux, (7.10 - Gutsy Gibbon) and PostgreSQL 8.2, but it should also be applicable to older versions (of Ubuntu and PostgreSQL) and other Debian based distros.</p>

<p><span id="more-57"></span></p>

<p>Right for the basic installation, at the command-line, enter the following commands (or search for the listed packages in synaptic if you prefer that way of working):</p>

<pre><code>$ sudo apt-get install postgresql postgresql-client postgresql-contrib
$ sudo apt-get install pgadmin3
</code></pre>

<p>This installs the database server/client, some extra utility scripts and the pgAdmin GUI application for working with the database.</p>

<p>Now we need to reset the password for the &#8216;postgres&#8217; admin account for the server, so we can use this for all of the system administration tasks. Type the following at the command-line (substitute in the password you want to use for your administrator account):</p>

<pre><code>$ sudo su postgres -c psql template1
template1=# ALTER USER postgres WITH PASSWORD 'password';
template1=# \q
</code></pre>

<p>That alters the password for within the database, now we need to do the same for the unix user &#8216;postgres&#8217;:</p>

<pre><code>$ sudo passwd -d postgres
$ sudo su postgres -c passwd
</code></pre>

<p>Now enter the same password that you used previously.</p>

<p>Then, from here on in we can use both pgAdmin and command-line access (as the postgres user) to run the database server.  But before you jump into pgAdmin we should set-up the PostgreSQL admin pack that enables better logging and monitoring within pgAdmin.  Run the following at the command-line:</p>

<pre><code>$ sudo su postgres -c psql &lt; /usr/share/postgresql/8.2/contrib/adminpack.sql
</code></pre>

<p>Finally, we need to open up the server so that we can access and use it remotely - unless you only want to access the database on the local machine. To do this, first, we need to edit the postgresql.conf file:</p>

<pre><code>$ sudo gedit /etc/postgresql/8.2/main/postgresql.conf
</code></pre>

<p>Now, to edit a couple of lines in the &#8216;Connections and Authentication&#8217; section&#8230;</p>

<p>Change the line:</p>

<pre><code>#listen_addresses = 'localhost'
</code></pre>

<p>to</p>

<pre><code>listen_addresses = '*'
</code></pre>

<p>and also change the line:</p>

<pre><code>#password_encryption = on
</code></pre>

<p>to</p>

<pre><code>password_encryption = on
</code></pre>

<p>Then save the file and close gedit.</p>

<p>Now for the final step, we must define who can access the server. This is all done using the pg_hba.conf file.<sup id="fnref:1"><a href="#fn:1" rel="footnote">1</a></sup></p>

<pre><code>$ sudo gedit /etc/postgresql/8.2/main/pg_hba.conf
</code></pre>

<p>Comment out, or delete the current contents of the file, then add this text to the bottom of the file:</p>

<p><pre># DO NOT DISABLE!</p>

<h1>If you change this first entry you will need to make sure that the</h1>

<h1>database</h1>

<h1>super user can access the database using some other method.</h1>

<h1>Noninteractive</h1>

<h1>access to all databases is required during automatic maintenance</h1>

<h1>(autovacuum, daily cronjob, replication, and similar tasks).</h1>

<p>#</p>

<h1>Database administrative login by UNIX sockets</h1>

<p>local   all         postgres                          ident sameuser</p>

<h1>TYPE  DATABASE    USER        CIDR-ADDRESS          METHOD</h1>

<h1>"local" is for Unix domain socket connections only</h1>

<p>local   all         all                               md5</p>

<h1>IPv4 local connections:</h1>

<p>host    all         all         127.0.0.1/32          md5</p>

<h1>IPv6 local connections:</h1>

<p>host    all         all         ::1/128               md5</p>

<h1>Connections for all PCs on the subnet</h1>

<p>#</p>

<h1>TYPE DATABASE USER IP-ADDRESS IP-MASK METHOD</h1>

<p>host    all         all         [ip address]          [subnet mask]  md5</pre></p>

<p>and in the last line, add in your subnet mask (i.e. 255.255.255.0) and the IP address of the machine that you would like to access your server (i.e. 138.250.192.115). However, if you would like to enable access to a range of IP addresses, just substitute the last number for a zero and all machines within that range will be allowed access (i.e. 138.250.192.0 would allow all machines with an IP address 138.250.192.x to use the database server).</p>

<p>That&#8217;s it, now all you have to do is restart the server:</p>

<pre><code>$ sudo /etc/init.d/postgresql-8.2 restart
</code></pre>

<p>And all should be working.</p>

<div class="footnotes">
<hr />
<ol>

<li id="fn:1">
<p>The following advice can also be given to you (plus you don&#8217;t even need to figure out IP addresses and subnet masks) from the latest versions of pgAdmin (1.6.x).  However, this is not the version that ships with Ubuntu, so i&#8217;ll leave these instructions here.&#160;<a href="#fnref:1" rev="footnote">&#8617;</a></p>
</li>

</ol>
</div>
]]></content:encoded>
			<wfw:commentRss>http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2007%2F11%2Finstall-postgresql-on-ubuntu-710&amp;seed_title=Install+PostgreSQL+on+Ubuntu%26%23160%3B7.10/feed</wfw:commentRss>
		<slash:comments>63</slash:comments>
		</item>
		<item>
		<title>Adding/Deleting Rows in TableKit Tables&#160;Revisited</title>
		<link>http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2007%2F11%2Faddingdeleting-rows-in-tablekit-tables-revisited&amp;seed_title=Adding%2FDeleting+Rows+in+TableKit+Tables%26%23160%3BRevisited</link>
		<comments>http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2007%2F11%2Faddingdeleting-rows-in-tablekit-tables-revisited&amp;seed_title=Adding%2FDeleting+Rows+in+TableKit+Tables%26%23160%3BRevisited#comments</comments>
		<pubDate>Thu, 01 Nov 2007 08:42:51 +0000</pubDate>
		<dc:creator>Daz</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[noteworthy]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[catalyst]]></category>
		<category><![CDATA[geek]]></category>
		<category><![CDATA[prototype]]></category>
		<category><![CDATA[tablekit]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://hocuspokus.net/2007/11/01/addingdeleting-rows-in-tablekit-tables-revisited/</guid>
		<description><![CDATA[TableKit is a great javascript library for making your HTML tables fully editable. However, one problem is that you can&#8217;t add or delete rows from the tables&#8230; I came up with a solution to this not so long ago, but &#8230; <a href="http://hocuspokus.net/feeder/?FeederAction=clicked&#38;feed=Articles+%28RSS2%29&#38;seed=http%3A%2F%2Fhocuspokus.net%2F2007%2F11%2Faddingdeleting-rows-in-tablekit-tables-revisited&#38;seed_title=Adding%2FDeleting+Rows+in+TableKit+Tables%26%23160%3BRevisited">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.millstream.com.au/view/code/tablekit/">TableKit</a> is a great javascript library for making your HTML tables fully editable.  However, one problem is that you can&#8217;t add or delete rows from the tables&#8230;</p>

<p>I came up with a solution to this <a href="http://hocuspokus.net/2007/10/11/adding-deleting-rows-to-tablekit-tables/">not so long ago</a>, but it still had a problem - TableKit caches the tables on loading, so after we update the table body (adding or deleting a row) the sorting and editing of the table is completely screwed! <img src='http://hocuspokus.net/wp-content/plugins/smilies-themer/tango/face-sad.png' alt=':(' class='wp-smiley' />  However, with a little more work, and some help from one of the guys in the office - we&#8217;ve finally got this cracked! <img src='http://hocuspokus.net/wp-content/plugins/smilies-themer/tango/face-smile.png' alt=':)' class='wp-smiley' /> </p>

<p><span id="more-50"></span></p>

<p>The basic idea to the fix is, instead of updating the table body, replace the entire table with a new one and get TableKit to do its stuff on the new table.  Although this is not the ideal solution<sup id="fnref:1"><a href="#fn:1" rel="footnote">1</a></sup> - this <em>does</em> work quite well.  Here&#8217;s the details.<sup id="fnref:2"><a href="#fn:2" rel="footnote">2</a></sup></p>

<p>First, we&#8217;ll update the code from our template file (/root/src/users/list.tt):</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
34
35
36
</pre></td><td class="code"><pre class="html4strict" style="font-family:monospace;">[% META title = 'User List' -%]
&nbsp;
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;users_div&quot;</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">table</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;users&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;sortable resizable editable&quot;</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">thead</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">th</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;id&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;sortfirstasc noedit&quot;</span>&gt;</span>Id<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">th</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">th</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;firstname&quot;</span>&gt;</span>First Name<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">th</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">th</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;lastname&quot;</span>&gt;</span>Last Name<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">th</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">th</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;noedit nocol&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">th</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">thead</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">tfoot</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">th</span>&gt;</span>Id<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">th</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">th</span>&gt;</span>First Name<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">th</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">th</span>&gt;</span>Last Name<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">th</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">th</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;nocol&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">th</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">tfoot</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">tbody</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;user_body&quot;</span>&gt;</span>
    [% FOREACH user IN users -%]
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">tr</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'[% user.id %]'</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;</span>[% user.id %]<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;</span>[% user.firstname %]<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;</span>[% user.lastname %]<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;nocol&quot;</span>&gt;</span>
          <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;delete&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span> <span style="color: #000066;">onclick</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;deleteUser([% user.id %]); return false&quot;</span>&gt;</span>delete<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>
    [% END -%]
    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">tbody</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">table</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">br</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;add&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span> <span style="color: #000066;">onclick</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;addUser(); return false&quot;</span>&gt;</span>add a user<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span></pre></td></tr></table></div>


<p>Then add this javascript code to the bottom of the same file:</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span> charset<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;utf-8&quot;</span><span style="color: #339933;">&gt;</span>
  <span style="color: #003366; font-weight: bold;">var</span> users_table <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> TableKit<span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'users'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
    editAjaxURI<span style="color: #339933;">:</span> <span style="color: #3366CC;">'[% c.uri_for('</span><span style="color: #339933;">/</span>users<span style="color: #339933;">/</span>_update_user<span style="color: #3366CC;">') %]'</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #003366; font-weight: bold;">function</span> addUser<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> timestamp <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Date<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">getTime</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> new_table <span style="color: #339933;">=</span> <span style="color: #3366CC;">'users'</span> <span style="color: #339933;">+</span> timestamp<span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> url <span style="color: #339933;">=</span> <span style="color: #3366CC;">'[% c.uri_for('</span><span style="color: #339933;">/</span>users<span style="color: #339933;">/</span>_add_user<span style="color: #3366CC;">') %]?timestamp='</span> <span style="color: #339933;">+</span> timestamp<span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">new</span> Ajax.<span style="color: #660066;">Updater</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'users_div'</span><span style="color: #339933;">,</span> url<span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span> 
      asynchronous<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span>
      onComplete<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #003366; font-weight: bold;">new</span> TableKit<span style="color: #009900;">&#40;</span> new_table<span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
          editAjaxURI<span style="color: #339933;">:</span> <span style="color: #3366CC;">'[% c.uri_for('</span><span style="color: #339933;">/</span>users<span style="color: #339933;">/</span>_update_user<span style="color: #3366CC;">') %]'</span>
        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
      <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #003366; font-weight: bold;">function</span> deleteUser<span style="color: #009900;">&#40;</span> user_id <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> timestamp <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Date<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">getTime</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> new_table <span style="color: #339933;">=</span> <span style="color: #3366CC;">'users'</span> <span style="color: #339933;">+</span> timestamp<span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> url <span style="color: #339933;">=</span> <span style="color: #3366CC;">'[% c.uri_for('</span><span style="color: #339933;">/</span>users<span style="color: #339933;">/</span>_delete_user<span style="color: #339933;">/</span><span style="color: #3366CC;">') %]?user_id='</span> <span style="color: #339933;">+</span> user_id <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&amp;timestamp='</span> <span style="color: #339933;">+</span> timestamp<span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> answer <span style="color: #339933;">=</span> <span style="color: #000066;">confirm</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Are you sure you want to delete this user?'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>answer<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #003366; font-weight: bold;">new</span> Ajax.<span style="color: #660066;">Updater</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'users_div'</span><span style="color: #339933;">,</span> url<span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span> 
        asynchronous<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span>
        onComplete<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
          <span style="color: #003366; font-weight: bold;">new</span> TableKit<span style="color: #009900;">&#40;</span> new_table<span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
            editAjaxURI<span style="color: #339933;">:</span> <span style="color: #3366CC;">'[% c.uri_for('</span><span style="color: #339933;">/</span>users<span style="color: #339933;">/</span>_update_user<span style="color: #3366CC;">') %]'</span>
          <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#125;</span>
      <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>


<p>The main differences in the above from last time round are as follows:
-   The &#8216;users&#8217; table is now inside a div with the id &#8216;users_div&#8217;
-   The link to add a user now calls a javascript function rather than an   Ajax.Updater call directly.
-   The functions to add and delete users are essentially the same:
- -         They create a timestamp to individually identify the new table we       are going to create (this is <strong>the</strong> most important thing here to       remember)!
- -         They then use an Ajax.Updater call to talk to the Perl controller       and generate the new table with a row added or removed.
- -         Once the Ajax.Updater is complete, TableKit is then called again        to make our new table editable and sortable.</p>

<p>That&#8217;s the template sorted, now let&#8217;s look at the controller (/lib/MyApp/Controller/Users.pm):</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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
</pre></td><td class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #000066;">package</span> MyApp<span style="color: #339933;">::</span><span style="color: #006600;">Controller</span><span style="color: #339933;">::</span><span style="color: #006600;">Users</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">use</span> strict<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> warnings<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> base <span style="color: #ff0000;">'Catalyst::Controller'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">=head1 NAME
&nbsp;
MyApp::Controller::Users - Catalyst Controller
&nbsp;
=head1 DESCRIPTION
&nbsp;
Catalyst Controller.
&nbsp;
=head1 METHODS
&nbsp;
=cut</span>
&nbsp;
<span style="color: #666666; font-style: italic;">=head2 index 
&nbsp;
=cut</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">sub</span> <span style="color: #000066;">index</span> <span style="color: #339933;">:</span> Private <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$self</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$c</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">@_</span><span style="color: #339933;">;</span>
    <span style="color: #0000ff;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">response</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">redirect</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'/users/list'</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;">=head2 list
&nbsp;
Fetch all user objects and pass to users/list.tt in stash to be displayed
&nbsp;
=cut</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">sub</span> list <span style="color: #339933;">:</span> Local <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$self</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$c</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">@_</span><span style="color: #339933;">;</span>
    <span style="color: #0000ff;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">stash</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span>users<span style="color: #009900;">&#125;</span>    <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span> <span style="color: #0000ff;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">model</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'MyAppDB::Users'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">all</span> <span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #0000ff;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">stash</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span>template<span style="color: #009900;">&#125;</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'users/list.tt'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">=head2 _update_user
&nbsp;
Ajax method to update the users table
&nbsp;
=cut</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">sub</span> _update_user <span style="color: #339933;">:</span> Local <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$self</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$c</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">@_</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #0000ff;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">model</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'MyAppDB::Users'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">find</span><span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#123;</span> id <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">req</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">params</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span>id<span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span>
      <span style="color: #339933;">-&gt;</span><span style="color: #006600;">update</span><span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#123;</span> <span style="color: #0000ff;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">req</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">params</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span>field<span style="color: #009900;">&#125;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">req</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">params</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span>value<span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #0000ff;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">res</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">body</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">req</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">params</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span>value<span style="color: #009900;">&#125;</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;">=head2 _delete_user
&nbsp;
Ajax method to delete users from the users table
&nbsp;
=cut</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">sub</span> _delete_user <span style="color: #339933;">:</span> Local <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$self</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$c</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">@_</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;"># Look-up our user entry</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$user</span> <span style="color: #339933;">=</span>
      <span style="color: #0000ff;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">model</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'MyAppDB::Users'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">find</span><span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#123;</span> id <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">req</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">params</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span>user_id<span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span>
      <span style="color: #339933;">-&gt;</span><span style="color: #006600;">delete</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$output</span> <span style="color: #339933;">=</span>
      __return_all_users<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$self</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$c</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">req</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">params</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span>timestamp<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">'null'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #0000ff;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">res</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">body</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$output</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;">=head2 _add_user
&nbsp;
Ajax method to add users to the users table
&nbsp;
=cut</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">sub</span> _add_user <span style="color: #339933;">:</span> Local <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$self</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$c</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">@_</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;"># create a new user...</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$new_user</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">model</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'MyAppDB::Users'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">create</span><span style="color: #009900;">&#40;</span>
        <span style="color: #009900;">&#123;</span>
            id        <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">req</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">params</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span>user_id<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
            firstname <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'[First Name]'</span><span style="color: #339933;">,</span>
            lastname  <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'[Last Name]'</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$output</span> <span style="color: #339933;">=</span> __return_all_users<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$self</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$c</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">req</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">params</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span>timestamp<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">$new_user</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">id</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #0000ff;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">res</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">body</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$output</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;">=head2 __return_all_users
&nbsp;
Private method for the Users ajax interaction.
Returns a html table.
&nbsp;
=cut</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">sub</span> __return_all_users <span style="color: #339933;">:</span> Private <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$self</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$c</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$timestamp</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$new_user_id</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">@_</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">@users</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">model</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'MyAppDB::Users'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">all</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$html</span> <span style="color: #339933;">=</span>
        <span style="color: #ff0000;">'&lt;table id=&quot;users'</span>
      <span style="color: #339933;">.</span> <span style="color: #0000ff;">$timestamp</span>
      <span style="color: #339933;">.</span> <span style="color: #ff0000;">'&quot; class=&quot;sortable resizable editable&quot;&gt;
      &lt;thead&gt;
        &lt;tr&gt;
          &lt;th id=&quot;id&quot; class=&quot;sortfirstasc noedit&quot;&gt;Id&lt;/th&gt;
          &lt;th id=&quot;firstname&quot;&gt;First Name&lt;/th&gt;
          &lt;th id=&quot;lastname&quot;&gt;Last Name&lt;/th&gt;
          &lt;th class=&quot;noedit nocol&quot;&gt;&lt;/th&gt;
        &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tfoot&gt;
        &lt;tr&gt;
          &lt;th&gt;Id&lt;/th&gt;
          &lt;th&gt;First Name&lt;/th&gt;
          &lt;th&gt;Last Name&lt;/th&gt;
          &lt;th class=&quot;nocol&quot;&gt;&lt;/th&gt;
        &lt;/tr&gt;
      &lt;/tfoot&gt;
      &lt;tbody id=&quot;user_body&quot;&gt;'</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #000066;">scalar</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">@users</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span> <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span> <span style="color: #339933;">;</span> <span style="color: #0000ff;">$i</span> <span style="color: #339933;">&lt;</span> <span style="color: #000066;">scalar</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">@users</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">;</span> <span style="color: #0000ff;">$i</span><span style="color: #339933;">++</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$class</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$new_user_id</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #0000ff;">$users</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">id</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">$new_user_id</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #0000ff;">$class</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'new'</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #b1b100;">if</span>   <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$i</span> <span style="color: #339933;">%</span> <span style="color: #cc66cc;">2</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #0000ff;">$class</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'rowodd'</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
                <span style="color: #b1b100;">else</span>                 <span style="color: #009900;">&#123;</span> <span style="color: #0000ff;">$class</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'roweven'</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span>
&nbsp;
            <span style="color: #0000ff;">$html</span> <span style="color: #339933;">.=</span>
                <span style="color: #ff0000;">&quot;&lt;tr class=<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span> 
              <span style="color: #339933;">.</span> <span style="color: #0000ff;">$class</span>
              <span style="color: #339933;">.</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span> id=<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span>
              <span style="color: #339933;">.</span> <span style="color: #0000ff;">$users</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">id</span> <span style="color: #339933;">.</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;
                &lt;td&gt;&quot;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">$users</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">id</span> <span style="color: #339933;">.</span> <span style="color: #ff0000;">&quot;&lt;/td&gt;
                &lt;td&gt;&quot;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">$users</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">firstname</span> <span style="color: #339933;">.</span> <span style="color: #ff0000;">&quot;&lt;/td&gt;
                &lt;td&gt;&quot;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">$users</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">lastname</span> <span style="color: #339933;">.</span> <span style="color: #ff0000;">&quot;&lt;/td&gt;
                &lt;td class=<span style="color: #000099; font-weight: bold;">\&quot;</span>nocol<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;
                    &lt;a class=<span style="color: #000099; font-weight: bold;">\&quot;</span>delete<span style="color: #000099; font-weight: bold;">\&quot;</span> href=<span style="color: #000099; font-weight: bold;">\&quot;</span>#<span style="color: #000099; font-weight: bold;">\&quot;</span> onclick=<span style="color: #000099; font-weight: bold;">\&quot;</span> deleteUser(&quot;</span>
              <span style="color: #339933;">.</span> <span style="color: #0000ff;">$users</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">id</span> <span style="color: #339933;">.</span> <span style="color: #ff0000;">&quot;); return false<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;delete&lt;/a&gt;
                &lt;/td&gt;
              &lt;/tr&gt;&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #0000ff;">$html</span> <span style="color: #339933;">.=</span>
          <span style="color: #ff0000;">'&lt;tr&gt;&lt;td colspan=&quot;4&quot; class=&quot;nocol&quot;&gt;All Users Deleted&lt;/td&gt;&lt;/tr&gt;'</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #0000ff;">$html</span> <span style="color: #339933;">.=</span> <span style="color: #ff0000;">'&lt;/tbody&gt;&lt;/table&gt;'</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000066;">return</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$html</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;">=head1 AUTHOR
&nbsp;
Darren Oakley
&nbsp;
=head1 LICENSE
&nbsp;
This library is free software, you can redistribute it and/or modify
it under the same terms as Perl itself.
&nbsp;
=cut</span>
&nbsp;
<span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span></pre></td></tr></table></div>


<p>The only real changes in the controller are a general code clean-up, and a slight change to the &#8216;__return_all_users&#8217; method - this now returns a whole table (identified by the unique timestamped id that we generated in the javascript functions).  Nothing really needed changing in the back-end.</p>

<p>There you go!  Now our TableKit based tables can be used to not only edit entries in the database, we can now add and remove them! <img src='http://hocuspokus.net/wp-content/plugins/smilies-themer/tango/face-smile.png' alt=':)' class='wp-smiley' /> </p>

<p>The files used in this example can be found below.</p>

<h4>Attached Files:</h4>

<p><a href="http://hocuspokus.net/wp-content/uploads/2007/11/myapp.zip" title="myapp.zip" title="MyApp - v3" class="archive">MyApp.zip - v3</a></p>

<div class="footnotes">
<hr />
<ol>

<li id="fn:1">
<p>That would be knowing more about javascript and the dom so that we can make changes to TableKits cache as we update the table body (thus keeping the original table).&#160;<a href="#fnref:1" rev="footnote">&#8617;</a></p>
</li>

<li id="fn:2">
<p>We&#8217;re using the code from the <a href="http://hocuspokus.net/2007/10/11/adding-deleting-rows-to-tablekit-tables/">previous post</a> as a starting point.&#160;<a href="#fnref:2" rev="footnote">&#8617;</a></p>
</li>

</ol>
</div>
]]></content:encoded>
			<wfw:commentRss>http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2007%2F11%2Faddingdeleting-rows-in-tablekit-tables-revisited&amp;seed_title=Adding%2FDeleting+Rows+in+TableKit+Tables%26%23160%3BRevisited/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->