Skip to content

Instantly share code, notes, and snippets.

View kenn's full-sized avatar

Kenn Ejima kenn

View GitHub Profile
@caseyohara
caseyohara / reserved_usernames.rb
Created December 9, 2011 22:58
A list of reserved usernames to avoid vanity URL collision with resource paths
# A list of possible usernames to reserve to avoid
# vanity URL collision with resource paths
# It is a merged list of the recommendations from this Quora discussion:
# http://www.quora.com/How-do-sites-prevent-vanity-URLs-from-colliding-with-future-features
# Country TLDs found here:
# http://en.wikipedia.org/wiki/List_of_Internet_top-level_domains#Country_code_top-level_domains
# Languages found here:
@stympy
stympy / deploy.rb
Created December 12, 2011 21:27
Skip asset pre-compilation when deploying if the assets didn't change
namespace :deploy do
namespace :assets do
task :precompile, :roles => :web, :except => { :no_release => true } do
from = source.next_revision(current_revision)
if capture("cd #{latest_release} && #{source.local.log(from)} vendor/assets/ app/assets/ | wc -l").to_i > 0
run %Q{cd #{latest_release} && #{rake} RAILS_ENV=#{rails_env} #{asset_env} assets:precompile}
else
logger.info "Skipping asset pre-compilation because there were no asset changes"
end
end
@nh7a
nh7a / population_count_test.c
Created December 13, 2011 09:44
population count test
/*
$ gcc -std=c99 a.c
$ ./a.out 10000000
10000000 bits...
precmp8: 11ms (1250001)
POPCNT: 6ms (1250001)
$ ./a.out 100000000
100000000 bits...
precmp8: 111ms (12500001)
POPCNT: 62ms (12500001)
@netmute
netmute / README.md
Last active October 27, 2022 13:22
Game of Life

Game of Life

An implementation of Conway's Game of Life in 140 characters of Ruby.

Author

Created by Simon Ernst (@sier).

@holman
holman / gemspec-usage.md
Created February 12, 2012 07:02
test/spec/mini

Just install this in your apps like so:

gem 'test-spec-mini', :git => 'git://gist.github.com/1806986.git', :require => 'mini'

@ono
ono / resque.sh
Created March 1, 2012 10:23
resque.sh
#!/bin/sh
usage()
{
echo "usage: ${0} {start|stop|graceful_stop|stop_child|restart} <any_process_keyword>"
exit 1
}
start_app() {
${app_cmd} 2>&1 | logger -t resque_worker &
}
> perl -E 'say "生" & "死"'
生 Life U+751F \xe7\x94\x9f 11100111 10010100 10011111
死 Death U+6B7B \xe6\xad\xbb 11100110 10101101 10111011
愛 Love u+611B \xe6\x84\x9b 11100110 10000100 10011011
require 'rubygems'
require 'redis'
require 'redis/distributed'
r = Redis::Distributed.new %w[redis://host1:6379 redis://host2:6379]
# show node for key "foo"
p r.node_for("foo")
# set the value of "foo"
class ActionDispatch::Routing::Mapper
def draw(routes_name)
instance_eval(File.read(Rails.root.join("config/routes/#{routes_name}.rb")))
end
end
BCX::Application.routes.draw do
draw :api
draw :account
draw :session
@corny
corny / error_pages.rb
Created May 12, 2012 11:32
Custom error pages
#
# Usage:
# class ApplicationController < ActionController::Base
# include ErrorPages
# end
#
module ErrorPages
extend ActiveSupport::Concern