Skip to content

Instantly share code, notes, and snippets.

View rrouse's full-sized avatar

Robert Rouse rrouse

  • St. Louis, Missouri
View GitHub Profile
Aaron Tenderlove Patterson (<Your Birthdate> – ) is an American educator, software developer, and awesome guy.
Patterson is most famous for Ruby and Rails core, his god-among-men beard, and creating and hosting Friday Hugs, which feature his gentle,
soft-spoken personality and directness to his audiences.
int fib(int n) {
if (n <= 1) return n;
return fib(n - 1) + fib(n - 2);
}
main() {
print('fib(20) = ${fib(20)}');
}
/*
Today I learned a few things.
1). D allows default parameters to appear at the beginning of a function signature if you want.
2). D can simulate Ruby blocks to an extent.
*/
import std.stdio;
@rrouse
rrouse / mixinsarefun.d
Created February 21, 2012 20:11
D is very interesting. Here is some compile time "magic" to produce methods by taking the name of the class passed in and lowercasing it. I can pretend to have ActiveRecord now!
import std.stdio, std.string;
mixin template has_one(T, string name = null) {
T _method() {
T thing = new T();
return thing;
}
1.9.3-p0 :031 > Bundler.definition.specs.each do | gem|
1.9.3-p0 :032 > puts gem
1.9.3-p0 :033?> end
#<Gem::Specification name=rake version=0.9.2.2>
#<Gem::Specification name=i18n version=0.6.0>
#<Gem::Specification name=multi_json version=1.0.4>
#<Gem::Specification name=activesupport version=3.2.1>
#<Gem::Specification name=builder version=3.0.0>
#<Gem::Specification name=activemodel version=3.2.1>
#<Gem::Specification name=erubis version=2.7.0>
Bundler.definition.index do |gem|
puts "#{gem.name}: #{gem.version}"
end
class point =
object
val mutable x = 0
method get_x = x
method move d = x <- x + d
end;;
let p = new point;;
app = Rails.application
session = ActionDispatch::Integration::Session.new(app)
session.admin_user_path(@user)
@rrouse
rrouse / activemodel_observing.rb
Created January 31, 2012 21:02
Coworker is building an ORM around Cassandra. He couldn't get ActiveModel::Observers working. So I read code and wrote him this example. Reading code to learn how things work to teach others is fun!
require 'active_model'
class Foo
include ActiveModel::Observing
def initialize(args = {})
@bar = args[:bar]
notify_observers(:before_create)
notify_observers(:after_create)
end
bundle exec rake -T --trace
(in /home/app/blockshopper)
*** Using highline effectively in JRuby requires manually installing the ffi-ncurses gem.
*** jruby -S gem install ffi-ncurses
!!!! Missing jruby-win32ole gem: jruby -S gem install jruby-win32ole
rake aborted!
cannot load Java class javax.jms.Session
org/jruby/javasupport/JavaClass.java:1204:in `for_name'
org/jruby/javasupport/JavaUtilities.java:34:in `get_proxy_class'