Tuesday, March 26, 2013

Create Remote Git Repository From Existing Local Repository

I ran across a situation where I needed source control in the absence of a TFS. So off to my favorite DVCS, Git. It worked great except I want to have a backup off of my computer. I know that Git can have remote repositories and I know how to pull from them, however I had never had to create a new remote repository on a network share from the a local repository. Below how I did it...

First, create the directory where the new repositorty will be created, then create a bare Git repository.
$ cd /n/Home
$ mkdir Demo.git
$ cd Demo.git/
$ git init --bare
Initialized empty Git repository in n:/Home/Demo.git/
Then change back to the local repository location and add a remote repository to your local repository. I'll name mine backup, you might want to name it origin if you don't have any remote repositories yet or potentially something more descriptive if you already have an origin remote repository.
$ cd /c/TFS/Demo/
$ git remote add backup /n/Home/Demo.git/
Lets check to see that the backup remote was added to the local repository.
$ git remote
backup
Now, push your branch to the backup remote repository.
$ git push backup master
Counting objects: 390, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (378/378), done.
Writing objects: 100% (390/390), 4.56 MiB | 4.87 MiB/s, done.
Total 390 (delta 255), reused 0 (delta 0)
To n:/Home/Demo.git
 * [new branch]      master -> master
The output will be a bit different every time, but the end result is the same... the files have been pushed to the remote repository.

Thursday, March 21, 2013

Lock Your OSX Computer

Fun tip. It is not obvious how to lock an OSX computer without logging off. After some searching a ran across a Gist which suspends the current session. This is equivalent to locking (Win+L) a Windows computer.
    #!/bin/bash
    /System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -suspend
If you save that into a file, you can make it executable by running:
    $ chmod 755 lock
This works great since I always have a terminal window open. Presuming the file is accessible via the path. I can just run the following and it locks the Mac.
    $ lock

Wednesday, March 13, 2013

Fixing ActiveAdmin Exception "undefined method `humanize' for nil:NilClass"

I am working on a Ruby on Rails project at the moment and ran across an interesting issue in ActiveAdmin. When I attempt to show an entity by id in a ActiveAdmin.register file, I would receive an error:

NoMethodError in MyEntity#show

undefined method `humanize' for nil:NilClass

I was lucky enough to get an Application Trace telling me the line to look at:

row(_nil) { "#{MyEntity.education_from_date} - #{MyEntity.education_thru_date}"}

Note: The formatting javascript removes the parameter "nil". Assume "_nil" is "nil".

Digging into to the database I discovered that the properties in the database were null, so I figured perhaps that was the issue (shouldn't be, but verifying this would be easy). I populated the fields, but the exception remained.

After some additional pondering, I looked at the nil parameter. There were other occurrences of this following that line, so I didn't think this would be fruitful. With a lack of other possible solutions, I pursued this farther. The row was supposed to not display a label, but just display the value. My first attempt was to change nil to "", but the exception remained. Not to be deterred, I attempted " " and that fixed my issue.

row(" ") { "#{MyEntity.education_from_date} - #{MyEntity.education_thru_date}"}