Fill Database with ActiveRecord

Rails ActiveRecord is a quite powerfull tool even without Rails itself. Since it gets all the needed information from the Database it can actually be used for all kinds of operations on the Database itself via scripting. In a current project there was the need to generate a lot of data on a table to use for testing, since the table was modified during the testing it made sense to write a script which auto generates the data based on the current table configuration.

This can be achieved by leveraging ActiveRecord, like this

https://gist.github.com/3017432.js?file=argen.rb

This can be expanded to all kinds of SQL types by extending the mapping hash, as well as the needed data generate methods. By doing so it can incoperate also database specific types like hashes by identifying the via their characteristic SQL type, i.e. md5 hash is char(40).

WordPress Plugin: WordPress Page Contact

Since WordPress does not provide any kind of author widget to go along with a post or page I decided to roll my own. I feel like it’s a nice thing to get the contact details for a person responsible for a specific section of the page right on this page, and a widget seemed like a perfect fit, so this is how WordPress Page Contact came into being, as my first listed WordPress plugin.

The structure is rather simple: create a database of contacts and associate them to a page or post via postmeta, which can be retrieved easily upon display. Rollup the information in a widget to display in the sidebar for any given entry and here we go.

Since I didn’t find anything similar I decided apply for it to be listed in the Plugin index so here we are. You can find it as WordPress Page Contact.

Enjoy!

MySQL Gem 2.8.1 on MacOSX Lion

Just because I keep googling it:

To install MySQL 2.8.1 on OS X Lion

1.

export DYLD_LIBRARY_PATH="/usr/local/mysql/lib:$DYLD_LIBRARY_PATH"

2.

env ARCHFLAGS="-arch x86_64" sudo gem install mysql -v='2.8.1' -- --with-mysql-dir=/usr/local/mysql --with-mysql-lib=/usr/local/mysql/lib --with-mysql-include=/usr/local/mysql/include --with-mysql-config=/usr/local/mysql/bin/mysql_config

Thanks Stackoverflow

Give me my $_POST, or a JSON helper for CodeIgniter

In a current Project I’ve been working with a Cappucino frontend and a CodeIgniter Backend. Since Cappucino just loves JSON I decided this is the way to go, sadly PHP doesn’t provide a standard way to interact with a JSON POST but with a little helper this can be solved easily. I made a Gist out of it so it can be improved apon and reused.

https://gist.github.com/1826959.js