GoRuCo 2012 talk

So this post is a few weeks overdue. I gave a microtalk at the GoRuCo 2012 (Gotham Ruby Conference) a few weeks ago. It was a blast!

My talk was titled 'Your Face in 10 minutes…with Macruby!' I ran through how one would create a desktop Mac face detection/recognition app with Macruby. For face detection, I use Cocoa’s native CIDetector (Core Image Detector) Api. For facial recognition, I integrated a Face.com rubygem. Since then as I’m sure you’ve heard, Face.com is shutting down its API services as part of the Facebook acquisition. So that part might not work in the near future, but still is a great example of how to integrate existing rubygems in a Macruby project.

I really wanted to get people excited about Macruby. I’ve been building apps with it for a couple of years now, some of which I hope to publish to the Mac App store at some point. With all the hype and excitement about RubyMotion, I don’t want people to forget where a lot of that awesome-ness came from. Its a great platform and writing desktop apps is actually fun!

I was humbled to speak amongst some ruby greats (i.e. Jim Weirich, David Chelimsky, Dr. Nic Williams). It was great chatting with everyone at the conference but the Yacht Party and especially the Karaoke after-after-party was AWESOME!

Since it is my birthday today, I’d like to offer everyone a gift…the code and slides from my talk :). You can also find the talk on Confreaks and its also available on Vimeo.

The web is soooo last decade…its all about desktop apps now ;)

Terminator vision trailer | hamin

@TerminatrVision full theme song from the trailer :) I recorded using Garageband on my Macbook Air

Install Riak on OS X Lion

I’ve been meaning to play with Riak for a while and finally decided to give it a shot with Riak Fast Track. This will be a quick repost of this other post, which was almost perfect, except you don’t need to pass 32-bit architecture build flags, you can specify 64-bit architecture. Perform the following in your shell :

curl -O http://downloads.basho.com/riak/riak-0.14/riak-0.14.2.tar.gz
tar xzvf riak-0.14.2.tar.gz
cd riak-0.14.2
CC=gcc-4.2 CFLAGS="-m64" LDFLAGS="-m64" make all rel
cd rel/riak
ulimit -n 1024
bin/riak start

I also spoke with Sean Cribbs, a Basho employee who works on Riak that the next stable version of Riak will have proper OS X builds with Lion in mind. In the meantime, following Basho’s instructions with the steps mentioned in this post should be enough. Enjoy!

Cascadia Ruby Conf 2011…a quick reflection

So this post is about a month overdue, but hey, Ramadan just ended. Thirty days of fasting and not enought sleep will definitely be cause for a bit of procrastination.

Cascadia Ruby Conf 2011 was definitely FANTASTIC! It was my first ever talk/presentation as a professional programmer at a conference. I’ve done several impromptu and informal unconference/barcamp/meetup talks but not a prepared talk with slides for a while. The last presentation I remember giving with slides was way back in college for my math research… Simulation of Viscoelastic Fluids…fun stuff :)

One thing I’ve gathered from attending Cascadia Ruby Conf and other local conferences (GoRuCo, GothamJS), I really love local conferences. I especially love small single track conferences. I always feel like I never missed a session that I would’ve liked to attend, and the discussions/Q&A are always more riveting.

I can say loads about all the different talks but really, just check out confreaks coverage of all the talks.

I think my talk went fairly well. For those of you who were unaware, my talk was titled The Enumerable Module or How I Fell in Love with Ruby. I essentially wanted just to share how I love the Enumerable module and why it makes me enjoy Ruby programming so much. My goal was that both experienced and inexperienced members of the audience would get something out of it. And judging from the feedback I got, I think I was fairly successful. One of the presentations after mine, mentioned how he loves that there was a whole presentation on the Enumerable module, he never seemed to recall seeing a whole presentation on Lists at any Java conference he’d been to :) .

I had a blast in Seattle, its a gorgeous city and of course it hosts an excellent Ruby community. I also had the chance to jam with a Ian Dees and Ivan Oats. Here is us jamming on Hey Joe by Jimi Hendrix.

You guys can check out my talk on confreaks. By the way… CONFREAKS ROCK!!! You can also grab my slides on both slideshare and scribd. I do plan on giving this talk (revised and perhaps extended) at other conferences if I get a chance, so do let me know if you’re interested.

I will end this post with something I said in my talk that seemed to resonate with the audience:

Are you in love with ruby yet? You don’t have to be monogamous…. go make some love!

Resources


Scribd

The Enumerable Module or How I Fell in Love with Ruby


Slideshare

The Enumerable Module or How I Fell in Love with Ruby

View more presentations from harisamin


Confreaks : http://confreaks.net/videos/607-cascadiaruby2011-the-enumerable-module-or-how-i-fell-in-love-with-ruby

Hey guys, I know I haven’t written in a while. That’s going to change…I’m serious! I am going to be presenting at the very first Cascadia RubyConf in Seattle,WA July 29-30, 2011. I will be speaking on July 29 @ 10:30AM PST. The guys at ConFreaks will be streaming the talk live. I will post a link once I get a chance. Oh, and the title of the talk is The Enumerable Module or How I fell in Love with Ruby.

Hey guys, I know I haven’t written in a while. That’s going to change…I’m serious! I am going to be presenting at the very first Cascadia RubyConf in Seattle,WA July 29-30, 2011. I will be speaking on July 29 @ 10:30AM PST. The guys at ConFreaks will be streaming the talk live. I will post a link once I get a chance. Oh, and the title of the talk is The Enumerable Module or How I fell in Love with Ruby.

Making Rails 3 RC, MongoMapper, and Devise play nice…for now

Edit: There is also a MongoMapper Devise plugin 
which has even the model generators working. 
Check it out: http://github.com/kristianmandrup/mm-devise
Let me know what you guys think. 
You can always use my solution below too :)

So this will be a quick informative one. Goal here is simple: get Rails 3 RC, MongoMapper, and Devise working all together nicely without much fuss. I had trouble finding this information so thought others might benefit from my findings.

First, real quickly, Devise for a long while had MongoMapper support. Up only recently (since a couple of months ago or so) they have removed support for MongoMapper since MongoMapper is not ActionModel compliant yet. Don’t panic just yet, from all that I’ve heard and read from John Nunemaker (author of Mongomapper), MongoMapper will be ActionModel compliant once final release of Rails 3 is out. If you’re unsure or don’t believe what I’m saying check out this conversation from the MongoMapper Google Groups .

So what to do for now, well if you looked further on the Google Groups page, Aaron Ti was nice enough to write a very simple and working Devise adapter for MongoMapper. Here is his Gist for his adapter:

So take that adapter and throw it in your lib directory in a file such as /lib/devise_mongomapper_adapter.rb. Then install devise as you would normally:

# install the gem
gem install devise

# install devise to your rails app
rails generate devise:install

Now the usual devise instructions tell you to run the devise model generator. Well, that doesn’t work in the adapter. But DONT PANIC! We can just create our own User model like so:

class User
  include MongoMapper::Document
  
  key :email, String
  key :username, String
  key :first_name, String
  key :last_name, String
  key :encrypted_password, String
  key :password_salt, String
  key :reset_password_token, String
  key :remember_token, String
  key :remember_created_at, Time
  key :sign_in_count, Integer
  key :current_sign_in_at, Time
  key :current_sign_in_ip, String
  timestamps!
  
  attr_accessible :email, :password, :password_confirmation
  
  devise :database_authenticatable, :registerable, :validatable, :recoverable, :rememberable, :trackable

end

Now this last step is very important! In your config/devise.rb make sure you’ve required your Devise MongoMapper adapter like so:

require 'devise_mongo_mapper_adapter'

And that’s it! You’re ready to use MongoMapper with Rails 3 and Devise. Just to let you know, I’m using Devise 1.1.1 currently and haven’t run into any problems. This is again if you can’t wait till MongoMapper, Devise, and Rails 3 play nicely natively again. Once Rails 3 is released, these issues will be of the past.

*NIX Commands to the Rescue

I thought that for my first meaningful post, I should share some *NIX knowledge with you guys (however many there may be). Some of these tools are new for me too.

The problem that I think most people find with learning/using more *NIX tools is not that there information isn’t there (man pages are your friend), but the information is sometimes out of context. I’ll show you some quick little *NIX commands that I used to troubleshoot a few things for a server running multiple Rails applications.

I was recently having problems on a server with processes which were taking too long to finish and were essentially hogging up resources on my machine. One of which is an ugly mess of a process that does a bulk import of a 40K+ record CSV file (arghh…3rd party vendors!) to a relational database (Postgresql). And the other is a daily incremental system backup run by my hosting provider (Rackspace).

So what can one do to investigate the health of their disk(s)? Well standard *NIX tool iostat goes a long way:

iostat

iostat will then spit out some pretty nice metrics on IO and CPU usage for all of your disks:

Note: The output of these tools/commands might vary in style and ordering of columns on different *NIX distributions. The output noted in this post is a RedHat Enterprise Linux (RHEL) machine .

e.g.

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           5.07    0.59   13.49    7.42    0.00   73.44

Device:            tps   Blk_read/s   Blk_wrtn/s   Blk_read   Blk_wrtn
sda              55.04        49.13       241.79  499975863 2460564420
sda1              0.00         0.04         0.00     439390      10130
sda2              0.24         3.34         1.69   34011331   17192522
sda3              0.73        13.17        12.33  133976082  125519952
sda4              0.00         0.00         0.00         18          0
sda5             54.06        32.58       227.76  331548234 2317841816

iostat basically gives you a status/summary of read, writes, and usage of the disks on your server. You can also use iostat 1 which essentially tails iostat so you can observe how those stats are changing. Adding the 1 argument may seem cumbersome, but it comes in handy for seeing how the stats change (if at all) as certain processes are killed. That was a gem for me.

You might want to see how IO was on your server today. Well for that you can use this:

sar

sar gives you averages on IO and CPU usage in 10 minute intervals.

e.g.

12:00:01 AM       CPU     %user     %nice   %system   %iowait    %steal     %idle
12:10:01 AM       all     11.90      0.00      1.98      8.67      0.00     77.45
12:20:01 AM       all      0.89      0.00      0.27      0.85      0.00     97.99
...
02:10:01 PM       all      4.08      0.00      1.00      0.36      0.00     94.56
Average:          all      4.21      0.01      9.68     22.81      0.00     63.29

This came in handy for me since the processes I was investigating were created by scheduled cron jobs that run daily at a low traffic time (usually early in the morning for me).

Lastly, I wanted to make sure that one process or the other was not paused by the system while it was trying to allocate resources properly. If you want to make sure that a process with a specific Process ID (PID) is not paused, you can always send it a continue signal like so:

kill -n SIGCONT 

Up until recently, I’d only used the kill tool to well…kill processes! But to my delight, and hopefully yours to, kill can take this neat little SIGCONT signal and send a continue signal to a process that might have been paused intentionally or unintentionally.

So that’s it for now. I hope you guys will find these tools useful. And remember, if you’re ever need to know more about any of these tools just check the man pages (i.e. man kill). Till next time, Happy *NIXing

Hello World!

Hey guys. Well this is meant to be my professional blog, but we’ll see how long that lasts :). I will try to post about my musings with all things code, linux, world of the web, and such. So here it is:

class Person
  attr_accessor :name
end
class Haris < Person
  def initialize
    @name = "Haris Amin"
    puts "I, #{@name} LIVE!"
  end
end
Haris.new # => "I, Haris Amin LIVE!"
© Copyright 2012 Haris Amin