Getting Started With Redis in Ruby

Redis is an open source, BSD licensed, advanced key-value store. It is often referred to as a data structure server since keys can contain strings, hashes, lists, sets and sorted sets.

To get started first we need is gem 'redis'. Open up irb console. Now working with redis is as simple as :

require 'redis'

redis_connection = => 0)
=> #<Redis client v3.0.7 for redis://>

redis_connection.set("key", "value")
=> "OK"

=> "value"

=> 1

=> nil # As we have delete the key value from redis memory.

By default our redis connection is connected to localhost, but we can specify the server ip where we want redis connection to be established.

redis_connection = => 0, :host =>

Make sure redis on is running and accepting connections from outside , other than localhost.

For more detailed list of commands for redis check here.

May 3rd, 2014

Can't Find ModelName With Id = 12345

Very often we use Callbacks to perform several actions after creation of a record. Also sometimes make a queue for SideKiq workers to work on. Let’s assume a model User.

class User < ActiveRecord::Base

  # ===== Call Backs ==== #
  after_create :do_some_action

  def do_some_action

Read on →

Set-up Guide for Rails Server on Ubuntu

Create a ubuntu 13.04 machine at desired hosting. I prefer using Digital Ocean for me.

After creating machine, login with root user.

ssh root@

Create a user named deploy with sudo permission. We will use this to carry out all operation instead of using root user. Also choose a strong password for your user.

sudo useradd -s /bin/bash -m -d /home/deploy  -g root deploy
sudo passwd deploy
sudo usermod -a -G sudo deploy

Logout from your server and run the following command to copy your ssh keys.This will allow you to do a passwordless login via ssh.

ssh-copy-id deploy@
ssh deploy@
Read on →
Apr 12th, 2014

Execute Sudo Commands Without Password Prompt

Executing sudo commands always require password after the command such as :

sudo service apache2 restart

To make it run we can add this to our whitelist where we dont have to input password everytime. Follow the following steps :

sudo touch /etc/sudoers.d/custom_permissions
echo "user_name ALL = (root) NOPASSWD: /etc/apache2" >> /etc/sudoers.d/custom_permissions
# you can use vi or some other editor also
sudo chown 0440 custom_permissions

NOPASSWD tells that password should not be prompted in case of this command execution. We can also add multiple commands using

user_name ALL = (root) NOPASSWD: /etc/apache2, /etc/nginx, /path/to/command, /path/to/another/command

Now all four commmands given above are executed without any password confirmation. We can mark all sudo commands by :


Be careful while doing this. Proceed with caution. Incase of some issue contact here.

Mar 29th, 2014

Dancing Quick Sort

Watch on youtube

Mar 22nd, 2014

Getting Started With Javascript Plugins

One can get started with creating javascript plugins easily. A to do guide for creating a simple pliugin is given here.

$.fn.reddish = function() {
  this.css( "color", "red" );

This defines the plugin. It will add red colour to any element on which reddish method will be called.

Read on →
Mar 14th, 2014

Checkout to a Branch on Local Machine Linked With Same Branch on Remote Origin

We can know all the existing branches of any project by git branch -a. It gives output something like

* master
remotes/origin/HEAD -> origin/master
  • `* master` tell the current branch.
  • Branch names starting from `remotes` tell us that branch is at remote server.
  • Branch name with `->` tells us to which remote branch local branch is mapped with.

Now to create a new local branch mapped with remote branc, assuming remotes/origin/master-some_another_feature_branch do

git checkout -b master-some_another_feature_branch origin/master-some_another_feature_branch

Now the new local branch is created, mapped with remote branch.

Mar 7th, 2014

Check if a Port Is Open on a Remote Server

Simply do

nc -z -w 200 6379; echo $?


nc -z -w 200 6379; echo $?

If it returns 0 that means port is open, if 1 port is closed.

This takes a little bit of time. Be patient :)

Feb 28th, 2014

Pull and Push Code From Different Repositories

A git repository has a remote origin where the code is pushed regularly. By default we have one remote origin. But some cases may require different origins e.g. My blog has its remote origin set to heroku. Comamnd

git push origin master
git push heroku master

Because both are pointed to same origin as we can see from

git remote -v show
heroku (fetch)
heroku (push)
origin (fetch)
origin (push)

Now, I want to keep a backup of everything apart from hosting on heroku lets say on my bitbucket repository. Simply add another

git remote add origin2

resultant is

git remote -v show
heroku (fetch)
heroku (push)
origin (fetch)
origin (push)
origin2 (fetch)
origin2 (push)

Now, code can be pushed to git repository hosted at bitbucket via

git push origin2 master

Happy Gitting :)

Feb 23rd, 2014

Map Remote Server Directories to Local Ubuntu Machine

At times we need to perform a number of actions on directories of remote server. For that either we use ssh or we do scp. Another good alternate is mapping the remote server directory to our local machine. Lets get started with

sudo apt-get install sshfs
Read on →
Feb 21st, 2014