Skip to content

Instantly share code, notes, and snippets.

@ryangreenberg
ryangreenberg / gist:1009398
Created June 5, 2011 20:36
Steps to create a new local development site

Steps to create a new local development site

[site] = name of site [root dir] = path to site root [logs] = path to logs directory

Example: site = helloworld root dir = /Users/me/Sites/helloworld logs = /Users/me/Sites/logs

@ryangreenberg
ryangreenberg / gist:1199301
Created September 6, 2011 23:35
self.destruct!
#!/usr/bin/env ruby -wKU
class Object
def destruct!
print "This message will self-destruct in..."
5.downto(0) {|i| print "#{i}..."; $stdout.flush; sleep(1)}
File.open(__FILE__, 'w') { }
end
end
@ryangreenberg
ryangreenberg / thrift.rb
Created October 6, 2011 22:02 — forked from mceachen/thrift.rb
Thrift 0.5.0 homebrew
require 'formula'
class Thrift < Formula
homepage 'http://incubator.apache.org/thrift/'
head 'http://svn.apache.org/repos/asf/incubator/thrift/trunk'
url 'http://archive.apache.org/dist/incubator/thrift/0.5.0-incubating/thrift-0.5.0.tar.gz'
md5 '14c97adefb4efc209285f63b4c7f51f2'
depends_on 'boost'
        _,'|             _.-''``-...___..--';)
       /_ \'.      __..-' ,      ,--...--'''
      <\    .`--'''       `     /'
       `-';'               ;   ; ;
 __...--''     ___...--_..'  .;.'
(,__....----'''       (,..--''   

To enable cat cat, place the above text in a file titled cat. Image by Felix Lee, from http://user.xmission.com/~emailbox/ascii_cats.htm

@ryangreenberg
ryangreenberg / thrift.rb
Created March 20, 2012 23:12
homebrew thrift 0.5.0
require 'formula'
class Thrift < Formula
homepage 'http://incubator.apache.org/thrift/'
head 'http://svn.apache.org/repos/asf/incubator/thrift/trunk'
url 'http://archive.apache.org/dist/incubator/thrift/0.5.0-incubating/thrift-0.5.0.tar.gz'
md5 '14c97adefb4efc209285f63b4c7f51f2'
depends_on 'pkg-config' => :build
depends_on 'boost'
@ryangreenberg
ryangreenberg / todo.rb
Created March 26, 2012 23:03
todo_for_real
require 'date'
class ExpiredTodoError < StandardError; end
# Implementation #
def todo(what, by_date)
if production? || (Date.parse(by_date) >= Date.today)
yield
else
raise ExpiredTodoError, "TODO: #{what}"
@ryangreenberg
ryangreenberg / gist:2370820
Created April 12, 2012 20:38
val == val // false
[ undefined, null, [], {}, NaN ].forEach(function(val){
console.log("val =", val, "; val == val; //", val == val );
});
// Output
// val = undefined ; val == val; // true
// val = null ; val == val; // true
// val = [] ; val == val; // true
// val = {} ; val == val; // true
// val = NaN ; val == val; // false
@ryangreenberg
ryangreenberg / gist:2402054
Created April 16, 2012 22:23
Find the longest file
find . -type f | # find all normal files
grep -v "\.log$" | # skip files ending with .log
xargs wc -l | # run wc -l on each file
sort -r # sort descending
@ryangreenberg
ryangreenberg / gist:2722492
Last active October 5, 2015 00:18
pid roulette
ps axc -o pid | grep -v PID | ruby -e 'puts STDIN.read.split("\n").shuffle.join("\n")' | head -1 | xargs kill
@ryangreenberg
ryangreenberg / gist:2816092
Created May 27, 2012 22:08
How to read a file in Ruby
# How to read a file in Ruby
file_name = "example.txt"
# It's simple.
# Open the file in read mode ("r"), read it, and close it.
f = File.open(file_name, "r")
f.read
f.close
# Though "r" is the default mode, so you can remove that.