Skip to content

Instantly share code, notes, and snippets.

== Development Approaches
Asshole Driven development (ADD) - Any team where the biggest jerk makes all the big decisions is asshole driven development. All wisdom, logic or process goes out the window when Mr. Asshole is in the room, doing whatever idiotic, selfish thing he thinks is best. There may rules and processes, but Mr. A breaks them and people follow anyway.
Cognitive Dissonance development (CDD) - In any organization where there are two or more divergent beliefs on how software should be made. The tension between those beliefs, as it's fought out in various meetings and individual decisions by players on both sides, defines the project more than any individual belief itself.
Cover Your Ass Engineering (CYAE) - The driving force behind most individual efforts is to make sure than when the shit hits the fan, they are not to blame.
Development By Denial (DBD) - Everybody pretends there is a method for what's being done, and that things are going ok, when in reality, things are a mess and th
@lian
lian / gist:7381252
Created November 9, 2013 03:36
IO#winsize
class IO
TIOCGWINSZ = 0x5413
TIOCSWINSZ = 0x5414
Winsize = Struct.new(:rows, :columns, :horizontal_pixels, :vertical_pixels)
def winsize
ioctl(TIOCGWINSZ, size=""); Winsize.new(*size.unpack("SSSS"))
end
def winsize=(winsize)
module B
def self.included(base)
base.extend(ClassMethods)
end
def foo
p 'from instance'
end
module ClassMethods
class Options < Hash
def self.new(&a)
a = lambda{|h,k| h[k] = new(&a) } unless a
super(&a)
end
def method_missing(m, *a)
if m[-1] == "="
key = keys.find{|k| k.to_s == m[0...-1].to_s } || m[0...-1].to_sym
self[key] = a.first
else
@lian
lian / gist:7346290
Created November 6, 2013 23:42
ruby-pop3-auth.rb
require 'socket'
serv = TCPServer.new("127.0.0.1", 110)
s = serv.accept
s.puts "+OK POP3 server ready"
while line = s.gets.strip
case line
when "CAPA"
s.puts("SASL PLAIN\n.")
@lian
lian / gist:7346260
Created November 6, 2013 23:40
ruby-shuffle-test.rb
require 'securerandom'
N = 100_000
A = %w(a b c)
Score = Hash.new { |h, k| h[k] = 0 }
N.times do
sorted = A.sort_by{ SecureRandom.random_bytes(4).unpack("I")[0] }
Score[sorted.join(" ")] += 1
end
h = Hash.new{|h,k| h[k] = 0 }; ObjectSpace.each_object{|o| h[o.class] += 1 }; p h.sort_by{|k,v| -v}
@lian
lian / gist:7345976
Created November 6, 2013 23:17
gists-fetcher.rb
require 'open-uri'; require 'json'
username = ARGV[0]
JSON.parse(open("http://gist.github.com/api/v1/json/gists/#{username}").read)['gists'].each{|i| system "git clone git://gist.github.com/#{i['repo']} gist-#{i['repo']}" }
@lian
lian / gist:7346060
Created November 6, 2013 23:23
em-fork-reactor.rb
require 'eventmachine'
children = []
Signal.trap('INT') do
puts "Killing #{children.size} children ..."
children.each do |pid|
Process.kill('SIGUSR1', pid) rescue nil
end
EM.stop
@lian
lian / gist:7346053
Created November 6, 2013 23:23
resistor_calculator.rb
class ResistorCalculator
# http://www.dannyg.com/examples/res2/resistor.htm
attr_reader :tolerance, :multiplier, :ones, :tens, :ohms
Tens = %w[Black Brown Red Orange Yellow Green Blue Violet Gray White]
Ones = %w[Black Brown Red Orange Yellow Green Blue Violet Gray White]
Multiplier = %w[Black Brown Red Orange Yellow Green Blue Violet Gray White Gold Silver]
Tolerance = %w[Gold Silver None]