Skip to content

Instantly share code, notes, and snippets.

View mattyoho's full-sized avatar

Matt Yoho mattyoho

  • Portland, OR, USA
View GitHub Profile
@mattyoho
mattyoho / music_library.rb
Created December 20, 2011 16:49 — forked from stevenharman/music_library.rb
When wrapping AR behind an intentional interface, go explicit or generic/idiomatic?
# This is a record, as in a vinyl.
class Record < ActiveRecord::Base
belongs_to :user
belongs_to :album
# explicitly stating what is needed
def from_library_for_album(collector, album)
where(user_id: collector).where(album_id: album)
end
person = {
save: function(){
$.ajax('...', {
context: this,
success: this.saved,
error: this.errored
})
},
saved: function(data){
console.log('OMG. USEFUL SCOPING.')
@mattyoho
mattyoho / ios-test.css
Created October 19, 2011 19:12 — forked from tonywok/ios-test.css
iOS Media Queries
// iOS Media Queries
// Goal: capture styles for iPhone, iPhone 3G, iPhone 3GS, iPhone 4, iPhone 4S, iPad, and iPad 2
//
// Author: Tony Schneider (@tonywok)
// Please tell me where I fail. :)
// iPhone v(4,4S) portrait
// test: black text (overwritten by v* portrait) with blue background
@media all and (-webkit-min-device-pixel-ratio: 2) and (orientation: portrait) {
a {
@mattyoho
mattyoho / gist:1200480
Created September 7, 2011 12:56 — forked from catharinejm/gist:1196418
inner function closure in C
#include <stdlib.h>
#include <stdio.h>
int(*outer(int val))() {
int inner() {
return val;
}
return inner;
}
@mattyoho
mattyoho / gist:1015011
Created June 8, 2011 18:30 — forked from dhh/gist:1014971
Use concerns to keep your models manageable
# autoload concerns
module YourApp
class Application < Rails::Application
config.autoload_paths += %W(
#{config.root}/app/controllers/concerns
#{config.root}/app/models/concerns
)
end
end
# 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'
@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'

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.

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
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