Skip to content

Instantly share code, notes, and snippets.

var = :foo
%w(a b c).each do |var|
# Do something.
end
puts var # var is actually "c", not :foo. This is not a problem in Ruby 1.9 onwards.
@chuyeow
chuyeow / jQuery event binding count.js
Created November 5, 2009 07:42
Good for checking number of event bindings in place when using jQuery. From http://ajaxian.com/archives/jquery-bondage
jQuery.fn.bind = function (bind) {
return function () {
console.count("jQuery bind count");
console.log("jQuery bind %o", this);
return bind.apply(this, arguments);
};
}(jQuery.fn.bind);
# Put this in nrpe.cfg on the remote host you're monitoring.
command[check_load]=/usr/local/nagios/libexec/check_load -w 5,4,3 -c 10,8,6
command[check_memory]=/usr/local/nagios/libexec/check_mem.pl -f -w 5 -c 2
command[check_disk]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /
command[check_swap]=/usr/local/nagios/libexec/check_swap -w 20% -c 10%
command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Z
command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 150 -c 200
command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Colors</key>
<dict>
<key>Background</key>
<string>0.082 0.087 0.109</string>
<key>InsertionPoint</key>
<string>1.000 1.000 1.000</string>
#!/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"
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
@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'
//= require jquery
//= require js/with/utf-8-characters
@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
@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"