Wednesday, March 14, 2012

Ruby and RoR Course with exercise

@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.md

Course 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-developers

More resources: http://code.dblock.org/crafting-a-ruby-on-rails-course-for-developers

It is CDE --> Community Driven Education :)





Sunday, March 11, 2012

File download indicator in browser

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 lost
  • Ajax 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 cleanup
  • Iframe 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 cookie

The third approach has helped in solving for the following:
1. Submit a JSON request to the server
2. Show/Hide a "waiting" indicator
3. Controlling the timeouts and indicate the user of delays (if any)
4. File download handle

Let me know if there are other ways of making it work.

Tuesday, December 13, 2011

sudo: cd: command not found

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 bash

and then 'cd'.

But be careful, that will open a shell for 'root' user.

Tuesday, November 29, 2011

RSpec::Core::Configuration::MustBeConfiguredBeforeExampleGroupsError

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

Saturday, November 26, 2011

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

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.






Friday, September 16, 2011

Saturday, May 14, 2011

Waterfall chart with Line Connectors

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

Sunday, May 8, 2011

Install rubygems without rdoc/ri

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




Wednesday, May 4, 2011

Micro-Blogging Solution for the Enterprise

Testing Extended Devise Controllers

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

Adding routes to rails3 - rspec2 (controller tests)

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

Monday, May 2, 2011

Inspect Rails 3 routes in "console"

Rails 3 and Controller Callbacks - demystified

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 ?


Friday, April 29, 2011

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

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 MSSQLSERVER

Protocol Name: TCP/IP (Enable)

Thats all :))




 


Monday, April 11, 2011

Connecting to SQL Server from Linux/Suse/Snow Leopard

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