Ever tried this:
Weird isn't it ?
I checked the "/etc/sudoers" and everything looked normal:
toamitkumar ALL = (ALL) NOPASSWD: ALL
I have sudo access - which means I have access to everything (thats what my understanding was)
Well, I was wrong.
After thinking for a while I felt - 'cd' is not a program, it is built-in for bash shell. So, I had to do:
sudo -s or
sudo su or
sudo bashand then 'cd'.
But be careful, that will open a shell for 'root' user.
Came across this weird error:
This had happened because I had RSpec 1 way of including spec_helper (in old files):
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
And the other way (in my new files):
require 'spec_helper'
Synching them fixed it :))
While pushing my rails application on heroku I stumbled across a weird error.
Here are the steps:
To look into details of the error, lets dig deep. Below are the steps I followed to resolve the issue.
My Ruby Conf 2011 presentation:
At speakerdeck:or at slideshare
Just released code to create inverted Organization Chart -->
library here
Check out how to generate stacked waterfall charts using highchart js library.
Update: the chart extension has evolved to produce waterfall charts with bubbles superimposed:
Just committed JS extension to create Waterfall charts
Look at
here for details
If you ever want to disable generating rdoc and ri when you install a ruby gem:
Add this to your
~/.gemrc:
install: --no-rdoc --no-ri
update: --no-rdoc --no-ri
Devise has become the de-facto library if you ever need Authentication. Tonnes of pluggable components which you can easily enable/disable.
For our application we had to reset session and easiest and cleanest way to do was to extend the devise - SessionsController:
For testing this piece:
With smiling face I ran the spec buuuuuuttttttttttttttttt arrrrggghhhh:
AbstractController::ActionNotFound
Checking the devise filters helped with some direction:
Have fun !!
I was working on migrating an existing Rails 2 app to Rails 3. And I came across a weird issue. All my controller specs started to fail with error - route not found even though all my routes were in place.
After some more reading in the rails routing module - found it overwrites the routes if you open the block and pass on extra routes
Hope this will save few hours of your development :))
I wanted to quickly check the callbacks that my controller has in my new Rails 3 application. With more abstraction in Rails 3 (AbstractController) - the easiest way I found was:
Other ways to do ?
Today I was trying to connect to SQL Server from my OSx Mac and I was getting "
Unable to connect: Adaptive Server is unavailable or does not exist".
I was able to connect to another sql server in the same farm from laptop.
Found out by default --> TCP connectivity is disabled for SQL Server.
Microsoft SQL Server 2008 R2 > Configuration Tools > SQL Server Configuration Manager > SQL Server Network Configuration > Protocols for MSSQLSERVERProtocol Name: TCP/IP (Enable)Thats all :))
Ken Collins from EngineYard released
TinyTds, a ruby gem that uses dblib to connect to MS SQL server. It has no hassles of managing ODBC connection. Read the
blog for detailed explanation.
Before TinyTDS:
The steps for setting libraries to connect to MS SQL on *nix environment. Follow the steps religiously to succeed.
Enter TinyTDS:
TinyTDS helps ODBC-less connection which means no pain of installing all the ODBC libraries.
It took a min to set-up the connection using the steps.
Goodies: Steps on Mac OSx Snow Leopard
We have been using "
Capistrano" to automate the deployment of our Rails apps. Capistrano is very powerful helps to execute any command on the remote machines. It has before/after "callback" hooks that helps to execute commands your application might depend on before running "cap deploy".
Capistrano assumes all the remote machines have the same credentials. Imagine you want to run commands on different remote machines each having different credentials.
Added a small extension for capistrano to prompt for password again when connecting to another server.
Drop the code in your
Rails.root/lib directory.
You will have to add:
in you recipes to force capistrano to prompt.
Bonus: Create ssh public keys and enjoy password-less deployment.
Next step: fork capistrano to add method for connecting to multiple servers
Just wanted to quickly share the awesome new ActiveRecord Relational Algebra. I am sure there are many others but this one is a gem.
For long conditions like these:
Post.where("(body like ? OR subject like ?) AND comment_count > ? AND created_at > ?", criteria, criteria, 5, 3.days.ago)
It becomes really difficult to match the order of parameters.
Welcome to ARel, the same query can be written as:
Post.where("(body like :criteria OR subject like :criteria) AND comment_count > :count AND created_at > created_date", :criteria => criteria, :count => 5, :created_date => 3.days.ago)
See the binding variables in place of hard to remember question marks. It is important to note, in case the same variable is repeated multiple times, passing the variable once is sufficient.
More goodies to come !!
Run the 'bundle install' command on your terminal and wait for bundler to install the gems. It is pathetically slow.
It appears that RubyGems is slow. This is because of how Rubygems manages index of gems . It has 3 indexes:
1) Index of new version of the gem
2) Index of all the versions
3) Index of pre release
Doing "gem install
, fetches the index of the latest version of the gem. Apparently, bundler downloads #2, all the indexes. These indexes are gzipped and Marshal'd array of gem name, version and platform. Parsing this huge array is the first spot of slow down.
Now as we know bundler has intelligent algorithm for dependency management, which means when we do "bundle install", it will install all dependencies of the gem. This is achieved via .gemspec file which bundler downloads unzips and "UnMarshal's".
To reduce the slowness there few options, lets explore them:
1) "bundle pack" the .gems inside vendor/cache - force bundler to install from local cache then going across the wire
2) have your gems in "Gemfile" to be locked to a version or use PessimisticVersionConstraint.
I have used a combination of both and found substantial improvement in the time taken by "bundle install/update".
There are few other options like - MirrorBrain, rubygems-mirror, murder etc. Keeping a watch on gemcutter mailing list for better ways of doing this.
Today while doing "bundle update" my server started to throw weird error.

Somehow I was not able to relate it to bundler and doing
# gem update
updating installed gems
ERROR: While executing gem … (ArgumentError)
marshal data too short
explained that gem specs on the server is corrupted. I still need to figure out the reason why that happened in first place.
This error kept popping up – no matter what commands I wanted to run with rubygems (update, update –system, install…)
Googling did not give any solution on this topic. I had a feeling it is messing with ~/.gems directory - and found out to be true.
I deleted all entries inside the ~/.gems directory. I had to just just reinstall all my gems.
Any better ways to solve this problem ?
https://gist.github.com/887350
You will run into this issue if you are using:
Mysql -> 5.5.x
rake db:create --trace
(in /Users/toamitkumar/development/rails_apps/mongotimeline)
** Invoke db:create (first_time)
** Invoke db:load_config (first_time)
** Invoke rails_env (first_time)
** Execute rails_env
** Execute db:load_config
** Execute db:create
rake aborted!
uninitialized constant Mysql::Error
spent 2 hours to figure out the issue is with 64 bit architecture on OSx. It is not able to find dynamic library libmysqlclient. Making the following entry in .bashrc file and then installing the mysql gem again solved the problem.
export DYLD_LIBRARY_PATH="/usr/local/mysql/lib:$DYLD_LIBRARY_PATH"
$ sudo env ARCHFLAGS="-arch x86_64"
$ gem install --no-rdoc --no-ri mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
Rock on !!
Bundler is a great tool which helps to manage your application dependencies. It is very simple to use, just drop it and you are good to go with one command -> bundle install
Check out: http://gembundler.com/, if you care.
The problem occurs when it fails to install a gem. It does not have a way to show the trace of stack calls like rake --trace.
Let me tell you the problem - I was moving a Rails 2.3.9 project to use bundler. The application is using libxml-ruby for XML parsing (yes I know nokogiri fans - @tenderlove did a wonderful job).
The Gemfile entry:
gem 'libxml-ruby'
$ bundle install
and bundler tries to install the native extension (dependencies on zlib, libxml, iconv). I downloaded all the .dll's and copied them to Devkit.
$ bundle install
The same failure.
The nice bundle.config command:
$ bundle config build.libxml-ruby -- --with-zlib-dir=/path/to/zlib --with-zlib-include=/path/to/zlib/include --with-zlib-lib=/path/to/zlib/lib --with-iconv-dir=/path/to/iconv --with-iconv-lib=/path/to/iconv/lib --with-iconv-include=/path/to/iconv/include --with-xml2-dir=/path/to/libxml --with-xml2-lib=/path/to/libxml/lib --with-xml2-include=/path/to/libxml/include
$ bundle install
and I started to see the gem building, and then NOOOOO, version mismatch of the DLLs. I spent hours figuring out which are the compatible versions.
And then,
@niranjan suggested: this entry
$ bundle install
all worked, sweet !!
Concurrency in Rails - a bug that bit me few weeks back. This led me to read in detail about "Reactor Pattern" (EventMachine, Twisted, Node.js) and making requests asynchronous.
Let me take a step back and tell ya what made me read all this.
Think about if, you had to solve a problem of making multiple service calls to complete a response. Doing this sequentially is "old" architecture, where you did not care much about performance. One can definitely argue, why not cache the beast !
Well,
- what if the data is dynamic
- what if I care more about CPU Utilization.
Every service requires I/O and everyone knows I/O is blocking. So, while waiting for the request to complete, CPU sits idle doing nothing. It could have fired another service call. This is more easy to say then to solve . This is where evented programming becomes very helpful. Consider all service calls as events which you can register for callbacks. You fire them all together and wait for them to complete. But now these events (ruby threads) compete for CPU cycle (yeah for obvious reasons - green thread). The threads are preempted by OS and there is no way you can control this.
Ruby 1.9 introduced this powerful concept of Fibers - of creating code blocks which can be paused and resumed by application developer. So, we can control when to pause and resume the execution ?? yeah
Moreover they are cheap to spin off new as compared to threads.
So, to achieve concurrency, we can fire fibers as events, each fiber responding back to callbacks.
All sweet !!
Wrote a nice Rails app ->
fibered-railsGoing to talk about this in our TCS Rails Conf'11 on 02/17/2011 - see the talk
here
Google steps into the world of micro-blogging ....
Rest of the micro-blogging players hide out...
Wanna try -> here
See the video to help yourself...
Well its been long I blogged but better late than never... :)))
Been busy with projects, visit to India etc etc ... I can come up with a long list of excuses but none of them will be procrastinating ... hehehe
I forced my self out of hibernation to blog about a recent (strange ??) problem I faced.
In one of my projects, I came across a fairly common requirement to upload a file (multipart form-data post) through a ruby script. Pretty simple huhhh!
Unfortunately I was stumped to find that net/http library does not support it (still dont believe it!!). The documentation is very poor and it took me sometime to figure out net/http treats them all as string. CRAP !!!.
Some nice libraries eg: rest_client, httpclient, curb etc.. do a decent job in terms of posting the file, but they all mess with either creating incorrect boundaries for multi-part form or mess with content_length header of form-post
My requirement was to make http post call (multipart form data post) to Domino server. The domino app was very particular about content_length header, which is where I faced the biggest hurdle in using them.
Left with no choice, rolled up my sweet multipart form post.
Sharing with you all ruby-multipart-post.
How to use ==> here
Any feedback, most welcome ...
Enjoy !!!
Goggling about some Ruby thing, I came across a nice article on Marketing Tips. I was forced to share these beautiful thoughts ....
http://www.webdesignerdepot.com/2009/07/9-marketing-tips-from-a-six-year-olds-lemonade-stand/
One more pain when coding on windows (as if I was born using Unix/Linux etc ;)))... but try installing a plugin -
ruby script/plugin install git://github.com/toamitkumar/extra_sanitize.git
and it will fail with an empty folder.
After googling found a way -> here which suggests using http instead of git protocol.
ruby script/plugin install http://github.com/toamitkumar/extra_sanitize.git
Well this also failed with an empty folder. After hours of struggling found adding a trailing forward slash to the url did the trick.
ruby script/plugin install http://github.com/toamitkumar/extra_sanitize.git/
It works now....