– we create awesome web applications

Pow is great. The single thing that bothered me was problems with using debugger while pow'ing away.

Did you ever put a debugger into your controller, connected with rdebug, hit refresh but it didn't stop?

The problem is most probably with POW_WORKERS setting. You see, by default, pow will start 2 ruby processes per application.

Since direct console access is not available when using pow, you have to use rdebug instead. Usually it means something like this added to config/environments/development.rb:

# to use ruby debug with Pow do the following:
# echo export RUBY_DEBUG_PORT=20000 >> ./.powenv
#
# to connect:
# rdebug -c -p PORT_NUMBER
if ENV['RUBY_DEBUG_PORT']
  Debugger.start_remote nil, ENV['RUBY_DEBUG_PORT'].to_i
end

Then you can restart your pow application and run the following command line:

rdebug -c -p 20000

Once you get "Connected." back you know that your rdebug has connected to some ruby process and is awaiting breakpoint hit.

The problem is that pow by default starts 2 ruby processes per application, and so only one of them will be able to bind to the port 20000. Which in turn means that only requests being processed by this process will get a chance to be stopped in debugger. So on average only about 50% of your requests will hit the debugger.

The solution is fairly simple. Just add the following line to your ~/.powconfig file:

export POW_WORKERS=1

Then restart pow.

Note: I mean the whole pow server, not just your current application. I'm using the excellent powify gem for this:

gem install powify
powify server restart

From now on you will get only one pow process per application and never miss a breakpoint again.

I was frustrated by ⌘Q and ⌘W proximity for a long time. Long, long time. Seriously, long time.

It hits me the most with browsers since I usually open and close quite a lot of tabs during the day. And I tend to do it from keyboard, so sometimes I just hit ⌘Q when I only intended ⌘W.

It just happened again.

But this time I suddenly realized that I can easily remap it. I was using this OSX feature for other things, like remapping useless since the typewriter days Caps Lock key, but somehow missed that I can fix this annoying problem too.

If not universally then at least in Chrome (or any other application if needed).

This is really easy:

  1. go to System PreferencesKeyboardKeyboard Shortcuts and choose Application Shortcuts in the left panel.

    Keyboard Shortcuts

  2. click on the + icon to add another shortcut.

  3. Choose Google Chrome as the application and type in exactly, including case Quit Google Chrome as Menu Title. Generally, it should be the exact menu command name in the application that you want to map.

  4. Now, click inside the Keyboard Shortcut field and then press on you keyboard whatever the new shortcut you want. I chose ⌥⇧Q so that it will stay at the same place but wont be as accidentally press-able.

Quit Google Chrome shortcut

⌘Q will not longer work, and the new shortcut will be correctly displayed in the Chrome's menu:

Chrome Menu

nanoScroller.js - jQuery plugin to implement OSX Lion-styled scrollbars for your website.

strong_parameters gem allows you to "test drive" the new way that Rails 4 is going to treat parameters security. attr_accessible and friends are being deprecated.

celluloid.io interesting approach to multithreaded programming for Ruby.

Letters - new take on debugging logging library for Ruby.

showcase of 40 pricing tables and signup pages can help with with some inspiration for your pricing page.

lenticular.js - Tilt controlled images.

Repo.js - light-weight jQuery Plugin that lets you easily embed a Github repo onto your site.

FullCalendar is a jQuery plugin that provides a full-sized, drag & drop calendar with events etc.

tl;dr Legal - easy summaries of open source licenses.

CCMenu - OS X menu bar application to pull build status of your projects. Support many different CI backends.

[Update - 30 Apr 2013] The new, updated and faster version of this blog post covering Ruby 1.9.3 patchelevel 392 and railsexpress patch set.

I knew that there are various Ruby patches available but I've never tried them as I didn't want to waste time for something that I thought I don't really need.

Then I found out that rvm comes bundled with patches ready to be applied, so I'm just a simple command line away from having a patched Ruby. Don't know how I missed that before.

One particular patch that worth trying is falcon. It improves startup time of big Ruby applications. And the bigger your Gemfile is the bigger the improvement.

Try it right now for yourself. It will only take a couple of minutes.

First upgrade rvm to make sure you have the latest

rvm get head

Then the actual Ruby build

rvm install 1.9.3 --patch falcon -n falcon

Note that this command can fail with the following error: Patch 'falcon' not found. The reason is that falcon patch is not yet supported on the latest Ruby patch level, in which case you will need to specify older patch level to make it work.

Find out what patchlevels have falcon support

✗ ls $rvm_path/patches/ruby/1.9.3/*/*falcon* | sort
/usr/local/rvm/patches/ruby/1.9.3/p0/falcon.patch
/usr/local/rvm/patches/ruby/1.9.3/p125/falcon.patch
/usr/local/rvm/patches/ruby/1.9.3/p194/falcon.diff
/usr/local/rvm/patches/ruby/1.9.3/p286/falcon.diff

So latest patch level with falcon support is 286 at the time of this writing.

Install specific patch level with falcon support

rvm install ruby-1.9.3-p286 --patch falcon -n falcon

Congratulations, you now have a patched Ruby installed.

Lets test how much improvement it is. The following is for one of my current projects with about 50 gems:

✗ rvm use default
Using /usr/local/rvm/gems/ruby-1.9.3-p194
✗ time bin/rails runner "puts :OK"
OK
bin/rails runner "puts :OK"  6.47s user 0.60s system 99% cpu 7.106 total
✗ rvm use ruby-1.9.3-p286-falcon
Using /usr/local/rvm/gems/ruby-1.9.3-p286-falcon
✗ time bin/rails runner "puts :OK"
OK
bin/rails runner "puts :OK"  2.79s user 0.52s system 98% cpu 3.354 total

Nice! Startup time decreased from 3.354 to 1.106 seconds. More then twice faster.

I'm going to use this Ruby by default now

rvm use ruby-1.9.3-p286-falcon --default

And while we are on the "lets improve rails startup times" subject, lets do one more change. Add the following to your shell startup file. i.e. ~/.bashrc or ~/.zshrc

export RUBY_HEAP_MIN_SLOTS=1000000
export RUBY_HEAP_FREE_MIN=500000
export RUBY_HEAP_SLOTS_INCREMENT=1000000
export RUBY_HEAP_SLOTS_GROWTH_FACTOR=1
export RUBY_GC_MALLOC_LIMIT=100000000

This will tune Ruby GC settings to be better suited for running big apps (as it seems to be tuned for small Ruby scripts by default).

Lets see how much improvement that is

time bin/rails runner "puts :OK"
OK
bin/rails runner "puts :OK"  2.27s user 0.58s system 98% cpu 2.890 total

Total improvement from 7.106 to 2.890 is almost 60%.

Now, stop fiddling with the environment and go back to creating something great! :)

I recently switched to ruby 1.9.3 as my deafult ruby verison, and suddenly some of my scripts started to fail in funny ways.

One of the latest ones was the script that was supposed to change 'updated' timestamp in a YAML formatted file. Instead of the current date it started to spit out binary strings.

The problem is quite complext but the fix is simple...

First lets see what happens:

In ruby 1.9.2p320:

> require 'yaml'
 => true 
> Time.now.to_s.to_yaml
 => "--- 2012-09-03 22:20:15 +0300\n" 

In ruby 1.9.3p194:

> require 'yaml'
 => true 
> Time.now.to_s.to_yaml
 => "--- !binary |-\n  MjAxMi0wOS0wMyAyMjoyMDozMCArMDMwMA==\n" 

Why did that happen?

This happens because Time.now.to_s returns a non-ascii string

> Time.now.to_s.encoding
 => #<Encoding:ASCII-8BIT>

To remind you, UTF-8 is backwards compatible with the standard 7bit ASCII, as the ASCII is just the subset of UTF8 where the 8th bit is 0;

So to output an 8bit ASCII in UTF-8 a conversion might be required (for example when time format contains regional characters from the upper part of the 8bit ASCII).

It is the same in 1.9.2 but apparently YAML over there knows how to handle it in the case when the string doesn't actually contain any 8bit characters.

In 1.9.3, instead of performing conversions YAML seems to just opting for the 'lets treat it as a binary' handling.

The problem of encodings is complex and "hairy", so we wont go into details here, but in the case when you just need a quick fix like I did you do this:

> YAML::ENGINE.yamler='syck'
 => "syck"
> Time.now.to_s.to_yaml
 => "--- 2012-09-03 22:24:22 +0300\n"

And the problem solved.

I did an overview presentation about the current state of real time web and server-push technologies at the Israely DevCon 2012 conference.

Below is the transcript of the talk (actually more like a talk plan ;)

There is also a [pdf version for download][pdf].

It is in English as this is the way I usually write down my presentations, although the actual talk was delivered in Hebrew.

Check out the video of the talk on YouTube or embedded here. And if you more of a reader then viewer you can check out the slides with sort of transcript below.

Given that module Foo is defined elsewhere what is the difference between this snippet:

class Foo::Bar
  ...
end

and this:

module Foo
  class Bar
    ...
  end
end

Answer inside ;)

LaunchBar is one of the tools I can't live without.

Basically, it's an application launcher, but besides actually launching an application it has lots and lots of features that help me complete tasks on my laptop while staying in the flow.

Ever since I installed it on my MacBook my workflow changed quite dramatically to the better.

My Vim-fu improved a lot in the last couple of years.

Part of the reason is that working on [dotvim][dotvim] forced me to dive deeper into it, but thats not the whole story.

I think a much bigger reason is that I decided to systematically work on improving it.

One of the tricks I use is to have a list of Vim tricks and shortcuts that I'm learning right now on my OSX dashboard.

It's alive. Again ;)

This blog was dead for a while. It was running on an old Mephisto system and it's admin interface just broke one day, throwing some cryptic exception.

It was probably not that hard to fix, but every time I thought to write a blog post it was like "oh, I have to dig into this antient codebase to figure out how to fix it before I actually get to write anything. I'll pass..."

So days become weeks, and weeks become months, pretty fast its a year that passed by with no blog posts whatsoever.

Meanwhile I was scribing my thoughts on future blogposts in markdown files on my harddrive.

Not long ago we finally decided to do something about it.

I was working on tests for blender when I came upon a need to mock or stub a back-tick operator e.g.:

`shell command`

Apparently this is just a shortcut for calling Kernel method :`.

We are giving 4 out of 20 sessions at Open 2010, an Israeli open source conference.

I just recently reinstalled my MacBook Pro, this time with Snow Leopard.

So I'm again going through various installation problems I already forgot about from few years back when I installed Leopard.

Anyway, just had to hunt down a problem with mysql gem installation on Snow Leopard.

A few days ago I gave a presentation about Ruby for Sayeret Lambda discussion group.

The title was "Ruby is an acceptable lisp" but the message is better served by "Ruby is Better then Lisp ... sometimes" :)

There is a new (0.2.7) version of Astrails-Safe.

I've just read "Do You Believe In Magic?" and the following quote resonated particularly well:

"It's not magic. There is no magic involved. It's just, if you never learnt Lisp, then you never learned to program, and Ruby's power is exposing a deficiency in your skills."

If you follow us on twitter (@astrails if you wondering) you already know that we are at the Startup Weekend Israel right now.

Which is going amazing by the way, thanks for asking, lots and lots of nice people, very creative and energetic atmosphere, food and beer.

Turns out our idea attracted a great team of developers, designers and business developers.

We just started a project for a client that involves Cassandra.

If you've been living under a rock and don't know what Cassandra is let me tell you :)

Cassandra is a "second-generation distributed database" that was built for web scale.

Its is one of the many distributed nosql databases that appear everywhere lately like mushrooms after a heavy rain :).

What sets Cassandra apart is that it comes from a recognizable entity - Facebook.

But I digress.

This is not meant to be a Cassandra introduction, there are enough of those on the net. I Just created a new nosql section on this blog where I'm going to post various tidbits of information about cassandra (and probably others) as I learn them while working on this new project.

Here is the first one: Cassandra gem is just an installer

Yeah, I know, MVC is the "Only True Way™". But sometimes, just sometimes, you need your link_to or html helpers working in the model.

For example, sometimes the cleanest way to implement something is to have to_html in the model (widgets anyone?).

Doing this will most probably require generating some urls, and you need a controller for that. Usually I solved this by passing controller to the to_html function, but it always felt wrong.

Just released a new 0.2.5 version of astrails-safe.

astrails-safe is our very simple to use backup script for mysql, postgres, filesystem, and subversion. It can store your backups locally, on Amazon s3 or on a remote SFTP server. Optional GnuPG enctyption completes the picture.

Since Github stopped to build gems we are moving to the gemcutter.

Damn, I just found this unpublished article in the blog admin...

How come it evaded my attention for 3 months??!!

Anyway, releasing it now thought this is all quite old news, going to announce 0.2.4 in a moment :)

I just did something pretty stupid. I edited /etc/sudoers file directly from within my non-root user account.

I just pushed new version 0.1.9 of astrails-safe to github.

The main difference is a fix to an embarrassing bug in the S3 backup rotation code.

Thanks to Thuvarakan Tharmalingam for reporting.

Again, the reason it escaped was the fact that we don't yet have full test coverage.

We are getting there though....

It looks like our astrails-safe gem is quite popular :). People started to contribute new features:

Mephisto commenting system is... how do i put it ... outdated :)

And we wanted something more engaging for our blog. Looking around the web we found that Disqus was used all over the place, so we decided to integrate it into our blog instead of the native comments system.

Wouldn't it be cool if you could just require "http://my-host/my-lib.rb" in ruby?

Now You Can! Using our "http_require" gem! :-)

Everyone needs a backup, right? Unfortunately almost no one does though. Why?!

We needed something for ourselves and our customers. Something simple, free, configure-and-forget. Most of the time there is no need for something fancy, a simple tar + mysqldump can do the job for many small/medium sites.

We recently moved our DNS to dnsmadeeasy.com from godaddy.com name servers.

After the transfer some internal CNAME records had a problem. So after fixing the problem and checking in the terminal that the changes propagated to the DNS server (host xxx.astrails.com) I tried to type the address in the browser, but it kept giving me the "can't find host" error.

Recently we looked for video transcoding/hosting solution to use in one of our client's projects.

The best thing we've found is Panda. It runs on Amazon stack of services including ec2, s3, and simpledb.

Using amazon has many advantages. no contracts, pay as you go, easy and fast scaling in case your site explodes :)

Unfortunately the image that is refered in the Getting Started (ami-05d7336c) is not safe for production - it has openssh version with a serious security bug, but don't worry, we will explain how to fix it.

This blog-post is mostly targeted at non-Rails developers. Rails devs should know all this by heart :) Many times we need to explain to our customers what is 'proper deployment' and why their current one sucks :) Now we'll be able to just point them to this post...

Blog moved to Mephisto. So we have comments now.

In the process of installing Mephisto I've got a problem with image_science gem.

It installed OK but when trying to require it the was a problem with RubyInline compilation:

We really like Debian and we usually use the current "stable" distribution for our production servers.

It all works great with one little problem: if you need very current soft it is probably not in the 'stable' yet.

The current Debian stable ("etch") includes rubygems 0.9.0-5 which is way too old.

We needed to upgrade to at least 1.2.

We just incorporated our own Ltd. company.

It was coming for a while now but we finally got to it when we started to hire people :)

Once again I’ve hit a problem of installing gems on a machine with very little memory.

On one of our projects we needed to do some caching for an action with an expensive db query. Fragment caching took care of the rendering but we needed a way to skip the db if we have a cache hit. And checking for an existence of the fragment file in the controller just didn’t seem right.