Leave a comment

Count the Users total commits from git

Here is the command to list all the users with their git commits

$ git shortlog -s -n

and output will be in following fromat

commit_count   user_name

Leave a comment

encoding::UndefinedConversionError: U+00C2 from UTF-8 to US-ASCII in Unbuntu Linux

This is an error due to the some locale language package inavailable in your linux system

You can check the list of locale in your system by following command

sudo locale -a

Then You can re-generate the locale for your system using commande

 sudo locale-gen

and this will solve your Encoding issue :)
1 Comment

Get Sum of field from associated table in Rails/Mysql

Sometime you have relationship like  campaign has_many causes and need to calculate sum of raise_amount raised from each campaign from the associated table

In mysql this can be done by a simple query

select campaigns.name,SUM(raises.raise_amount) as total_sum FROM campaigns LEFT OUTER JOIN raises ON campaigns.id=raises.campaign_id GROUP BY campaigns.id;

In Rails it can be achieved by this query

Campaign.joins(“LEFT OUTER JOIN raises on campaigns.id = raises.campaign_id”).group(“campaigns.id”).order(“SUM(raises.raise_amount) DESC”)

it takes a couple of hours to figure it out. might it save others time.


Leave a comment

How to get size of mysql database in MB ?

Run this query and you’ll get the size of databases in MB


SELECT table_schema "DB Name", 
 Round(Sum(data_length + index_length) / 1024 / 1024, 1) "DB Size in MB" 
FROM   information_schema.tables 
GROUP  BY table_schema; 
Leave a comment

Error While starting Postgres in ubuntu

Getting following error while trying  to start postgres

* The PostgreSQL server failed to start. Please check the log output:
2013-05-29 14:29:02 IST FATAL: could not create shared memory segment: Invalid argument
2013-05-29 14:29:02 IST DETAIL: Failed system call was shmget(key=5432001, size=39321600, 03600).
2013-05-29 14:29:02 IST HINT: This error usually means that PostgreSQL’s request for a shared memory segment exceeded your kernel’s SHMMAX parameter. You can either reduce the request size or reconfigure the kernel with larger SHMMAX. To reduce the request size (currently 39321600 bytes), reduce PostgreSQL’s shared memory usage, perhaps by reducing shared_buffers or max_connections.


The simple solution for above problem is

go to /etc/sysctl.d/30-postgresql-shm.conf  file and  add or change this line in the file

kernel.shmmax = 41943040

and then run the command sudo sysctl -p

now you can start your postgres 🙂

Leave a comment

Install Rails Passenger Module on Apache2.4

I tried to install passenger-install-apache2-module and getting error :

Apache2 headers not found.

its seems that Passenger is not getting a Path of an Apache2.4 to solve this.,

we need to export these ENV into bash

export HTTPD="/usr/local/apache2/bin/httpd"
export BINDIR="/usr/local/apache2"
export APXS2="/usr/local/apache2/bin/apxs"
export APR_CONFIG="/usr/local/apr/bin/apr-1-config"
export APU_CONFIG="/usr/local/apr/bin/apu-1-config"

or we can Direct pass the path as

passenger-install-apache2-module --auto --apxs2-path=/usr/local/apache2/bin/apxs --apr-config-path=/usr/local/apache2/bin/apr-1-config
Leave a comment

Invalid multibyte char with Ruby 1.9

When I deployed the code to a server I got the error

Invalid multibyte char US-ASCII

So I noticed the my local version in ruby 1.8 where its working fine and on ruby.9 its throwing an exception,

so for that just I out this line

# encoding: utf-8

to start of the file where I got the error and Problem Resolved 🙂