FitTimer - staying fit and having time for other things.

I like working out, but I like a lot of things and working out usually does not make my priority list as much these days. I used to spend a lot of time in a gym. By “a lot of time” I really mean a lot of time. Some weeks I must have spend as many as 20 hours in the gym. I was really fit but I had absolutely no time for other things.

I have started to wonder why my workouts are taking so much of my time. What in those workouts take the time and if there is a way to workout as hard but in less time. I bought a stopwatch and started measuring where the time was going. As you may expect it was not going into working out. Most of my time was spent on breaks. Breaks could take up as much as 90% of my time in the gym.

90% seems like a lot of time, so I have stated to experiment with different break times and I have noticed that I did not need to take such long breaks.  For most exercises a 45 second break was adequate where others were ok at 60 seconds.  Needless to say stopwatch became a necessary accessory at the gym.  Yes one more thing to carry while I work out.

And then … Apple came out with the iPhone.  Thanks, Apple.  It is the device that has replaced 3 items I used to carry with me at the gym.  The phone, an iPod and the stopwatch.

I have written FitTimer to be the way to keep track of my breaks.  Simplicity and nice design where the top priorities during the design process.

It had to be simpler then a stopwatch. After all no one want’s to struggle with a program while they are working out.  Your focus should be always on working out and not on operating a device.  Tracking your workout should be almost incidental and not the primary goal of working out.

It had to look good.  As one of the “gym rats” I know full well that we are somewhat vain.  OK, some of us are really vain, but I am talking about the average “gym rat.”  We go to the gym to look good.  Why would we have an app in the gym that makes us look worse?  Well, we would not.

So here is what I came up with:

Simple, functional and elegant.

Now I can fit my workouts in under an hour.  That’s 2 hours I save every day.

I bet if you work out and not measuring your times you are wasting your time just I use to so if you have an iPhone or an iPod touch you can get the app at the apple AppStore: FitTimer

You can also see more screen shot on our company website: http://eideticsoftware.com/fittimer

Rails, tests and code coverage

“If it’s not tested assume it’s broken.” This is one of the mantras in my company. Sometimes it’s easier said then done. If I always had to test everything I would be doing nothing but testing. So I employ different techniques to keep me programming and the computer to test the code I write.

One of the nice things about Rails is that you have a whole array of tools to automate testing and at least one very nice tool to let you know what’s tested and what’s not. Yes I am talking about Rcov.

Rcov has been “the bee’s knees” for code coverage awareness. Recently I have noticed Rcov has been doing more work then expected. When I ran the rcov command in a rails project it tested everything. I mean everything, including gems installed on the system.

Since everything is just a bit too much for my project I started looking for a way to limit the output. It appears I had to use -x option to stop the code coverage tool from traversing the gems. Here is the whole task:

desc 'Measures test coverage using rcov'
Rcov::RcovTask.new(:rcov) do |rcov|
  rcov.pattern    = "test/**/*_test.rb"
  rcov.rcov_opts  = [
    "-x 'gems/.*,rubygems/.*,rcov/.*'",
    "-T",
    "--rails" ]
  rcov.output_dir = “rcov/unified”
end

I hope this helps you.

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