Batch clean up of local git branches

I usually add an alias in my .zshrc file so that I can run a single command to clean up feature branches that are merged into master or develop.

alias gbclean="git branch --merged | egrep -v '(^\*|master|develop)' | xargs git branch -d"

But if you run:

git branch --merged | egrep -v '(^\*|master|develop)' | xargs git branch -d

This will remove all branches that are merged into master or develop.

How to speed up bundle install on a Mac

Most new laptops/computers come with multiple cores standard.

So assuming you do have a system with multiple cores why not use them.

# How many cores are on your system?
> sysctl -n hw.ncpu
> bundle config --global jobs 24

* This might work on any *nix system just find the appropriate commands.

Creating a new rails app

How to create a new project withouttest unit and with postgresql database

# in shell

rails new myapp -T --database=postgresql

# edit Gemfile and add: rspec, haml, etc.
gem 'rspec-rails'
gem 'haml'
gem 'haml-rails'
gem 'factory_girl_rails'

bundle install

# init rspec
rails generate rspec:install

# convert layout to haml
rails generate haml:application_layout convert


My grep commands

When I search for things in my codebase I find that using the terminal and grep is usually the best option. Here is what I usually run:

# find meng in all files under a specific directory

# switches i - case insensitive, r - recurrsive, H - show file and path, n - line number
grep -irHn 'meng' current/

# you can count using c
grep -irc 'meng' current/

# you can use regex
grep -ire ^d current/
# search files in current direct for any line that starts with d or D
# make sure e is an the end for example I want line numbers
grep -irne ^d current/

# to skip binary files use I (uppercase i)
grep -iIHrn 'meng' current/


Learn how to use top command in linux

I find myself using this often while debugging errors or trying to figure why a server is slow or unresponsive.

# show all processes

# to quit top type q
# to sort press Shift+O
# K for cpu % or use Shift+P

# show all processes from a specific user
top -u username

# example for me using deployer as the user to run web processes
top -u deployer

# highlight working process

# show path for process

# kill pid

# get help


Vagrant Boxes / VMWare Fusion / CentOS 7

Use one found here: you can use one of those to build upon or you can create one.

These steps are if you want to to create a fresh box.
Grab the latest CentOS image here:

I use the minimal image

First you need to create a VM using Fusion.

  1. Select “Install from disc or image” >> Continue
  2. “Use another disc or disc image” >> Find your iso >> Continue
  3. Uncheck “Use Easy Install” make sure “Make your home folder accessible to the virtual machine is unchecked. >> Continue
  4. Click “Customize Settings” >> Rename your vm and place it somewhere safe.

Continue reading “Vagrant Boxes / VMWare Fusion / CentOS 7”

Nginx / Comodo PositiveSSL / CentOS 7

1. Before you purchase your SSL

Before any purchase of an SSL you’ll need a key file and a csr (Certificate Signing Request).

# I always assume you are logged in as root
# ssh into server and run
openssl req -nodes -newkey rsa:2048 -keyout server_name.key -out server_name.csr

# you have now generated 2 files server_name.key and server_name.csr

cat server_name.csr

The certificate registrar is going to ask for the contents of your csr file, just cut and paste whats inside the file into the webform. Make sure you register with the domain name you plan on using. Purchase your SSL, they’ll send your administrator an email validate that. Then wait for an email from Comodo with a zip file.

Within this zip file you’ll receive 4 files:

  • AddTrustExternalCARoot.crt – Root Cert
  • COMODORSAAddTrustCA.crt – Intermediate Cert
  • COMODORSADomainValidationSecureServerCA.crt – Intermediate Cert
  • server_name.crt – Your Positive Cert

2. Prep for installing SSL Cert

# combine your crt files into a bundle for nginx

cat server_name.crt COMODORSADomainValidationSecureServerCA.crt COMODORSAAddTrustCA.crt AddTrustExternalCARoot.crt >> server_name.ssl_bundle.crt


# you should have server_name.ssl_bundle.crt
# copy files into place (you can move mv or copy cp files)
cp server_name.ssl_bundle.crt /etc/ssl/certs/server_name.ssl_bundle.crt
mkdir /etc/ssl/private
cp server_name.key /etc/ssl/private/server_name.key

3. Installing the SSL Certificate

Now to configure Nginx.

    server {
        listen       ip_address:443;
        server_name  example_com;

        ssl on;
        ssl_certificate      /etc/ssl/certs/server_name.ssl_bundle.crt;
        ssl_certificate_key  /etc/ssl/private/server_name.key;

        ssl_session_cache    shared:SSL:1m;
        ssl_session_timeout  5m;

        ssl_protocols   TLSv1 TLSv1.1 TLSv1.2;

        ssl_ciphers  ALL:!aNULL:!ADH:!eNULL:!LOW:!EXP:RC4+RSA:+HIGH:+MEDIUM;
        ssl_prefer_server_ciphers  on;

        location / {
            root   /html;
            index  index.html index.htm;

4. Restart Nginx

service restart nginx

To test your ssl: