Skip to content

Instantly share code, notes, and snippets.

Jim Weirich jimweirich

Block or report user

Report or block jimweirich

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View Has Anybody Seen My Code
In celebration of Whyday: Rubyists always want to show others the beautiful code
they have created, hence the question: Has Anybody Seen My Code?
Has Anybody Seen My Code
(sung to the tune of Has Anybody Seen My Gal)
Clean and small, works for all,
Ruby is my all in all.
Has anybody seen my code?
View source_for.rb
# My take on Mike's source_for method.
# (see http://pragmaticstudio.com/blog/2013/2/13/view-source-ruby-methods)
#
# (1) I named it 'src' rather than source_for (ok, I'm a lazy typer).
# (2) The edit function was broken out as a separate function.
# (3) The edit function is for emacs
# (4) If the method is not defined on the object, and the object
# is a class, then see if it is an instance method on the class.
#
# The fourth point allows my to say:
@jimweirich
jimweirich / Rakefile
Last active Jan 10, 2019
Bottles of Beer, for Sandi Metz
View Rakefile
#!/usr/bin/env ruby
require 'rake/clean'
require 'rake/testtask'
task :default => [:spec, :test]
task :spec do
sh "rspec ."
end
@jimweirich
jimweirich / Gemfile
Created May 21, 2013
Template for creating autonomous drone programs.
View Gemfile
source 'https://rubygems.org'
gem 'celluloid'
gem 'celluloid-io'
@jimweirich
jimweirich / x.rb
Created Feb 7, 2012
Vital Ruby my_each
View x.rb
class Array
def my_each
i = 0
while i < self.length
yield self[i]
i += 1
end
self[0]
end
@jimweirich
jimweirich / abstract.md
Created Apr 17, 2012
Berlin Clock Kata
View abstract.md

Berlin Clock

Original Reference

Create a representation of the Berlin Clock for a given time (hh::mm:ss).

The Berlin Uhr (Clock) is a rather strange way to show the time. On the top of the clock there is a yellow lamp that blinks on/off every two seconds. The time is calculated by adding rectangular lamps.

View attr_flag.rb
class Module
def attr_flag(*names)
names.each do |name|
module_eval "def #{name}?(); @#{name}; end"
end
end
end
@jimweirich
jimweirich / analysis.rb
Created Jul 20, 2011
Results from Roman Numeral Calculator Kata at @cincinnatirb
View analysis.rb
# When I posted the results of the Roman Numeral Calculator kata
# earlier this week, I said that I felt that the evolution of the code
# through TDD was much more interesting than the final result. Let me
# explain.
#
# First, some background. The goal of this Kata is to produce a
# RomanNumeralCalculator object that converts from arabic numbers to
# Roman numerals, and from Roman numerals back to arabic.
Then { calculate("1").should == "I" }
@jimweirich
jimweirich / adhoc.sh
Last active Jul 22, 2017
Controlling multiple drones with a single Ruby program.
View adhoc.sh
# This script should be run on the drone.
# Change the IP address to be difference
# for each drone on the same ad-hoc network
#
killall udhcpd
ifconfig ath0 down
iwconfig ath0 mode ad-hoc essid ardrone2_070401 channel auto commit
ifconfig ath0 192.168.1.100 netmask 255.255.255.0 up
View church_numerals.clj
; Church Numerals in Clojure
;
; Church numerals use anonymous functions to represent numbers.
;
; ((zero f) x) -- returns x
; ((one f) x) -- return (f x)
; ((two f) x) -- return (f (f x))
; ...
(def zero (fn [f] (fn [x] x)))
You can’t perform that action at this time.