Skip to content

Instantly share code, notes, and snippets.

View mattyoho's full-sized avatar

Matt Yoho mattyoho

  • Portland, OR, USA
View GitHub Profile
nkallen_: nkallen_: anyway, i want to stress that we basically agree about things so i want to be sure that the tone of the blog post is such
[7:25pm] nkallen_: [7:17pm] nkallen_: i would argue that what you do in rails 3 (according to these tweets I've read)
[7:25pm] nkallen_: [7:17pm] nkallen_: is exactly what I propose... this is just how one might do it in Ruby
[7:25pm] nkallen_: [7:18pm] nkallen_: but my point is conceptual and not about ruby
[7:25pm] nkallen_: [7:18pm] nkallen_: it applies to every oo language and also I might argue to functional languages
[7:25pm] nkallen_: [7:18pm] nkallen_: which is to structure a program around the ability to layer on enhanced functionality and ensure that no assumptions are hardcoded by abstracting over the manufacture of objects
[7:25pm] nkallen_: [7:19pm] nkallen_: in the literature, these techniques are called DI, decorators, and factories.
[7:25pm] nkallen_: [7:20pm] nkallen_: i like these terms because they reflect the concepts that are at work. because ruby m
# not sure if i like this or not
# but it was fun to write!
# :Foo => Foo, :Foo, :Bar => Foo::Bar, etc
def with_foo_like_class(*args)
klass = if args.size == 1
klass_obj = Class.new
Object.const_set(args[0], klass_obj)
else
klass_sym = args.pop

2010 Modularity Olympics

This is a contest, open to programming languages from all nations, to write modular and extensible code to solve the following problem: Implement a service that can run queries on a database.

The Challenge

Sounds simple right? Wrong! A programmer without control over the source-code of that service must be able to later add enhancements such as statistics collecting, timeouts, memoization, and so forth. There are a few more requirements:

  1. the “enhancements” must be specified in a configuration object which is consumed at run-time (e.g., it could be based on user-input).
  2. The enhancements are ordered (stats collecting wraps timeouts, not the other way around) but it must be possible to reverse the order of the enhancements at run-time.
  3. The enhancements must be “surgical” and not “global”. That is, it must be possible to simultaneously have two query services, one reversed and one not reversed, and even have a query service without any enhancements.
# mechanize just enough of campfire to get what i need
require 'mechanize'
class Campfireanize
def initialize(subdomain)
@subdomain = subdomain
@client = Mechanize.new
@logged_in = false
end
#!/usr/bin/ruby
require 'rubygems'
require 'rbench'
require 'find'
def glob(dir)
hash = {}
Dir.glob("#{dir}/**/*.rb") do |f|
hash[f] = File.mtime(f) rescue next
Given /^I will confirm on next step$/ do
begin
evaluate_script("window.alert = function(msg) { return true; }")
evaluate_script("window.confirm = function(msg) { return true; }")
rescue Capybara::NotSupportedByDriverError
end
end
def javascript_confirm(answer)
page.evaluate_script 'window._confirm = window.confirm'
page.evaluate_script "window.confirm = function(x) { return #{answer} }"
yield
page.evaluate_script 'window._confirm && (window.confirm = window._confirm)'
page.evaluate_script 'window._confirm = null'
end

My reply to @marcpeabody's tweet here:

"@marcpeabody: For @mattyoho and you other Inception fanboys - why the movie sucked: http://gist.github.com/501827 #spoileraler" http://twitter.com/marcpeabody/status/19972669611

His claims and my replies:

  1. Getting trapped in a dream means going to limbo. You're stuck in limbo forever… or up until you kill yourself - in which case you'll simply wake up in real life. So why was everyone so afraid of going to limbo?

Going into limbo, due to the time dilation of the dreamworld, meant, to the perceiver, a near-infinite span of time spent in the deep dream world. Meaning you would not only grow old a thousand times over, but the repetition, ennui, and unfathomable duration of the experience would likely drive the person insane; imagine going to sleep feeling 30 and waking up feeling impossibly ancient, your mind having crumbled to dust. Of course you cannot imagine it, which is why it would obliterate the mind.

@mattyoho
mattyoho / gist:583108
Created September 16, 2010 20:30 — forked from headius/gist:579505
~/projects/jruby ➔ jruby -rreal_unix -e 'trap("INT") { puts :there; exit }; puts :here; select(nil, nil, nil, nil)'
here
^Cthere
~/projects/jruby ➔ jruby -rreal_unix -e 'puts $$; exec "echo $$"'
461
461
~/projects/jruby ➔ cat real_unix.rb
require 'ffi'
# This is just an hint for a simple Redis caching "framework" using Sinatra
# A friend of mine asked for something like that, after checking the first two gems realized there was
# a lot of useless complexity (IMHO). That's the result.
#
# The use_cache parameter is useful if you want to cache only if the user is authenticated or
# something like that, so you can do cache_url(ttl,User.logged_in?, ...)
require 'rubygems'
require 'sinatra'
require 'redis'