Skip to content

Instantly share code, notes, and snippets.

@nick-desteffen
nick-desteffen / OSX UTC Time Zone
Created August 5, 2011 01:50
Set Time zone in OSX to UTC
sudo ln -sf /usr/share/zoneinfo/UTC /etc/localtime
@nick-desteffen
nick-desteffen / engineyard.rake
Created September 20, 2011 03:25
EngineYard AppCloud Deployment Script
namespace :engineyard do
@environment = "your_application_production"
@git_tag = "HEAD"
desc "Upload Chef Deploy recipes"
task :upload_chef_recipes => [:environment, :set_eyrc] do
sh "cd ey-cloud-recipes && bundle exec ey recipes upload -e #{@environment}"
end
@nick-desteffen
nick-desteffen / parans_test.rb
Created September 23, 2011 22:24
Parans Test
######
###### Write a function that accepts a string of parenthesis, return true if it is a valid string, false if not.
###### Strings are valid if all parens close, ie: () or (()) or (()()()) are valid, ()), ((), )( etc. would be invalid.
###### An empty string is also valid.
######
require 'test/unit'
def valid_parans(string)
@nick-desteffen
nick-desteffen / rescue_nil_bad.rb
Created March 25, 2012 15:27
Why rescue nil is bad
class Category < ActiveRecord::Base
def ask_question(question)
## Code to check some other system for the answer, Redis or Memcached maybe.
raise "System is unavailable, you should turn it on"
end
end
params = {category_id: 1, question: "Why did the quick brown fox jump over the lazy dog?"}
@nick-desteffen
nick-desteffen / rescue_nil_bad_fixed.rb
Created March 25, 2012 15:35
Why rescue nil is bad - fixed
class Category < ActiveRecord::Base
def ask_question(question)
begin
## Code to check some other system for the answer, Redis or Memcached maybe.
raise "System is unavailable, you should turn it on"
rescue Exception => e
## Do something with exception
puts "System is unavailable"
return nil
@nick-desteffen
nick-desteffen / nginx.conf
Created September 23, 2012 15:42
Nginx Upstart script
# nginx
description "nginx http daemon"
author "George Shammas <georgyo@gmail.com>"
start on (filesystem and net-device-up IFACE=lo)
stop on runlevel [!2345]
env DAEMON=/opt/nginx/sbin/nginx
env PID=/var/run/nginx.pid
@nick-desteffen
nick-desteffen / .gitignore
Created November 13, 2012 04:36 — forked from pcdinh/.gitignore
fabfile to deploy flask app to nginx/supervisor/uwsgi stack
.idea/*
*.pyc
@nick-desteffen
nick-desteffen / Javascript RandomDate
Created December 14, 2012 15:27
Function to generate a random date between 2 dates
start = new Date(2001, 0, 1)
end = new Date()
function randomDate(start, end) {
return new Date(start.getTime() + Math.random() * (end.getTime() - start.getTime()))
}
//http://apod.nasa.gov/apod/ap950616.html
#! /bin/sh
### BEGIN INIT INFO
# Provides: redis-server
# Required-Start: $syslog
# Required-Stop: $syslog
# Should-Start: $local_fs
# Should-Stop: $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: redis-server - Persistent key-value db

Benchmark Bundler

Because loading gems can take longer than you think

$ curl -fsSL https://gist.github.com/raw/5022636/benchmark.rb | ruby
............................................................[DONE]

Gem                            Time(sec)     Pct %
--------------------------------------------------