Skip to content

Instantly share code, notes, and snippets.

View hannestyden's full-sized avatar

Hannes Tydén hannestyden

  • Stockholm, Sweden
View GitHub Profile
class C
def pub
:pub
end
protected
def prot
:prot
end
module M
extend self
def m
:m
end
end
class A
extend M
# 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'
# 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
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"
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
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)
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
<!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) {
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