Sonntag, 13. Oktober 2013

RailsConf 2006

This is a rather old video from the RailsConf 2006 but still relevant (and very amusing):
http://www.scribemedia.org/2006/07/09/dhh/

Very relevant is also the latest book "Rework" written by David Heinemeier Hansson et al. at 37signals.
Read it!
It will change the way you look at (IT-) projects, entrepreneurship...
http://37signals.com/rework

Sonntag, 2. Juni 2013

Mac OS X tuning tips


Here are some tips that made my 5 years old Mac Book Pro a lot faster.
Please note, that im using OS X 10.8.3 while reading this.
As the Mac OS X file system doesn‘t require defragmentation as the windows file systems do, I don‘t recommend using third party defragmentation tools.
I suggest you stick to the Mac OS X tools shown here. You will notice the difference, in speed gained.

If your'e, like me, using a Mac Book, make sure it's running with the power supply and not on battery.

1. Defragment the Hard Disk

Start the console.
In the finder, select: Applications -> Utilities -> Console

You can manually start the daily, weekly or monthly defragmentation jobs by typing:
-> sudo periodic daily
or
-> sudo periodic weekly
or
-> sudo periodic monthly
or all at once
-> sudo periodic daily weekly monthly

You will be asked to type the super user password each time.
Please wait until the defragmentation is done.
Don‘t be disappointed if it takes only a few seconds, because your Mac starts this jobs periodically on its own.

2. Repair the file Access Rights

Access rights, that are not set correctly can slow down your Mac.
But don‘t worry. Your Mac has the tools to correct the access rights.
Start the Disk Utility.
In the finder, select: Applications -> Utilities -> Disk Utility

In the disk utility window, select the volume and klick the button „Repair access rights“
Please wait until the job is done.

3. Repair volume

In order to repair damages on you (main) volume you open the „Disk Utility“.
To be able to repair and not just analyse the volume however, you have to start the disk utility in another way as described above. Shut down your Mac and start it again while holding the keys cmd+r (all together). A window, where you select the disk utility, will show up.
Select the volume and click „Repair Volume“ and wait until the job is done. This can take a while.
Don‘t bother if you get some minor errors at this time. On my Mac they disappered the second time i repaired the volume.

4. Reset Cache

Shut down your Mac, stating it again keeping alt+cmd+r+p (all together) pressed.
The second time your Mac "bounces up", you release the keys and your Mac will start all the way up.

Shut down your Mac and start it again. If you got some minor errors while repairing the access rights or the volume, you can try repeating those steps. I my case, my Mac generated no errors the second time and the gain in speed was significant!

Have fun!

Donnerstag, 4. April 2013

Spin Heroku Dynos up and down programmatically

Does your customers sleep at night?
If they do, your software can do that as well ;-)

So why not spin the Heroky dynos down to 1 in the night and spin it up next morning again. One dyno is free of charge and your application will still be accessible with a bit larger load time when your app has „gone to sleep“ (swapped out on disc).
The load time, when in „sleep mode“, is aprox 30 seconds, but when it‘s up and running, it‘s ... up and running and will do so for a while until going back to sleep.
Spinning the dynos up and down programmatically is done with two rake tasks and the „Heroku Scheduler Standard“ add on, which is free of charge!

This is what you have to do:
  1. Add an environment variable „APP_NME“ with the name of your app.

    In the console: heroku config:set APP_NAME=myapp
    Check the settings in heroku.
    In the console: heroku config
  2. Add the gem „heroku-api“ to your gemfile.
Please note, that there is an older gem „herou“ to, but you should use the new one as it covers the new heroku api:
    gem "heroku-api", "~> 0.3.9"
  3. As you have to - once in a life time - manually confirm the billing of a second dyno, you have to spin up the dynos to more than 1, manually once.
    In the console: heroku ps:scale web=2
  4. Add the two rake tasks below to lib/tasks/scheduler.rake

    Please note that the heroku scheduler expects a file with the name „scheduler.rake“
    You find your heroku api key in the app settings on heroku!
  5. Add the free heroku add on „Heroku Scheduler Standard“ to your app.

    On the console: 
heroku addons:add scheduler:standard
  6. Test your rake tasks manually.
    In the console: heroku run rake spin_up
    And check the result.
    In the console: heroku ps
  7. Enter the appropriate settings in the heroku scheduler using the heroku web site.
    Please note, that the time entered is a UTC-Time (Coordinated Universal Time), which can differ from your local time. In most european countries the local time is UTC+1 in the winter and UTC+2 in the summer due to the summer time correction.


Content of lib/tasks/scheduler.rake


require 'heroku-api'
desc "Scale UP dynos. This task is called by the Heroku scheduler"
task :spin_up => :environment do
  puts "Spinn one dyno up..."
  heroku = Heroku::API.new(:api_key => 'my_app_key')
  heroku.post_ps_scale(ENV['APP_NAME'], 'web', 2)
  puts "Done!"
end


desc "Scale DOWN dynos. This task is called by the Heroku scheduler"
task :spin_down => :environment do
  puts "Spinn one dyno down..."
  heroku = Heroku::API.new(:api_key => 'my_app_key')
  heroku.post_ps_scale(ENV['APP_NAME'], 'web', 1)
  puts "Done!"
end