This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class C | |
def pub | |
:pub | |
end | |
protected | |
def prot | |
:prot | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module M | |
extend self | |
def m | |
:m | |
end | |
end | |
class A | |
extend M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is a modification of: | |
# http://github.com/antifuchs/homebrew/raw/0fa5fbd851f378166367c12eac5e3d3cf784a491/Library/Formula/varnish.rb | |
require 'formula' | |
class Varnish < Formula | |
url 'http://downloads.sourceforge.net/project/varnish/varnish/2.1/varnish-2.1.tar.gz' | |
homepage 'http://varnish.projects.linpro.no/' | |
md5 '91d92ea69f7dce470e55ef4721ef9b7d' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Logical operator precedence in Ruby | |
# | |
# Problems might arise in combination with the assignment operator. | |
# | |
# http://blog.jayfields.com/2007/08/ruby-operator-precedence-of-and-which.html | |
# http://phrogz.net/ProgrammingRuby/language.html#table_18.4 | |
# Definitions: | |
# '&&' and '||' are logical operators | |
# 'and' and 'or' are logical composition operators |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
N = 10 | |
(1..N).map { rand(36).to_s(36) }.join # => "1w5v8zbwdg" | |
(1..N).map { c = rand(36).to_s(36); rand(2) == 1 ? c.upcase : c }.join # => "QvM42fvDsJ" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module FixedLengthRandomString | |
extend self | |
ALPHANUMS = [ ('a'..'z'), ('A'..'Z'), ('0'..'9') ].map { |r| r.to_a }.flatten | |
def random(length) | |
(0...length).map { ALPHANUMS.sample }.join | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Util | |
extend self | |
# Is there a standard way to do this? | |
def yield_or_return(object, &block) | |
block_given? ? block.call(object) : object | |
end | |
end | |
class Tree < Struct.new(:left, :right) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module InstrumentModule | |
def self.build(*methods) | |
evil = methods.map do |method| | |
%Q[ | |
def #{method}(*arguments, &block) | |
t = Time.now | |
r = super | |
td = Time.now - t | |
puts "*inst* " + (self.class === Class ? self.name + "." : self.class.name + "#") + "#{method}: " + td.to_s + " s" | |
r |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> | |
<title>SoundCloud OAuth 2 User Agent Authentication Flow Demo</title> | |
<script type="text/javascript" charset="utf-8" src="javascript/jquery-1.4.2.js"></script> | |
<script type="text/javascript" charset="utf-8"> | |
$(function () { | |
var extractToken = function(hash) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for c in `git log [ INSERT GIT BRANCH REFERENCES HERE ] --oneline | grep -v 'Merge branch' | cut -f1 -d ' ' | tac`; do git cherry-pick $c; done |