Skip to content

Instantly share code, notes, and snippets.

@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 / Preferences.sublime-settings
Last active January 19, 2017 07:51
Sublime Text 3 preferences
{
"auto_complete_commit_on_tab": true,
"bold_folder_labels": true,
"caret_style": "solid",
"color_scheme": "Packages/Color Scheme - Default/Twilight.tmTheme",
"create_window_at_startup": false,
"ensure_newline_at_eof_on_save": true,
"file_exclude_patterns":
[
".DS_Store"
@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
#!/bin/sh
set -u
set -e
APP_ROOT=/var/railsapps/ryokan/current
PID=$APP_ROOT/tmp/pids/unicorn.pid
ENV=production
CMD="/opt/ruby-enterprise/bin/unicorn_rails -D -E $ENV -c config/unicorn.rb"
old_pid="$PID.oldbin"