Skip to content

Instantly share code, notes, and snippets.

View davidchua's full-sized avatar

David davidchua

View GitHub Profile
# ~/.bashrc
# for git branch display on bash
# -- START ---
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
function proml {
PS1="\u@\h:\w\[\033[0;32m\]$(parse_git_branch)\[\033[0;0m\]> "
Workflow:
1) Do a git pull to ensure your master is having the latest copy
2) Create a new branch with the command
git checkout -b <branchname>
"I'd normally name the branchname something in relation to the task at hand, this is supposed to make your life easier."
namespace :db do
desc "Backup database to #{RAILS_ROOT}/db/backup"
task :backup => :environment do
max_backups = (ENV["MAX"] || 14).to_i
timestamp = Time.now.strftime("%Y%m%d_%H%M%S")
backup_folder = File.join("db", "backup")
backup_file = File.join(backup_folder, "#{RAILS_ENV}_dump_#{timestamp}.sql.gz")
FileUtils.makedirs(backup_folder)
db_config = ActiveRecord::Base.configurations[RAILS_ENV]
command = "mysqldump -u #{db_config['username']} -p#{db_config['password']} --default-character-set=utf8 --single-transaction --quick #{db_config['database']} | gzip -c > #{backup_file}"
#!/bin/bash
#
# Homepage: http://www.debian-tutorials.com
# Email: contact@debian-tutorials.com
# Bash script to download and install or upgrade wordpress to specified directory.
install_wp ()
{
cd ~</pre>
<!--more-->
<pre>
@davidchua
davidchua / zerigo_to_aws_route53.rb
Last active February 22, 2017 20:19
quick and dirty ruby script to copy dns from zerigo to amazon aws route 53 (route53). allows users to migrate ALL zones from zerigo over to Route53
#!/usr/local/rvm/rubies/ruby-1.9.2-p180/bin/ruby
require 'rubygems'
require 'zerigo_dns'
require 'route53'
Zerigo::DNS::Base.user = 'username@email.com'
Zerigo::DNS::Base.api_key = 'yourkeyhere'
# iterate through all domain names
@davidchua
davidchua / deploy.rb
Last active December 11, 2015 07:29
Default Capistrano Script to get Started - Git - RVM System
load 'deploy/assets'
require "bundler/capistrano"
set :application, "some_web"
set :repository, "git@somedomain.com:whatever.git"
set :deploy_to, "/home/ubuntu/some_web"
set :user, 'ubuntu'
set :use_sudo, false
@davidchua
davidchua / nginx-init
Created March 15, 2013 06:33
Working NGIX init.d script to be placed in /etc/init.d/nginx
#! /bin/sh
### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the nginx web server
# Description: starts nginx using start-stop-daemon
@davidchua
davidchua / non-us-s3-buckets
Created March 15, 2013 07:20
Modify ~/.s3cfg after installing s3cmd and running s3cmd --configure. This solves Errno 32: Broken Pipe error when trying to push a file to a non-US S3 bucket.
# in ~/.s3cfg
# modify host_base and host_bucket to the proper endpoints
host_base = s3-ap-southeast-1.amazonaws.com
host_bucket = %(bucket)s.s3-ap-southeast-1.amazonaws.com
@davidchua
davidchua / non-rails-deploy.rb
Created March 21, 2013 01:07
Capistrano Deploy Recipe for Non-Rails App (PHP/HTML)
set :application, "<name>"
set :repository, "<repo>"
set :deploy_to, "/path/to/name"
set :user, 'deployer'
set :use_sudo, false
set :rvm_type, :system
set :scm, :git # You can set :scm explicitly or Capistrano will make an intelligent guess based on known version control directory names
@davidchua
davidchua / gist:5661182
Created May 28, 2013 07:59
Cappers (Capistrano) file for node.js production deployment - Make sure you have 'cappers' gem installed
set :application, "Myapp"
set :repository, "ssh://git@bitbucket.org/yourrepo/app.git"
set :deploy_to, "/approot"
set :user, 'deployer'
set :use_sudo, false
set :use_nave, false
set :main_js, 'server.js'