iChessClock in the Apple AppStore

Brent and I finally were able to submit our first iPhone application. It’s a simple yet elegant chess clock that can satisfy most of the chess matches out there.

Eidetic Software’s Website:
http://www.eideticsoftware.com

The iChessClock is available at the Apple AppStore

Removing git-svn remote branch

I could not find a reference how to remove a remote branch that is connected to an SVN repository so I have tried this:

$git branch -r -d my-remote-branch

This seemed to work well.

Unix prompt (PS1) with git branch name

Working with Git I noticed that I change branches quite a lot. This is a good thing but sometimes I am in the incorrect branch when I check things in. I needed a warning system especially when I check things into remote SVN repository. Since most of my check-ins are done from the command line it would be nice to know what branch I am on just by looking at the screen. Fortunately there is neat way to add the branch information to the Unix prompt. You can do that by overriding the PS1 variable for example:

export PS1="[\D{%Y-%m-%d} \t] \w \n$”

would generate

[2008-07-12 12:00:00] /foo/bar
$

if I am in the /foo/bar directory.

So at this point I would like the prompt to look like:

[2008-07-12 12:00:00] /foo/bar [master]
$

when I am in a master branch and prompt:

[2008-07-12 12:00:00] /foo/bar [experimental]
$

when I am in any other branch.

Here are the steps to get this working:
Prerequisites:
- ruby interpreter
- git

Steps:

  1. Create a git-ps.rb file
    green = "\033[0;32m"
    white = "\033[0;37m"
    red   = "\033[0;31m"
    current_branch = `git branch 2>/dev/null`.grep(/^\*/).first
    if current_branch
      branch_name = current_branch.gsub(/^\*\s*/,'').strip
      color = branch_name  =~ /master/ ? green : red
      unless current_branch.empty?
        puts "  #{color}[#{branch_name}]#{white}”
      end
    end
    
  2. create .ps file in your home directory:
    parse_git_branch() {
      ruby ~/git-ps.rb 2>/dev/null
    }
    export PS1="[\D{%Y-%m-%d} \t] \w\$(parse_git_branch) \n$ ”
    
  3. Include the .ps file in your .bashrc and .bash_profile by inserting following line:
    . ~/.ps
    

To activate the new prompt in your current execute command:
. ~/.ps

I hope this helps.


References

Ref: Prompt Creation
Ref: Git and Bash prompt
Ref: __git_ps1


Downloads

colored_branch_name

Chess quote of the day

“I would do just fine if I could get you to keep your pieces still.”
- Scott

Gaussian Rounding in Ruby

While working on a research tool for my work I have noticed that my ruby solution rounds differently then the original c# .net code. It was not in every but about 10 percent of my tests failed due to the different rounding schemes.

Ruby uses the Symmetric Arithmetic Rounding while C# .net uses the Gaussian rounding otherwise known as the Banker’s routing.

I have looked for a quick solution for Ruby but Google did not return a result I could immediately use. I have found a javascript solution which I translated to Ruby.

Additionally I have added a “decimal” parameter to specify the precision of rounding.

Here is the code:

class Numeric
  def _round(val)
    sign = val < 0 ? -1 : 1
    return (val.abs.round * sign) if (val.abs - val.abs.floor) != 0.5
    return (val.abs.ceil  * sign) if val.abs.floor % 2 == 1
    return (val.abs.floor * sign)
  end

  def gaussian_round(decimals = 0)
    return (_round(self * (10**decimals))/((10**decimals).to_f))
  end
end

Ref: Javascript Gaussian Rounding Example
Ref: Wikipedia article on rounding

Using MacRuby to set Xcode project version from git

I have been looking into automating some of my development tasks in Cocoa/Xcode environment.  For the longest time I was using Subversion which would integrate quite well with Xcode. Recently, however, I have been exploring other version control systems.  Especially git.  Since it’s a much newer (D)VCS it does not have as much integration into systems as subversion.

I have managed to find some interesting solutions to include Git version number in Xcode project however the only actual solutions I have found are written in languages I don’t care for anymore.  Yes I can program in them but why would I want to.

So here is a quick solution written in MacRuby.

#!/usr/local/bin/macruby

git_output = `git show --abbrev-commit`
commit_version = git_output.split("\n").grep(/^commit/).first
version = commit_version.gsub(/^commit\s+(.*)\.{3}/, "\\1")
if version
  list = NSMutableDictionary.dictionaryWithContentsOfFile("Info.plist")
  list["CFBundleVersion"] = version
  list.writeToFile(’Info.plist’, :atomically => true)
end

In my final solution I intend to have an output in following format:

major.minor.revision (build)

where the “build” is going to correspond with the git commit version
and the other parts will reflect the marketing version numbers.


Ref: Shiny Frog Article Python solution
Ref: Cocoa is my Girlfriend Article Perl solution

Motto of the Day

“If you don’t know where to start, start from writing tests.”

Quick rename of menu items in XCode

Sometimes a little bit of automation goes a long way and other times it may be just wasted time. I have run into one of these situations recently when dealing with Xcode and trying to rename menu items from NewApplication to the Application Name.

For Example:

Quit NewApplication -> Quit TestApp

My first approach was to use Ruby open the MainMenu.xib and do a replacement. This technique may prove to be useful in the future when I have more command line tools for other tasks, but currently there is a much simpler way of dealing with renaming menu items.

1. Right click on MainMenu.nib and select “Open As” -> “Source Code File”

2. Press: “Command-F” to open find/replace dialog

3. Replace all NewApplication strings with desired application name.

That’s it

Webkit-appearance property.

I have spend some time wondering why would Apple decide to style their buttons in a non-standard way and then not respect the css style set by the designer. I just found the answer how to get rid of the Apple predefined style and allow the buttons to look like in every other browser. To do this you have to set the webkit-appearance property to none:


input { --webkit-appearance: none; }

That’s all.

Contributing to ActiveMerchant

I have always been a fan of open source and wanted to contribute some code to a project or two. Somehow, I never found a project I would really enjoy and could directly benefit from as well. I was simply looking for an project that would scratch my itch.
Finally while working on an e-commerce system for my company I have decided to use active_merchant to connect to PayPal. The original implementation used by active_merchant was targeting and older xml based gateway and I have decided to re-implement the gateway using more recent NVP (name-value pair) interface. Hopefully this will allow for more modern features of the PayPal service.
A few days ago Cody has committed my patch and it is currently part of the active_merchant main code.

I have also created git repository where I can add more functionality as needed.
Here is the link for the interested:

git clone http://git.furmanek.net/active_merchant.git

Enjoy.