Skip to content

Instantly share code, notes, and snippets.

View mattyoho's full-sized avatar

Matt Yoho mattyoho

  • Portland, OR, USA
View GitHub Profile
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 / calculator_test.rb
Created August 2, 2011 14:21
Test file for four-function calculator
require 'test/unit'
require File.expand_path(File.dirname(__FILE__) + '/../lib/calculator')
class CalculatorTest < Test::Unit::TestCase
def test_default_value
calc = Calculator.new
assert_equal 0, calc.value
end
def test_setting_initial_value
@mattyoho
mattyoho / error_messages_for.rb
Created July 29, 2011 13:44
Rails 3 #error_messages_for, via @j3 => @RyanBates
def error_messages_for(*objects)
options = objects.extract_options!
options[:header_message] ||= I18n.t(:"activerecord.errors.header", :default => "Invalid Fields")
options[:message] ||= I18n.t(:"activerecord.errors.message", :default => "Correct the following errors and try again.")
messages = objects.compact.map { |o| o.errors.full_messages }.flatten
unless messages.empty?
content_tag(:div, :class => "error_messages") do
list_items = messages.map { |msg| content_tag(:li, msg) }
content_tag(:h2, options[:header_message]) + content_tag(:p, options[:message]) + content_tag(:ul, list_items.join.html_safe)
end
function Hello()
{
alert("caller is " + arguments.callee.caller.toString());
}
arguments.callee.caller.name
@mattyoho
mattyoho / gist:1036397
Created June 20, 2011 19:44
Ryan Davis' book recommendations
My annual reread book is The School of Niklaus Wirth: The Art of Simplicity
Others I love:
Compiler Construction, Wirth
Effective TCP/IP Programming: 44 Tips to Improve Your Network Programs
C Programming Language
The Annotated C++ Reference Manual (first and last good book on C++, besides meyers)
Structure and Interpretation of Computer Programs
The Little Schemer, The Seasoned Schemer, (and probably Reasoned Schemer, but I haven't gotten through that yet).
@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'
require 'ruby-debug'; Debugger.start; Debugger.settings[:autoeval] = 1; Debugger.settings[:autolist] = 1; debugger