Tidbits

Things I have found myself repeating, and other ramblings.

GitHub With Multiple Accounts

When you need to work with more than one account on GitHub you’ll need to get a little creative. This situation usually arises when you want to keep your personal account separate from your work account. The process is fairly straightforward and involves exercising SSH.

So, given that your existing SSH keys are your personal ones we’ll make the second set for work.

Create a New SSH Key

Create a new SSH key to use for the work account

  • You can also use -t dsa, if you do, replace all references to rsa with dsa.
  • Be careful NOT to overwrite your existing SSH key. Give this new key a unique name, e.g. ~/.ssh/id_rsa_WORK.
1
$ ssh-keygen -t rsa -C "your-email-address"

Add a new SSH key entry to your GitHub account by copying and pasting the contents of ~/.ssh/id_rsa_WORK.pub into the SSH key field of your account.

If you are running an authentication agent you will need to add this new SSH key to it.

1
$ ssh-add ~/.ssh/id_rsa_WORK

Edit the SSH Config File

If you do not already have the file ~/.ssh/config create it and add something similar to the following

1
2
3
4
5
6
7
8
9
10
11
# Personal
Host github.com
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_rsa

# Work
Host github-WORK
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_rsa_WORK

Sample Usage

In a nutshell, use the Host entry in your SSH commands instead of the actual host and SSH will use the correct information. For example, the following will use the new identity key.

1
$ git clone git@github-WORK:<account>/<repo>.git

Memcached Debugging

Here is a useful PHP tool for debugging Memcached. You will need this file – memcache.php.

Mac

Setup

If you do not have Apache running see the post Enable Apache on a Mac. Alternatively, try MAMP – adjust paths as necessary.

1
2
3
4
5
$ cd ~/
$ mkdir Sites
# move memcache.php to ~/Sites/
$ cd /etc/apache2
$ sudo vi httpd.conf

Search for ‘php’ – this line specifically

1
#LoadModule php5_module libexec/apache2/libphp5.so

Uncomment it (remove the leading ‘#’) and save file.

Put memcache.php in ~/Sites/. To hit it

1
http://localhost/~<username>/memcache.php

memcache.php has a username/password setup

1
2
username: memcache
password: password

Windows

If on Windows and not running Apache take a look at WAMP. In either case drop the PHP file in the appropriate place.

Telnet Debugging

For telnet to memcached

1
$ telnet localhost 11211

Quick overview of the most useful telnet commands

1
2
3
4
5
> stats #lists a bunch-o-stuff
> stats items #lists the slabs, example output. STAT items:3:number 1
#list the items in slab id 3 up to 100 items (doesn't seem to work if you leave off the last number, although it can be any number)
> stats cachedump 3 100
> version #version of memcached

SVN to Git Migration

This is the process to migrate an SVN repository to a Git repository. Adjust paths to your particular scenario.

Create a Git repository, but do not add anything to it. It must be bare. For example, if on GitHub do NOT add any ignore or readme files.

It is IMPORTANT that you do NOT go through the steps to clone the newly created repository or add anything to it. We are going to import the migrated SVN repository into it.

Now we need the SVN authors in nice Git format – store for safekeeping as it will be used later

1
2
$ cd /path/to/svn/repo
$ svn log --quiet | grep -E "r[0-9]+ \| .+ \|" | awk '{print $3}' | sort | uniq > authors.txt

To cover scenarios ambiguous scenarios add a ‘no author’ with an email of your choosing.

Somewhere safe make a temporary working area

1
$ mkdir temp && cd temp

Pre-prep the SVN repository (locally), this has some additional options as an example

1
2
$ cd /somewhere/safe/temp
$ git svn clone https://svn.example.com/svn/path/to/repo -A ~/authors.txt --no-metadata --stdlayout --no-minimize-url --ignore-paths="^branches" --tags="tags/releases" --tags="tags/ci-builds"

Create a bare Git repository

1
2
3
4
5
$ cd /somewhere/safe/temp
# if already in the temp dir you can just use 'baremig.git'
$ git init --bare /somewhere/safe/temp/baremig.git
$ cd temp/baremig.git
$ git symbolic-ref HEAD refs/heads/trunk

Push the pre-prep SVN repository to the newly created baremig.git

1
2
3
4
$ cd /somewhere/safe/temp/OHS
$ git remote add bare /somewhere/safe/temp/baremig.git
$ git config remote.bare.push 'refs/remotes/*:refs/heads/*'
$ git push bare

Rename ‘trunk’ to ‘master’

1
2
$ cd /somewhere/safe/temp/baremig.git
$ git branch -m trunk master

Migrate the SVN tags

1
2
$ cd /path/to/temp/new-bare.git
$ git for-each-ref --format='%(refname)' refs/heads/tags | cut -d / -f 4 | while read ref; do git tag "$ref" "refs/heads/tags/$ref"; git branch -D "tags/$ref"; done

Push the bare repository

1
2
3
$ cd /somewhere/safe/temp/baremig.git
$ git remote add origin ssh://git@github.com/<name>/<repo>.git
$ git push -u origin --all

If the SSH ‘git remote add’ command does not work, try this one

$ git remote add origin git@github.com:<username>/<repo>.git

Push the tags to

1
$ git push --tags

Now go check it out. Once verified you can delete the local temp directory you worked from.

Tips, Tricks and Hints

SVN Command Line Error

If using the latest Xcode (version 4.6.2) and command line tools (/usr/bin/svn) with a Subversion version of 1.6.18 and you receive errors trying to check out the SVN repository

  • Go to Homebrew and install Subversion – use this svn (/usr/local/svn) instead of /usr/bin/svn – that is make sure /usr/local/bin comes before /usr/bin in your PATH

Git SVN Command Line Error

When running the ‘git svn’ command and it errors out immediately you probably have to update the Perl SVN::Core CPAN module

  • It will create ~/.cpan as root which can then chwon -R once done (I think it’s OK to remove it, though, but probably best to wait until everything is completed)
1
$ sudo cpan SVN::Core

HyperSQL Debugging

This is one manner in which to debug HyperSQL, there are others, but this is probably the most straightforward. Since HyperSQL runs in memory you must be in debug mode with a breakpoint set in your application.

The breakpoint MUST BE configured to just stop the current thread, otherwise the HyperSQL browser will lock up since all threads will be stopped.

  • Set a breakpoint in your application – make sure it is right after where you want to examine data
  • Bring up the code evaluation window for your IDE
    • Eclipse: Display Mode
    • IntelliJ: Evaluate Expression | Code Fragment Evaluation
  • Paste in one of the following and evaluate (the Swing one has a nicer UI)
    • You can also paste one of these directly into your test class, e.g. in a before method, a test method, etc, but that may mess things up for others if you commit the code
1
2
3
org.hsqldb.util.DatabaseManagerSwing.main(new String[] {
    "--url",  "jdbc:hsqldb:mem:testdb", "--noexit"
});
1
2
3
org.hsqldb.util.DatabaseManager.main(new String[] {
    "--url",  "jdbc:hsqldb:mem:testdb", "--noexit"
});

As long as you are stopped at the breakpoint the DB browser will remain. You can continue to other breakpoints, but if you reach the end of the debug session the DB browser will exit.

One alternative is to run HyperSQL in server mode, you’ll still need to be in debug mode with a breakpoint in your application, but the advantage is you can use your DB client of preference to attach to HyperSQL. The connection string would look something like this (adjust accordingly)

1
jdbc.url=jdbc:hsqldb:mem:testdb;sql.enforce_strict_size=true

Prevent Desktop From Reverting to Default Images After a Mac Restart

If your Mac reverts your desktop images back to the defaults after a restart try the following

1
2
3
$ rm -rf ~/Library/Preferences/com.apple.desktop.plist
# This file may or maynot exist
$ rm -rf ~/Library/Preferences/com.apple.desktop.plist.lockfile

Reboot. The desktop images will be the default, so go ahead and reset them to what you want. Restart and they should remain.

Enable Apache on a Mac

Create the Apache conf file for your user

1
$ sudo cat > /etc/apache2/users/`whoami`.conf

Add the following to that file (change <username> to your Mac’s username)

1
2
3
4
5
6
<Directory "/Users/<username>/Sites/">
     Options Indexes MultiViews
     AllowOverride All
     Order allow,deny
     Allow from all
</Directory>

Complete the setup (this is where your sites will go)

1
$ mkdir ~/Sites

Start Apache

1
$ sudo /usr/sbin/apachectl start

This will also setup Apache to relaunch on system restarts.

To stop Apache, as well as disabling it for relaunch on system restarts,

1
$ sudo /usr/sbin/apachectl stop

To restart a running Apache

1
$ sudo /usr/sbin/apachectl restart

Access your sites as

1
http://localhost/~<username>/