Skip to content

Instantly share code, notes, and snippets.

@mmmries
mmmries / TextComparer.sh
Created August 28, 2014 14:33
nand2tetris helps
#!/bin/sh
cd `dirname $0`
java -classpath "${CLASSPATH}:bin/classes" TextComparer $1 $2
@mmmries
mmmries / talk.md
Created May 30, 2014 17:15
ArrrrCamp Talk Summary

Title

How I Accidentally Wrote the Best Code of my Career

Summary

Picking the right abstractions can be very hard. Understanding object design helps us evaluate tradeoffs, but where do you get the raw ideas to evaluate? I have to be creative? Lets talk about the 3rd rewrite of a system that came out surprisingly beautiful because we accidentally used a lot of creative processes.

@mmmries
mmmries / installs.sh
Last active August 29, 2015 14:00
Raw Ubuntu 14.04 to Working Artoo
# Open the software sources and enable the multiverse + proprietary stuff
sudo apt-get install -y ruby1.9.1 ruby1.9.1-dev git
sudo gem install artoo-digispark --no-ri --no-rdoc
@mmmries
mmmries / Gemfile
Last active August 29, 2015 14:00
Avro Gem Broken??? Or I don't understand it?
source "https://rubygems.org"
gem "avro", "1.7.5"
@mmmries
mmmries / expected_output.txt
Created February 28, 2014 19:59
TCP Server Example
$ ruby -v
ruby 2.1.0p0 (2013-12-25 revision 44422) [x86_64-darwin12.0]
$ ruby tmp/tcp_server.rb
Server :: client says: ping
Client :: server says: Hello! Time is 2014-02-28 12:55:54 -0700
Server :: client says: die!
Server :: farewell cruel world!
All Done!
@mmmries
mmmries / gist:9009549
Created February 14, 2014 21:20
rubyhop :(
$ rubyhop
/Users/michael.ries/.rvm/rubies/ruby-2.1.0/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:135:in `require': dlopen(/Users/michael.ries/.rvm/gems/ruby-2.1.0/extensions/x86_64-darwin-12/2.1.0-static/gosu-0.7.50/gosu.bundle, 9): Symbol not found: __ZNSbIwSt11char_traitsIwESaIwEE4_Rep11_S_terminalE (LoadError)
Referenced from: /Users/michael.ries/.rvm/gems/ruby-2.1.0/extensions/x86_64-darwin-12/2.1.0-static/gosu-0.7.50/gosu.bundle
Expected in: flat namespace
in /Users/michael.ries/.rvm/gems/ruby-2.1.0/extensions/x86_64-darwin-12/2.1.0-static/gosu-0.7.50/gosu.bundle - /Users/michael.ries/.rvm/gems/ruby-2.1.0/extensions/x86_64-darwin-12/2.1.0-static/gosu-0.7.50/gosu.bundle
from /Users/michael.ries/.rvm/rubies/ruby-2.1.0/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:135:in `rescue in require'
from /Users/michael.ries/.rvm/rubies/ruby-2.1.0/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:144:in `require'
from /Users/michael.ries/.rvm/gems/ruby-2.1.0/gems/gos
@mmmries
mmmries / acts_as_csv.v1.rb
Created January 16, 2014 16:46
Convenient CSV My solution for the homework assignment from the end of chapter 2 in the [Seven Languages in Seven Weeks](http://pragprog.com/book/btlang/seven-languages-in-seven-weeks) book
module ActsAsCsv
def read
@csv_contents = []
filename = self.class.to_s.downcase + '.csv'
file = File.new(filename)
@headers = file.gets.chomp.split(', ')
file.each do |row|
@csv_contents << row.chomp.split(', ')
end
@mmmries
mmmries / request_spec.rb
Created June 13, 2013 21:14
rspec test that a request makes certain changes to a model. How can I do something like this?
describe "my request" do
it "should update the model" do
Model.any_instance.should_receive(:save) do
self.changes.should include(:attribute)
self.attribute.should == 'value'
end
xhr :put, model_path(model), {attribute: 'value'}
end
end
@mmmries
mmmries / line_reader.v1.rb
Last active December 17, 2015 10:48
Tab-separated Value Reader
module TSV
class LineReader
attr_reader :filepath
def initialize(filepath)
@filepath = filepath
end
def each
buffer = ""
open(filepath) do |f|
@mmmries
mmmries / strict_tsv.rb
Last active December 16, 2015 16:09
Tab-separated parsing using Ruby 2.0 CSV library
# The main parse method is mostly borrowed from a tweet by @JEG2
class StrictTsv
attr_reader :filepath
def initialize(filepath)
@filepath = filepath
end
def parse
open(filepath) do |f|
headers = f.gets.strip.split("\t")