Logo

Who is talking?

Archive

Ruby and RoR Course with exercise

over 5 years ago | Amit Kumar: RubyizednRailified

@engineyard and @pivotallabs release an excellent course material and exercise for Ruby and Ruby on Rails.It is one of the best I have seen so far. Quotes from the repo: "This course teaches experienced developers Ruby and Ruby-on-Rails. It's designed to be taught by a practicing rubyist and a teaching assistant. Both individuals must have expert understanding of Ruby, Rack and Ruby-on-Rails." The list of contributors: https://github.com/generalassembly/ga-ruby-on-rails-for-devs/blob/master/CONTRIBUTORS.mdCourse is structured to cover all the platforms (Linux, Mac and yesss Windows). It starts with basics and covers some advanced development guidelines.An excellent presentation by @dblockdotorg: http://www.slideshare.net/dblockdotorg/crafting-a-rubyonrails-course-for-developersMore resources: http://code.dblock.org/crafting-a-ruby-on-rails-course-for-developersIt is CDE --> Community Driven Education :)

File download indicator in browser

over 5 years ago | Amit Kumar: RubyizednRailified

For last few days I have been struggling with a requirement to show file download indicator. Here's the requirement.Web page has a link "Download File". On click of this link - a JSON post request is sent to the server. The server generates the files based on the JSON input and streams back with Content-Disposition "attachment" for the browser to download. There are several ways to visually indicate the click of the link:Normal form post - Create a dynamic form and post it. On the server-side make sure content disposition is set to attachment. When browser receives the response, it pops the "Open-Save-Cancel" dialogue box.            Cons:               - No control of the page response time, page dies in case of timeouts               - Page refreshes and the current context of the user is lostAjax post - Do an Ajax form post with JSON data. Download "waiting" indicator can be easily initiated with "Ajax prefilter". In the response from the server send back the URL to download. Remove the "waiting" indicator. Change the window location to the URL and let the browser do the rest.            Cons:               - Retain the file on the server and run a background cleanupIframe post (recommended solution) - Create a dynamic form and post (target of the form) it to an iframe. Disable the download link, show the "waiting" indicator. Start the timer and look for presence of a cookie. If the cookie is found, remove the indicator and enable the link. This requires some server side code as well: adding the cookie. The detailed sample code:                              The client side code:                            The server-side code:                           Cons:               - Server has to set an extra cookieThe third approach has helped in solving for the following:1. Submit a JSON request to the server2. Show/Hide a "waiting" indicator3. Controlling the timeouts and indicate the user of delays (if any)4. File download handleLet me know if there are other ways of making it work.

Invalid gemspec in” and “Illformed requirement”

over 5 years ago | Amit Kumar: RubyizednRailified

If you have to solve the problem:

sudo: cd: command not found

over 5 years ago | Amit Kumar: RubyizednRailified

Ever tried this:Weird isn't it ?I checked the "/etc/sudoers" and everything looked normal:toamitkumar   ALL = (ALL) NOPASSWD: ALLI 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.

RSpec::Core::Configuration::MustBeConfiguredBeforeExampleGroupsError

over 5 years ago | Amit Kumar: RubyizednRailified

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 :))

! No such app as radiant-cloud-8241. (Heruko)

over 5 years ago | Amit Kumar: RubyizednRailified

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.

Big Data Enterprisey Analytics and Ruby

over 5 years ago | Amit Kumar: RubyizednRailified

My Ruby Conf 2011 presentation:At speakerdeck:or at slideshare Ruby conf'11 View more presentations from toamitkumar

Building JS Org Chart

almost 6 years ago | Amit Kumar: RubyizednRailified

Just released code to create inverted Organization Chart --> library here

Stacked waterfall charts in highcharts

about 6 years ago | Amit Kumar: RubyizednRailified

Check out how to generate stacked waterfall charts using highchart js library.

Waterfall chart with Line Connectors

about 6 years ago | Amit Kumar: RubyizednRailified

Update: the chart extension has evolved to produce waterfall charts with bubbles superimposed:Just committed JS extension to create Waterfall chartsLook at here for details

Install rubygems without rdoc/ri

about 6 years ago | Amit Kumar: RubyizednRailified

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-riupdate: --no-rdoc --no-ri

Testing Extended Devise Controllers

about 6 years ago | Amit Kumar: RubyizednRailified

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::ActionNotFoundChecking the devise filters helped with some direction:Have fun !!

Adding routes to rails3 - rspec2 (controller tests)

about 6 years ago | Amit Kumar: RubyizednRailified

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 routesHope this will save few hours of your development :))

Rails 3 and Controller Callbacks - demystified

about 6 years ago | Amit Kumar: RubyizednRailified

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 ?

[freetds] tsql Unable to connect: Adaptive Server is unavailable or does not exist

about 6 years ago | Amit Kumar: RubyizednRailified

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 :)) 

Connecting to SQL Server from Linux/Suse/Snow Leopard

about 6 years ago | Amit Kumar: RubyizednRailified

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

Extending "Capistrano" to prompt for password when connecting to multiple servers

about 6 years ago | Amit Kumar: RubyizednRailified

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

Binding Variables in ARel

about 6 years ago | Amit Kumar: RubyizednRailified

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 !!

pathetically slow "bundle install"

about 6 years ago | Amit Kumar: RubyizednRailified

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 gem2) Index of all the versions3) Index of pre releaseDoing "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 wire2) 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.

marshal data too short - rubygems error

about 6 years ago | Amit Kumar: RubyizednRailified

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 shortexplained 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 ?