Hello, my name is Kristopher.

I am a web and desktop developer and all-around nice guy.

Let's get in touch...

2

Returning in PostgreSQL

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.
0

A Complete, Polished Look for Gnome

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.

0

What’s in Your Interwebz?

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?

0

WordPress on a BlackBerry

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.

0

Twitter, mobile devices and sessions

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.

0

Failed Kernel Upgrade

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.

0

PostgreSQL 8.3 Permissions in Gentoo

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

0

Upgrading to PostgreSQL 8.3 on Gentoo

Gentoo has taken a long time to unmask PostgreSQL 8.3 in Portage. Currently, the best version you can get is. 8.0.5, which, if you can tell, is pretty far away from 8.3.

This masking is largely due to the painful process of upgrading PostgreSQL (which usually involves dumping all your databases and restoring them afterwards). Here’s what I did to get 8.3 up and running.

First, make sure you backup all your databases:

pg_dumpall > postgres-backup.dump

Run the following commands as root. This will add entries to your /etc/portage/package.keywords file:

echo "dev-db/postgresql-base ~amd64" >> /etc/portage/package.keywords
echo "dev-db/postgresql-server ~amd64" >> /etc/portage/package.keywords
echo "virtual/postgresql-server ~amd64" >> /etc/portage/package.keywords
echo "virtual/postgresql-base ~amd64" >> /etc/portage/package.keywords

Make sure to replace amd64 with your actual architecture.

Now, we’re going to unemerge PostgreSQL so we can emerge the new version:

emerge --unmerge dev-db/postgresql dev-db/libpq

Emerge the new version, configure it, start it, and add it to startup:

emerge virtual/postgresql-base virtual/postgresql-server
emerge --config =dev-db/postgresql-server-8.3.5
/etc/init.d/postgresql-8.3 start
rc-update add postgresql-8.3 default

Make sure to replace the version above with the one you actually installed. Now restore your databases:

psql -U postgres -f postgres-backup.dump template1

And you should be all set.

Helpful Links:

PostgreSQL: Backup and Restore

0

Constraints in Rails Migrations

I decided to try a rails project again… something I do quite frequently after I’ve completely forgotten everything I’ve learned.

One thing I quickly remembered is that there is no easy way in a migration to create constraints, like a foreign key. You have to do some exec silliness with an actual query.

After some quick searching, I found this plugin: http://rubyforge.org/projects/mig-constraints
Continue Reading →

0

Using Flowplayer and ffmpeg to Stream Video

We recently had a client that had a need for hosting and streaming videos from their website. These videos were public domain videos, some found on YouTube, NASA’s website, and other resources, and the client was concerned that the videos might be taken down or moved, so they were insistent on hosting the videos on their site. There was also a desire to not require users to have to install Windows Media Player, Quick Time, Flash to be able to view all videos.

Continue Reading →

Copyright © 2010 — phup 'n stuff | Site design by Trevor Fitzgerald