Xbox Gamertag API

Following in the footsteps of [Duncan Mackenzie](http://duncanmackenzie.net/) and his [REST API for Xbox Gamertag Data](http://duncanmackenzie.net/Blog/put-up-a-rest-api-for-xbox-gamertag-data) I’ve written an API of my own to replace his since he shut it down.

It is available at [xbox.samuel.kadolph.com](http://xbox.samuel.kadolph.com/).

Since I never used his API I cannot compare mine to his so if you have any suggestions let me know.

Addendum: mysql2 ruby gem and Mac OS X: image not found

Back at the start of April I wrote [mysql2 ruby gem and Mac OS X: image not found](http://samuel.kadolph.com/2011/04/mysql2-gem-and-mac-os-x-image-not-found/) to deal with the extremely relative path to `libmysqlclient.16.dylib`. I had said I would prefer not putting `libmysqlclient.16.dylib` in `/usr/lib` but I couldn’t find a dylib path that ruby uses. That is until today when I decided to try again.

I found `libexecdir` in `RbConfig::CONFIG` which is the directory where ruby can load dylib files from.

libexecdir=$(ruby -rrbconfig -e ‘puts RbConfig::CONFIG[“libexecdir”]’)
sudo mkdir -p $libexecdir
sudo ln -s /usr/local/mysql/lib/libmysqlclient.16.dylib $libexecdir

Now ruby can load `libmysqlclient.16.dylib` without putting it in `/usr/lib`.

I forgot to mention it in the first post but if your ruby wants `libmysqlclient.18.dylib`, just replace the 16 with 18. Same with any other number.

mysql2 ruby gem and Mac OS X: image not found

If you are using the mysql2 ruby gem on Mac OS X you may have run into this problem before.

> require ‘mysql2’
LoadError: dlopen(mysql2-0.2.7/lib/mysql2/mysql2.bundle, 9):
Library not loaded: libmysqlclient.16.dylib
Referenced from: mysql2-0.2.7/lib/mysql2/mysql2.bundle
Reason: image not found – mysql2-0.2.7/lib/mysql2/mysql2.bundle

So far the only [solution I have found online](http://freddyandersen.wordpress.com/2010/10/03/mysql-5-5-snow-leopard-and-rails/) is to use [`install_name_tool`](http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man1/install_name_tool.1.html) to update the (extremely) relative `libmysqlclient.16.dylib` reference to be absolute (usually to `/usr/local/mysql/lib/libmysqlclient.16.dylib`).

While this solves the problem, it only works until you reinstall the mysql2 gem or install a newer version and then you have to do it again. To permanently solve it you need to create a [symlink](http://en.wikipedia.org/wiki/Symbolic_link) of `libmysqlclient.16.dylib` to `/usr/lib` so that it can be found with that default relative path.

Ideally you wouldn’t put it in `/usr/lib` but I haven’t be able to find a path inside of ruby that will let you load the `dylib`.

sudo ln -s /usr/local/mysql/lib/libmysqlclient.16.dylib /usr/lib

Enter your password and then you can use the `mysql2` gem without needing to edit the compiled bundle afterwards.

Store your git https passwords in your OS X Keychain

Around this time last year [git added a “smart” HTTP transport](http://progit.org/2010/03/04/smart-http.html) that is faster than the old HTTP transport (and in some cases faster than SSH too). And a few months later [GitHub added support for this new HTTP transport](https://github.com/blog/642-smart-http-support) and made it the default selected url for repositories (that you aren’t a contributor for).

There aren’t any major advantages using https over ssh to access your GitHub repositories, it’s just more simple to use your username/password instead of adding your ssh key. The only other advantages is that it’s easier to set up HTTP proxy for git (`git config –global http.proxy proxy:8080` vs ssh config) and being able to use more than one GitHub account (which you shouldn’t since anyone can add you as a contributor to a project).

One major disadvantage is that it asks you for your username/password each time you interact with your remote repository (clone, pull, push, etc). To solve this, I decided to write a program that stores your username and/or password in your keychain so git will ask once for you username/password and retrieve it later so you don’t have to type it again. [If you only want the program, skip to it.](http://samuel.kadolph.com/2011/03/store-your-git-https-passwords-in-your-os-x-keychain/#program)

Continue reading “Store your git https passwords in your OS X Keychain”

Using ‘using’ with Phidget’s C# Library

The [`using`](http://msdn.microsoft.com/en-us/library/yh598w02.aspx) statement is an extremely useful feature of C# and it’s quite disappointing that Phidgets did not implement [`IDisposable`](http://msdn.microsoft.com/en-us/library/system.idisposable.aspx). Thankfully it’s fairly easy to create a wrapper for any Phidget that implements it so we can simply some code.

Continue reading “Using ‘using’ with Phidget’s C# Library”

Missing Namespaces on PhidgetSBC2’s Mono

Since we cannot install `mono-complete` on the PhidgetSBC2 currently, we are missing some of the C# namespaces. If you are trying to use any of the following namespaces and `gmcs` cannot find it, you will have to install the respective package.

Namespace Package
Mono.Data libmono-data2.0-cil
System.Data libmono-system-data2.0-cil
System.Data.Linq libmono-system-data-linq2.0-cil
System.DirectoryServices libmono-system-ldap2.0-cil
System.Messaging libmono-system-messaging2.0-cil
System.Runtime libmono-system-runtime2.0-cil
System.Web libmono-system-web2.0-cil
System.Web.Mvc libmono-system-web-mvc2.0-cil

Using Mono on the PhidgetSBC2

So this Monday my [PhidgetSBC2](http://www.phidgets.com/products.php?category=21&product_id=1072) arrived and I was super excited to get started playing around with the short-term goal of [being able to open my door lock remotely](http://lifehacker.com/5734528/hack-your-door-to-lock-and-unlock-via-text-message).

I really wanted to write the code in C# because it’s simply better than Java and it’s lot easier to implement a server in C# than in C. While the [manual for the SBC2][manual] says you can get Mono working if you install the correct packages, I couldn’t find any information on the Phidget website on how to do it, so I had to figure it out myself.

Continue reading “Using Mono on the PhidgetSBC2”

Playing with FormBuilder

The methods that come with the standard ActionPack::Helpers::FormBuilder cover most cases of what you need to do but if you need to do something it doesn’t have a method for, things can get a little ugly.

In my case I wanted to create a helper for autocompleted fields that all had the same attributes but different arguments (the urls).

So let’s say you have an Unobtrusive JavaScript file that looks for an attribute called data-autocomplete, normally when you wanted to have the field autocompleted, you would pass in the attribute to the form helper text_field.

f.text_field :username, :'data-autocomplete' => users_path(:json)

While there is nothing bad about doing this, you end with a bunch of :'data-autocomplete' scattered about in your views which makes it harder to change down the road if you were to switch your JS implementation.

A nicer way is to have your own form builder method called autocomplete_field which requires two arguments (method and url) that adds the :'data-autocomplete' option (which is now in one place and easily changed) for you. Best part is this can be done with only one helper file.

Continue reading “Playing with FormBuilder”