Showing posts with label ruby. Show all posts
Showing posts with label ruby. Show all posts

Thursday, April 4, 2013

Git Grep with Git Blame

If you ever wished you could run git blame on the results of git grep then have a look at this

Wednesday, December 5, 2012

Using Rails.env in SASS

You can add your custom scripts to SASS easily, but make sure the following code loads in your config.rb/application.rb or somewhere along the line. and here is how you can use them

Sunday, May 8, 2011

Sniffing Android Tablets

On Android devices the "Mobile" string in the User Agent indicates that the device would prefer a version of the website optimized for Mobile (small form factor devices).
Tablets don't have this, for example

Mozilla/5.0 (Linux; U; Android 2.2.1; en-us; device Build/FRG83) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Safari/533.1

unlike phones

Mozilla/5.0 (Linux; U; Android 2.2.1; en-us; Nexus One Build/FRG83) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1


This can be used to detect Android tablet devices

is_androidmobile = request.user_agent =~ /android/i && request.user_agent =~ /mobile/i


in context

def is_mobile?
is_iosmobile = request.user_agent =~ /iphone|ipod/i
is_androidmobile = request.user_agent =~ /android/i && request.user_agent =~ /mobile/i

return is_iosmobile || is_androidmobile
end



more on that here,
android-browser-user-agent-issues

Sunday, June 13, 2010

Ruby memory leaks

So we had this problem that some batch processes in our production environment were leaking memory... and the funny part is that it was working fine on our developer machines.
In order to find out what's actually happening to it I've used the tool called
bleak_house, which is very good to examine how your object space is evolving.
Istallation is fairly simple:

gem install bleak_house

And then just run you application using the ruby-bleak-house instead of a regular ruby.

Basically what bleak_house does is it dumps an object space picture to a disk when you press Ctrl-C, or send a USR2 signal to the process.
So I used the second method from crontab to get an image of the process every minute.
Then you can run bleak command to analyze the dump and see what has changed.

In our case it happened that logs were not flushed (sic!), but since we are currently running our application with debugging logs enabled - it led to very fast process growth.