Tuesday, August 06, 2013

Sunday, July 21, 2013

Three Rules of TDD

Notes from Bob Martin's screencast:

1. Write the test first.
2. Write only enough of a test to demonstrate a failure.
3. Write only enough of production code to pass the test.

Friday, July 12, 2013

iomega external drive is not showing up on Mac OS

1. In a terminal run : sudo chflags nohidden /Volumes/*

Since I did not know the name of my iomega drive I used the wildcard * instead of the name for the external drive.

2. Unplug the power to the external drive and connect it back to your Mac.

It should work now.

Monday, July 01, 2013

How to Setup Amazon Cloud Front in Rails 3.2 app


I bought my domain at namecheap.com. It is hosted at Linode.

Step 1 : I used Linode control panel to create a CNAME. It looks like this:

CNAME Records
Hostname Aliases to TTL
cdn amazon-provided-id.cloudfront.net Default
www clickplan.net Default

Step 2 : Go to Amazon Cloud Front and setup a CDN distribution. I followed the instructions from this blog: http://happybearsoftware.com/use-cloudfront-and-the-rails-asset-pipeline-to-speed-up-your-app.html

Note that you should also provide alternate domain name. In my case it was cdn.clickplan.net.

Step 3 : In production.rb add :

  config.action_controller.asset_host = "amazon-provided-id.cloudfront.net"

You can also setup a CNAME like cdn.yourdomain.com to point to amazon-provided-id.cloudfront.net. I am using https for the entire site. Since I did not have wildcard SSL certificate, it did not work so I am using https://amazon-provided-id.cloudfront.net for now. Amazon also has a documentation that shows how to use SSL with your cname. If you have issues, make sure you clear all the history in the browser and hit the URL to see if you can view the css and javascript.

Monday, June 03, 2013

Friday, May 31, 2013

How to control the order of css file inclusion in Rails 3.2 asset pipeline?

In your application.css remove the require_tree .
Then add the css files one by one in the order you would like it to be included in the html. Like this:

*= require_self
*= require 'form'
*= require 'layout-fix'

and so on. Just leave the require_self as it is. For a detailed explanation: RAILS ASSET PIPELINE HANDLING OF CSS & JS 

Wednesday, May 29, 2013

NoMethodError: undefined method `y' for main:Object

If you want to use the y method to inspect an object in yaml format. Whenever you bring up rails console in development, you can inspect any object.  Just add the following line to your development.rb:

YAML::ENGINE.yamler = 'syck'

How to print text in green in Ruby

text = "This is a test"
irb > print "\033[32m#{text}\033[0m"
This will print the text in green.

NoMethodError: undefined method `buckets' for :AWS::Core::Configuration

Resolution: Use the constructor version of S3 : s3 = AWS::S3.new('your credentials')

Tuesday, May 28, 2013

ignoring config/database.yml

If you already have the config/database.yml file in the repo and you want to ignore it. Follow these steps:

1. Add : config/database.yml to .gitignore file.
2. Rename database.yml to database.yml.sample
3. Check in the changes.
4. Now git will ignore the database.yml that you create in your project.

Keeping Security Credentials Out of Source Code Repository

Moonshine is supposed to keep the file in the shared folder and symlink it to the file under current project folder just by adding one line to the config/moonshine.yml

:shared_config
  - config/amazon_s3.yml

For some reason it created the symlink but it did not upload the file. I had to manually do it by :

cap shared_config:upload

on my laptop. On initial setup it actually worked for database.yml. I think it is because of cap deploy:setup command. Remember to add the config file to the .gitignore file so that it does not get checked into the repo.

Sunday, May 26, 2013

Consuming Webservices deployed on Google App Engine from Rails


Google App Engine is very attractive for exposing services that needs to be up and running 24x7 and scale automatically based on demand. Rails apps can consume RESTful services developed using Google Cloud Endpoints. Even though Google Cloud Endpoints is experimental,  platform developers will find very compelling. Any platform that can make a http request can consume the services.

1. Using OAuth 2.0 for Server to Server Applications
   
2. Google APIs Client Library for Ruby
Here is the github repo :  https://github.com/google/google-api-ruby-client

3. Code to Cloud in under 45 minutes

4. Slides from 18 to 34 from Pycon2013

5. Google Cloud End Points sample project
 
6. Python End Points

7. OReilly Webcast : Python for Google App Engine



The absolute uri: http://www.oracle.com/technetwork/java/javaee/jsp/index.html cannot be resolved in either web.xml or the jar files deployed with this application


To get the guestbook.jsp App Engine example working replace the tag library fn as follows:
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>

Monday, May 20, 2013

Error: Cannot find module 'npmlog'


1. npm install -g yo grunt-cli bower gives the error:

Fix : sudo curl https://npmjs.org/install.sh | sh

How to upgrade Node.js


1. Check the version :  $node --version
   output will be like : n@0.9.3 /usr/lib/node_modules/n

2. To upgrade, run : $n 0.9.3
where, 0.9.3 is from the output of step 1.

Open a new terminal and type: $node --version
You should see the upgraded version.
   

Friday, May 17, 2013

SQLite3::BusyException: database is locked: ROLLBACK TO SAVEPOINT active_record_1

Caused SQLite3 to lock due to bug in a test. To fix:

1. ps -a | grep ruby
2. kill -s 9 12345

12345 is the process id that is the zombie rspec process.