Hello, my name is Kristopher.

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

Let's get in touch...

0

An Epic Struggle With Portage

Today I embarked on an epic struggle with the Portage package manager attempting to update the packages on my system. After I ran into what can only be described as a phantom package.

Continue Reading →

2

array_to_string in PostgreSQL

This snippet courtesy of Kieran Smith.

Want to get more work done in a single query? Tired of looping through query results to simply build a list of data. How about this?

SELECT
array_to_string(
    ARRAY(
        SELECT name
        FROM projects
        WHERE customer_id = 10
        ORDER BY LOWER(name)
    ), ', '
) AS projects;

What you are doing is building an array from the subquery and then turning it back into a string immediately, so you can display multiple results in a single field. Our results might look something like this:

gnucashweb, Hangar, OpenAvanti, tarmac

Nice!

2

Gentoo Portage Alternative

I just came across an alternative to the http://gentoo-portage.com and http://packages.gentoo.org sites: http://znurt.org/

Nice, clean, beautiful and full of information.

0

The Sluggish Speed of Gentoo

Gentoo, ffs, get PHP 5.3.1 in Portage ASAP. PHP 5.3 isn’t even in there, yet. What’s the use of your package manager if I just have to manually install stuff?

/rant

1

Automatically Setting Modified Date Database Fields

Most of my database tables always have four columns in common:

created_on timestamp
created_by_id int
last_modified_on timestamp
last_modified_by_id int

These columns should be pretty self explanatory. Usually created_on has a default of now() to auto populate it. Populating the last_modified_on column is a little more difficult, especially if you don’t want it to be populated on INSERT (which is what using default now()) would do.

Of course we could just provide for it in our code, especially if using a trusty application framework that takes care of it for us, but I like putting basic logic in the database, and we can’t assume all data updates will come from our application. They could, for example, come from a command line update.

I crafted this quick little database trigger function for taking care of this for me:

CREATE OR REPLACE FUNCTION auto_update_last_modified()
  RETURNS TRIGGER AS
$BODY$
DECLARE
BEGIN
	NEW.last_modified_on:= now();
 
	RETURN NEW;
END;
$BODY$
  LANGUAGE 'plpgsql';

This function simply populates the last_modified_on column of NEW (the new record being updated) with the current timestamp. Now I can add a trigger to every table that has this column:

CREATE TRIGGER auto_update_table_name_last_modified
  BEFORE UPDATE
  ON table_name
  FOR EACH ROW
  EXECUTE PROCEDURE auto_update_last_modified();

And now when updating a record in table_name, it will automatically populate a value for last_modified_on.

2

User Time Zones in PHP

When writing applications that are meant to be used by users the world over (not just users within a localized network), it’s important to be able to show dates and times relative to the users time zone. If one user posts something at 11:30 EST, and a few minutes later, a user in California checks the post, it would look as if it were made in the future. Not cool.

Lucky, it’s quite easy to localize dates and times using PHP’s built in date classes.

Continue Reading →

0

PostgreSQL 8.4.2-r1 on Gentoo

A new version of PostgreSQL, 8.4.2-r1, is available in Gentoo Portage, but be careful. It appears the server is compiled with HAVE_INT64_TIMESTAMP by default, something not true with previous versions. Because of this, after updating, you might get an error about the data cluster being incompatibile with the server when you restart, unless you were using the pg-intdatetime use flag in previous versions (which has been removed in the newest version).

Continue Reading →

1

Inheritance in PostgreSQL

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 →

0

Subversion Commit Logs to Twitter

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.

0

Removing Windows Newline Characters in Vim

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.

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