Skip to content

Instantly share code, notes, and snippets.

@chuyeow
chuyeow / unicorn
Created September 10, 2013 08:31
Unicorn init.d script
#! /bin/sh
### BEGIN INIT INFO
# Provides: unicorn
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Manage unicorn server
# Description: Start, stop, restart unicorn server for a specific application.
### END INIT INFO
@chuyeow
chuyeow / unicorn_logrotate.conf
Created September 10, 2013 04:21
Unicorn sample logrotate file
/var/railsapps/appname/shared/log/*.log {
daily
missingok
rotate 3
compress
dateext
delaycompress
lastaction
pid=/var/railsapps/appname/shared/pids/unicorn.pid
@chuyeow
chuyeow / setup-redis.md
Last active December 22, 2015 02:19
Setting up Redis server on Ubuntu

Compile Redis

  1. Download and unpack redis from (http://redis.io/download).
  2. Run make or make 32bit (good idea to save on memory or when RAM is low).
  3. Run tests with make test.

Install Redis

  1. Copy binaries (redis-server, redis-cli, etc.) in src/ to /usr/local/bin.
  2. Setup init.d script:
@chuyeow
chuyeow / .tmux.conf
Last active December 20, 2015 17:59
tmux config
set -g default-terminal "screen-256color"
set -sg escape-time 1
set-option -g repeat-time 200
set -g status-utf8 on
setw -g utf8 on
set-window-option -g utf8 on
setw -g monitor-activity on
set -g visual-activity on
@chuyeow
chuyeow / inflections.java
Created March 17, 2013 06:33
Rails style inflections in Java (from ages ago).
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Transforms words (from singular to plural, from camelCase to under_score, etc.). I got bored of doing Real Work...
*
* @author chuyeow
*/
@chuyeow
chuyeow / ec2-run-instances-example.sh
Created July 4, 2012 08:48
EC2 command to launch an EBS-backed instance and attach ephemeral storage
ec2-run-instances ami-2c22637e --group default --key chuyeow --user-data hostname=hostname --instance-type c1.xlarge --region ap-southeast-1 --availability-zone ap-southeast-1a --disable-api-termination --monitor -b /dev/sda1=:30:false -b "/dev/sdb=ephemeral0" -b "/dev/sdc=ephemeral1" -b "/dev/sdd=ephemeral2" -b "/dev/sde=ephemeral3"
@chuyeow
chuyeow / swapper.sh
Created July 2, 2012 09:02
Script to add a swapfile
#!/bin/bash
# Creates a swapfile at SWAPFILE.
SWAPFILE=/mnt/swapfile
SWAPSIZE_MB=7168
SWAP_ALREADY_ON=`swapon -s | grep $SWAPFILE`
if [ -e $SWAPFILE ]; then
if [[ -n $SWAP_ALREADY_ON ]]; then
//= require jquery
//= require js/with/utf-8-characters
@chuyeow
chuyeow / Reduce font-size.js
Created October 22, 2010 08:06
Reduce font-size of text in $target to fit into a single line if necessary.
var $target = $('#selector');
var target_width = $target.parent(':first').width();
var $span = $('<span></span>');
$span.css({
'display': 'inline',
'visibility': 'hidden',
'font-size': parseInt($target.css('font-size'), 10),
'font-weight': $target.css('font-weight'),
'white-space': 'nowrap'
namespace :bundler do
task :create_symlink, :roles => :app do
set :bundle_dir, File.join(release_path, 'vendor', 'bundle')
shared_dir = File.join(shared_path, 'bundle')
run "rm -rf #{bundle_dir}"
run "mkdir -p #{shared_dir} && ln -s #{shared_dir} #{bundle_dir}"
end
task :bundle_new_release, :roles => :app do