Skip to content

Instantly share code, notes, and snippets.

View practicingruby's full-sized avatar

Gregory Brown practicingruby

View GitHub Profile
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
@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

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.

(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)
(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)))
require "fileutils"
class Skeletor
include FileUtils
def self.generate(project_dir)
new(project_dir).generate
end
def initialize(project_dir)

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("/")
@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

module A
def foo
puts "FROM A!"
a
b
c
end
private
## INHERIT from a base class
# -----------------------------------------
class Product < ActiveRecord::Base
belongs_to :category
def self.lookup(item_code)
where(:item_code => item_code).first
end
end