Skip to content

Instantly share code, notes, and snippets.

View practicingruby's full-sized avatar

Gregory Brown practicingruby

View GitHub Profile
@practicingruby
practicingruby / idea.md
Last active December 10, 2015 22:49
Evidence based software development

I am considering starting up a community-funded project that is aimed at exploring software development methodologies and practices through the lens of evidence-based scientific studies. The purpose of this project would be to design, conduct, and report on real world experiments that attempt to answer questions that are relevant to everyday programmers.

This project would be subscriber-supported, but would follow a completely open publication model.

Subscribers would pay a small fee (maybe $5 to $10/month) and get all of the following benefits:

  • A monthly progress report summarizing all interesting activity on the project
  • Opportunities to read early drafts of articles
  • Opportunities to participate in pilot sessions for studies
  • Access to a members-only mailing list to discuss research activities with other supporters and with the project's maintainers.
@practicingruby
practicingruby / puzzlenode1.lua
Last active December 11, 2015 04:18
Puzzlenode #4 in Lua
-- Implements the Robots vs. Lasers problem:
-- http://puzzlenode.com/puzzles/4-robots-vs-lasers
conveyors = {}
function conveyors.parse(filename)
local f = io.open(filename, "r")
local conveyors = {}
repeat
# from Alberto Fernandez-Capel(afcapel) for a practicing ruby article
require 'thread'
module Actor
module ClassMethods
def new(*args, &block)
Thread.current[:actor] = Proxy.new(super)
end
end
module MyApplication
Conditions = {}
Conditions[:near_christmas] = FuzzyLogic::Set.new(1) { |time|
# default output is zero
o = 0.0
# time has to be in december before or at the 24th
if time.month == 12 and time.day <= 24 then
# set is completly true when its 20th december or above
module Cached
def cache(*method_names)
method_names.each do |m|
original = instance_method(m)
results = {}
define_method(m) do |*a|
results[[m, a]] ||= original.bind(self).call(*a)
end
end
class ComposedCache
def initialize(target)
@target = target
end
def cache(*method_names)
method_names.each do |m|
original = @target.method(m)
results = {}
class ComposedCache
def initialize(target)
@target = target
end
# does not support caching with recursive calls (or calls to other cached methods)
def cache(*method_names)
method_names.each do |m|
results = {}

When access to an object's internals is truly necessary, it isn't practical to use composition based techniques. For example, consider the following mixin-based code which implements a memoization routine for caching method return values:

module Cached
  def cache(*method_names)
    method_names.each do |m|
      original = instance_method(m)
## 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
module A
def foo
puts "FROM A!"
a
b
c
end
private