Skip to content

Instantly share code, notes, and snippets.

View practicingruby's full-sized avatar

Gregory Brown practicingruby

View GitHub Profile
@practicingruby
practicingruby / heroes.md
Last active December 13, 2015 19:29
My Experiences with selecting Ruby Heroes

It's Ruby Hero award selection time, and I've decided this year I won't be participating. I won this award myself in 2010, and I was once a very strong supporter of the idea, so that may come as a surprise.

However, in recent years I've started to feel a few things that have shifted my perspective greatly:

  • I tend to view heroics as unsustainable and ultimately harmful in the long run to a healthy ecosystem (even though I've engaged in them plenty myself)

  • Most people I know who have had their voice greatly amplified have been worse off because of it. It would be nice to say that recognition doesn't change people's motivations, nor does it change how others perceive them, but we've got deep set cognitive biases that prevent that from being possible. This leads to weird side effects that are hard to enumerate concisely, but those who have read the book "Thinking, Fast and Slow" will know what I'm talking about.

  • The Ruby Hero awards use a selection process that was efficient an

Problem

A method has too many parameters, making it hard to remember its interface.

Suppose we were building a HTTP client library called HyperClient. A trivial request might look like this:

http = HyperClient.new("example.com")
http.get("/")
require "fileutils"
class Skeletor
include FileUtils
def self.generate(project_dir)
new(project_dir).generate
end
def initialize(project_dir)
(ns weiqi.core
(:use seesaw.core
seesaw.graphics
seesaw.color))
(def rect-width 30)
(def board-size 19)
(def border-width 1)
(def black-stone-style (style :background (color :black)))
(ns weiqi.core
(:require [seesaw.mouse :as mouse]
[clojure.math.numeric-tower :as math])
(:use seesaw.core
seesaw.graphics
seesaw.color))
(def scale-factor 30)
(def board-size 19)
(def border-width 1)

Ten principles of sustainable software

(Inspired by both Dieter Rams and ISO/IEC 9126):

Sustainable software is...

Purposeful: It has a real, well-defined problem it needs to solve

Reliable: It consistently works correctly under normal circumstances, and handles failures gracefully in exceptional circumstances.

Unobtrusive: It is pleasant to work with, not ugly or distracting.

@practicingruby
practicingruby / x.rb
Last active December 15, 2015 02:29
require "thread"
class TransactionalMap
TransactionAborted = Class.new(StandardError)
def initialize
@data = [{}]
@version = 0
@write_lock = Mutex.new
@update_lock = Mutex.new
require_relative "microworlds"
sim = Microworlds::Simulator.new
display = Microworlds::Visualization.new
sim.notify(display)
sim.up { set_patch_color [:black, :black, :white].sample }
sim.up! do
class BufferedHash
def initialize(head={})
@head = head
@buffer = {}
end
attr_reader :head
def [](key)
@buffer[key] || @head[key]
An ecosystem with ten members each of ten unique species(***) play a simple game...
On each round, each creature rolls a 100 sided dice:
- If it rolls a 1, it dies.
- If it rolls a 2, it creates an exact clone of itself which joins
the game on the next round
- Otherwise, nothing happens and the creature simply moves on to the next round
Then all the creatures repeat the process again, and again, and again.