phup 'n stuff

Another Blog About Being a Developer

Inheritance in PostgreSQL

January 1st, 2010 Filed under Database by Kristopher

Another cool feature I've recently discovered in PostgreSQL, although one available and documented for a long time, is table inheritance, which works almost exactly like object inheritance in object oriented programming. This simply means that you can have tables inheriting columns from parent tables.

Continue Reading »

Subversion Commit Logs to Twitter

December 29th, 2009 Filed under Version Control by Kristopher

Twitvn is a small Python script that, when used as a Subversion post-commit hook, will publish commit messages to a Twitter account: http://code.google.com/p/twitvn/

Why would anyone want to do this?

There are many reasons. It would help foster collaboration on a multi-member project, either allowing them to follow the Twitter account with their own, or via Twitter's RSS feed. It could also allow interested users of the project to follow status updates of what is going on with the project.

Finally, it's just a damn fun idea.

Removing Windows Newline Characters in Vim

December 21st, 2009 Filed under Linux, Programming by Kristopher

Sometimes when working on projects in both Linux and Windows, a file will end up with Windows newline characters, which show up as ^M in Vim. Annoying as this is, there's a quick fix to remove them in Vim using a regular expression replace:

:%s/<control-v><control-m>//g

Magically, all the ugly Windows newline characters are gone.

Returning in PostgreSQL

November 20th, 2009 Filed under Database by Kristopher

I recently came across an amazing feature in PostgreSQL: the RETURNING clause. This clause allows you to return specific data as the result of an INSERT or UPDATE query.

Often, after doing one of these queries, I'm interested in getting some data, such as an autogenerated primary key field, or maybe some defaulted data (like a created timestamp). Normally, one would have to do an additional query to get this data. Using RETURNING, we can do our data manipulation and retrieval in the same query.

Example:

-- Return just the ID:
 
INSERT INTO books(name, author) VALUES('Awesome Book', 'Smart Author') 
    RETURNING book_id;
 
-- Return more than one column:
 
INSERT INTO books(name, author) VALUES ('Sweet Book', 'Other Author') 
    RETURNING book_id, created_on;
 
-- Return all the columns:
 
INSERT INTO books(name, author) VALUES ('Silly Book', 'Airhead Author') 
    RETURNING *;

In our code, we can simply treat the return value of the INSERT or UPDATE code like we would a SELECT statement.

Some things to keep in mind, though:

  1. If the UPDATE query affects multiple rows, multiple rows of data will be returned. If no rows are affected, none will be returned.
  2. Normally the database would return the number of rows affected, but obviously we're overriding the return value of the query. Obviously we can check the number of rows returned by the query (like we would with a SELECT) to get around this.

A Complete, Polished Look for Gnome

September 17th, 2009 Filed under Linux by Kristopher

I'm not afraid to admit it: I'm a fan of Gnome. I think KDE looks to cartoonish. I actually prefer using OpenBox with a slew of lightweight apps for window manager addons, but that because too much to maintain, and I have better things to do with my time.

It's hard to find a nice, clean set of decorations for Gnome that mesh well together. GDM theme, icons, wallpapers, GTK themes, etc that all blend well together to create a complete, polished look.

Recently I found the "Colors" theme set on Gnome Look.

GDM and Wallpapers: http://www.gnome-look.org/content/show.php/Arc-Colors+GDM-Walls?content=88305
GTK: http://www.gnome-look.org/content/show.php/Shiki-Colors?content=86717
Icons: http://www.gnome-look.org/content/show.php/GNOME-colors?content=82562

Nice and simple.

What’s in Your Interwebz?

September 17th, 2009 Filed under WTF by Kristopher

After watching the commercials for a year or so now and being a cardholder for 7 years, I thought I'd try designing my own Capital One credit card. I accidentally closed the browser window while trying to close something else and thought no big deal of it; I'd just reopen it, right? Wrong. I ran into this error message:

Oops…
We're sorry but it looks like you have recently visited the Image Card site. Please close this browser window and return to the original.

If you've already closed the original window, you will need to wait 3 hours before returning to the Image Card site. We're sorry for the inconvenience.

Eh? Wait 3 hours? I thought a simple matter of clearing my cookies would help. Nope. Still get the error.

I have no insight into the Capital One code, but as a web developer, I can really think of no reason one would have to wait 3 hours to use an application. Seriously, just provide a link that clears the session or cached server data. No big deal.

Capital One = FAIL. How about you guys lower my interest rate, too?

Wordpress on a BlackBerry

August 13th, 2009 Filed under Mobile, Wordpress by Kristopher

Installed the Wordpress app for my BlackBerry. While it seems like a fun idea, typing HTML on this tiny, touch screen keyboard is a pain in the ass.

I don't think I'll be doing this often… or ever.

Twitter, mobile devices and sessions

June 15th, 2009 Filed under Mobile by Kristopher

I'm sure I'm probably the only one that has ever run into this, but whenever I'm curious if someone or some organization is on Twitter, instead of searching for them on Twitter, I do a quick Google of +"their name" +twitter.

In my over-excitement of actually finding someone, I quickly click the link, only to find out that it was a link for m.twitter.com, the mobile version of the site. So I get the condensed site. No big deal, just modify the address bar and remove the m, right?

Wrong.

It seems that Twitter stores the fact that you're on a mobile device in the session or in a cookie. Because I still get the mobile site… for every Twitter site I go to.

The only way I've found to reverse this is to delete the cookies for twitter.com.

Ugh, Twitter. UGH.

Failed Kernel Upgrade

March 21st, 2009 Filed under Linux by Kristopher

The other day I upgraded my Gentoo kernel (after realizing I was about 7 kernel updates old). After compiling and setting up Grub, I rebooted and received this error:

RAMDISK: Compressed image found at block 0
RAMDISK: ran out of compressed data
invalid compressed format (err=1)
UDF-fs: No VRS found
List of all partitions:

No file system could mount root, tried: …
Kernel panic - not syncing: VFS: unable to mount root fs on unknown-block(1,0)

After painful research, I finally discovered the problem: I ran out of space on my boot partition.

Apparently genkernel does not complain when it runs out of space to compile the kernel. It just stops and outputs the same message it would it if succeeded.

A "quick" use of parted to allocate more space to the boot partition, and re-compiling the kernel solved the problem. It's just sad that genkernel doesn't bother reporting the fact that it ran out of space.

PostgreSQL 8.3 Permissions in Gentoo

March 7th, 2009 Filed under Linux by Kristopher

PostgreSQL 8.3 in Gentoo now creates the socket in /var/run/postgresql with stricter permissions, meaning that regular users cannot connect to the PostgreSQL server via command line. Emerging this package outputs a message about this that I initially missed when installing:

Please note that the standard location of the socket has changed from /tmp to /var/run/postgresql and you have to be in the 'postgres' group to access the socket.

This means that regular users who need access to the PostgreSQL server need to be added to the postgres group:

gpasswd -a user postgres