Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env ruby
class Matcher
def initialize( *args, &blk )
@args = args
@blk = blk
end
def call( *params )
matches = @args.zip(params).all?{|arg, param|
@regularfry
regularfry / link-gems
Created March 21, 2014 12:42
microgems

SRP: two approaches, two definitions of “responsibility”

Using “Uncle Bob” and “Sandi Metz” as figureheads of each style because they’ve both written about them, not necessarily to imply any ownership of the concepts.

  • Uncle Bob: “Each module has a single responsibility TO SOMEONE”
    • If this applies at the class level, it can’t be usefully used at the method level
  • Sandi Metz: “Each class/method has a single responsibility FOR SOMETHING”
    • This implies the same test applied at two different levels of
require 'thread'
class Actor
def initialize(send_queue, recv_queue)
@send_queue = send_queue
@recv_queue = recv_queue
end
def send(sym, *args)
@send_queue.push([sym,*args])
require 'rubygems'
require 'builder'
xml = Builder::XmlMarkup.new
@recent_items = [
{:title => "Item Title",
:description => "Item Description",
:pub_date => Date.today,
:guid => "10893750189756019760127",
require 'rubygems'
require 'builder'
xml = Builder::XmlMarkup.new
@recent_items = [
{:title => "Item Title",
:description => "Item Description",
:pub_date => Date.today,
:guid => "10893750189756019760127",
bitstring = <<-BITS
110101001110100001100101101000000101010111101110
011010011111011001100101011100101111001101101001
011101001111100110100000011011110110011010100000
110001011110010001101001111011101110001011110101
011100101110011111101000101000000111011101101111
111101010110110011100100101000000110110001101001
111010110110010110100000011101000110111110100000
011101001110100011100001111011101110101110100000
011010010111010011110011101000001111001111110101
;; Some fairly nasty elisp for a very simple purpose: to set up a new clojure-project
;; and run clojure-project in it. For those of us who Know Not The Ways Of Maven.
(defun clojure-project-setup (path)
"Set up a project structure for clojure-project and copy any
interesting-looking jars into lib/."
(interactive (list
(ido-read-directory-name
"Project root: "
(locate-dominating-file default-directory "~"))))
@regularfry
regularfry / gist:1073970
Created July 9, 2011 21:12
Thoughts on a first pass-through of the Sproutcore getting started guide
=begin
I worked through this Getting Started guide on 2011-07-08, on an
up-to-date Debian Squeeze desktop with ruby 1.9.2-p180 installed via
RVM, and Sproutcore 1.6.0.rc.2 installed via Rubygems. The Getting
Started guide was the first literature on Sproutcore I exposed myself
to. I've interspersed notes about where I got confused in =begin/=end
blocks throughout, mostly in the form of rhetorical questions as they
appeared in my mind at the time. I did not watch the screencast.
@regularfry
regularfry / gist:1600582
Created January 12, 2012 13:41
lein test slowness
$ lein version
Leiningen 1.6.2 on Java 1.6.0_18 OpenJDK 64-Bit Server VM
$ lein new foo
Created new project in: /home/zander/scratch/foo
Look over project.clj and start coding in foo/core.clj
$ cd foo
$ lein deps
Copying 1 file to /home/zander/scratch/foo/lib
$ time lein test