Installing DBD::mysql on Mavericks

3 years ago, I posted about getting DBD::mysql to build on OSX 10.6 – it seems the same thing works on Mavericks (10.9) as well!

#   Failed test 'use DBD::mysql;'
#   at t/00base.t line 18.
#     Tried to use 'DBD::mysql'.
#     Error:  Can't load '/Users/simon/.cpan/build/DBD-mysql-4.027-wbgMWL/blib/arch/auto/DBD/mysql/mysql.bundle' for module DBD::mysql: dlopen(/Users/simon/.cpan/build/DBD-mysql-4.027-wbgMWL/blib/arch/auto/DBD/mysql/mysql.bundle, 2): Library not loaded: libmysqlclient.18.dylib
#   Referenced from: /Users/simon/.cpan/build/DBD-mysql-4.027-wbgMWL/blib/arch/auto/DBD/mysql/mysql.bundle
#   Reason: image not found at /System/Library/Perl/5.16/darwin-thread-multi-2level/DynaLoader.pm line 194.
#  at (eval 7) line 2.

The version of MySQL has changed slightly (and hence the path used) but everything else is the same.

$ sudo install_name_tool -id /usr/local/mysql-5.5.30-osx10.6-x86_64/lib/libmysqlclient.18.dylib /usr/local/mysql-5.5.30-osx10.6-x86_64/lib/libmysqlclient.18.dylib

$ otool -D `mdfind libmysqlclient.18.dylib`

cpan2rpm for CentOS 6.5

I’ve been attempting to build all the dependencies for Dancer on CentOS 6.5 and things just kept going wrong. Several of the modules complained about needing perl >= 5.006 even though CentOS 6.5 comes with Perl 5.10.

[mockbuild@build6 ~]$ cpan2rpm Test::Simple

-- cpan2rpm - Ver: 2.028 --
Upgrade check
Fetch: HTTP

-- module: Test::Simple --
Found: Test-Simple-1.001002.tar.gz
At: http://search.cpan.org//CPAN/authors/id/R/RJ/RJBS
Retrieving URL
Metadata retrieval
Tarball extraction: [/home/mockbuild/rpmbuild/SOURCES/Test-Simple-1.001002.tar.gz]
Unable to build module, the following dependencies have failed:
  perl >= 5.006
Stopped at /usr/local/bin/cpan2rpm line 491.

Despite there not being a newer version of cpan2rpm than 2.028 obviously available, there is a development version 2.028_02 which makes it compatible with Perl 5.10.  You have to download it directly from CPAN at http://search.cpan.org/CPAN/authors/id/B/BB/BBB/cpan2rpm-2.028_02.tar.gz and then use cpan2rpm to build it!

[mockbuild@build6 ~]$ cpan2rpm --no-prfx --no-sign ./cpan2rpm-2.028_02.tar.gz

Once it’s built the new cpan2rpm rpm, install it using yum localinstall which will remove the old version at the same time. This new version is able to build the packages for more up to date versions of Test::Simple and URI.

Update: Test::Simple builds but doesn’t pass all the tests, URI is ok.

Extracting ebooks from Apple iBooks for Mavericks

I decided to remove a lot of the read ebooks from my library but wanted to back them up first, especially the ones that weren’t purchased via iTunes. iBooks on Mavericks had “imported” them all from iTunes and as a result I couldn’t just right click on them in iTunes and use Show in Finder.

First step was to locate them – turns out they’re in ~/Library/Containers/com.apple.BKAgentService/Data/Documents/iBooks/Books/

Next problem was that all the files had been renamed from something human readable into a large string of hex characters! The Books.plist file contained a lot of metadata, including the original filename and the current full path of the ebook. I wasn’t about to go renaming them manually so wrote a quick Perl script using Data::Plist::BinaryReader to extract the data structures and print the values for ‘BkDisplayName’ and ‘path’ from each book.

Then I found that although some of them were still .epub files, quite a few had been unpacked into directories containing the epub contents but not with the OEBPS subdirectory.

I wasn’t about to go updating the script to repack all the epubs and just on a whim thought I’d try dragging an ebook out of iBooks onto the desktop.. it worked! The one I had tried was one of the unpacked ebooks but on the desktop was a zipped up epub file. I wish I’d tried dragging them in the first place as it would have saved a lot of hassle!

To back them up, I ended up simply selecting all the ebooks and dragging them to a separate folder. Now I can remove all the read ebooks from within iBooks without worrying about losing them.

cpan2rpm on CentOS 6.4

I’ve just been building up a new server with CentOS 6.4 and noticed that cpan2rpm wouldn’t work for some Perl modules. The error you get is as follows.

Metadata retrieval
Can't locate object method "interpolate" via package "Pod::Text" at
/usr/bin/cpan2rpm line 522.

Turns out it’s because Pod::Text changed between the version that comes with CentOS 5 (2.21) and the version with CentOS 6 (3.13) and the interpolate method disappeared.

I found a patch attached to this ticket and when applied to cpan2rpm, it works once more. https://rt.cpan.org/Public/Bug/Display.html?id=27309#txn-323456

DigitalOcean – first impressions

A couple of friends mentioned they were having a look at http://www.digitalocean.com/ as a VPS provider so I thought I’d take a quick look myself.

The signup process is painless, just an email address and a password required and you’re into a control panel that is relatively uncluttered. Just a few important options down the left side and as you click each one, the top right has a large button with what appears to be the most commonly selected option. For example, click “Billing” reveals “Manage Payments”, “Droplets” (their name for a VPS) results in a “Create” button and “Support” gives “New Ticket”.

There is plenty of space around the various options so no danger of accidentally clicking the wrong button and most of the icons have a tooltip pop up to say what they are (although it’s generally fairly obvious anyway).

There’s a well documented API available – just a couple of clicks to create an API key and you can do anything from create a new droplet to add a domain to their DNS. All the API functionality can be accessed from simple HTTP GET requests and results are JSON formatted so you could easily write a Javascript page to perform sequences of the common actions.

Support tickets get a fast response and there’s an active IRC channel (#digitalocean on Freenode) with plenty of helpful people and even some DigitalOcean staff.

Creation of a droplet takes just a couple of minutes. It says less than 55 seconds, but it took just over 2 minutes for mine – I guess there’s a certain amount of dependency on the load of the host servers. If you upload an SSH public key, it can be pre-installed on the server.

The billing is hourly and you can put some credit on your account with PayPal or add a credit card and then just create/destroy droplets as required. The control panel has a clear amount that the current month has cost you and it’s possible to create a snapshot, destroy the droplet and not incur any more costs until you restore the snapshot to a new droplet (this is apparently changing and snapshots will cost a small amount per month).

A couple of things I’ve noticed so far that aren’t so good:

They have datacentres in three locations: NYC (North Bergen, NJ), San Francisco, and Amsterdam, but only San Francisco is available for new droplets at present due to capacity issues in NYC and Amsterdam. This is supposed to be resolved soon and it’s possible to move droplets between locations by creating a snapshot and then recreating a droplet at the new location from the snapshot. I would imagine there will be limitations such as IP address changes and some downtime whilst the snapshot is made.

I created a CentOS 6.4 droplet and upgraded all the packages – when it rebooted, the kernel was still using an older one and not the one that just got installed. It turns out that you can’t boot a custom kernel, although there is a selection to choose from within the control panel (just not the most recent CentOS kernel).

Overall though, quite a nice system and not a bad price either!

DBIx::Class default column value

Having read the docs for DBIx::Class::Row new() and DBIx::Class::ResultSource add_columns() it’s hard to know whether it’s better to (a) override new() for the Result module and set a default value in the method params, or (b) use default_value in the add_columns method and set the default within the database itself.

After some investigation, (b) requires fetching the row after creating it just in case there’s a default value being added by the database. Since I already had a custom new() method to validate one of the parameters anyway, I decided to go for option (a) and add a simple check to new()

$args->{ column_name } = $default unless exists $args->{ column_name };

DBD::mysql, MySQL and OS X Lion

I downloaded and installed MySQL Community Server 5.5.15 from http://dev.mysql.com/downloads/mysql/5.5.html

Using CPAN, I then tried to install DBD::mysql on a fresh install of OS X Lion and was presented with an error saying it was unable to load the library.

#     Error:  Can’t load ‘/private/var/root/.cpan/build/DBD-mysql-4.019-H1RD6j/blib/arch/auto/DBD/mysql/mysql.bundle’ for module DBD::mysql: dlopen(/private/var/root/.cpan/build/DBD-mysql-4.019-H1RD6j/blib/arch/auto/DBD/mysql/mysql.bundle, 2): Library not loaded: libmysqlclient.18.dylib
#   Referenced from: /private/var/root/.cpan/build/DBD-mysql-4.019-H1RD6j/blib/arch/auto/DBD/mysql/mysql.bundle

Continue reading DBD::mysql, MySQL and OS X Lion

Shartak internals – speech and translation

Within Shartak there are two main factions – natives and outsiders. To make things somewhat realistic (and interesting), when they first start off there is quite a hefty language barrier in that a native can’t really understand an outsider and vice-versa. This situation can be improved by gaining the various language skills that help with reading/hearing the other language, and then for writing or speaking the other language.

There are three levels of comprehension – basic, advanced and expert language – followed by foreign writing and foreign speech. As far as the translation of language goes, we’re only interested in the first three skills. The foreign writing/speech skills simply allow things to work in reverse.

One of the players posted the results of a fairly detailed examination of the translation system on the Shartak forum and he was quite accurate with a some of the information. It’s not possible to accurately translate the garbled text back into the original text – this is intentional because otherwise it would only be a matter of time before someone wrote a Greasemonkey script to translate it and thus render 5 skills completely useless.

Both native and outsider speech work in the same way, all that changes are the character sequences associated with each letter. The sequences were deliberately chosen (with assistance from someone who knows about such things) such that the outsiders have a less harsh sound than the natives.

Natives have sounds like kam, rak, hok and uck where outsiders have kar, rar, hum and uh.

Trivia: the name of the cannibals home camp Rakmogak is actually a slight variation of the native translation of “Raw meat”!

Shartak internals – Maps and movement

The map for Shartak is held in a database table with over 140,000 rows in it. Each row corresponds to a single location on the map, also called a tile. The initial island map was generated automatically based on a simple bitmap image with varying colours for the different terrain types. Since 2005 there have been many changes to it, most of which are done by manually editing the table one row at a time. Bear in mind that this system is probably not the best way to do it, but it works for Shartak and allows for some interesting map layouts if I ever need them.

Continue reading Shartak internals – Maps and movement