Skip to content

Instantly share code, notes, and snippets.

View mattyoho's full-sized avatar

Matt Yoho mattyoho

  • Portland, OR, USA
View GitHub Profile
@stevenharman
stevenharman / Iso8601DateTimeBinder.cs
Created November 2, 2010 19:25
an asp.net-mvc Model Binder that respects the ISO 8601 standard. look it up, yo!
using System;
using System.Globalization;
using System.Web.Mvc;
namespace Zomg.Web.ModelBinders
{
public class Iso8601DateTimeBinder : DefaultModelBinder
{
public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
{
@igrigorik
igrigorik / webapp.rb
Created November 13, 2010 21:28
Inspired by @JEG2's talk at Rubyconf... Any ruby object, as a webapp! 'Cause we can. :-)
require 'rubygems'
require 'rack'
class Object
def webapp
class << self
define_method :call do |env|
func, *attrs = env['PATH_INFO'].split('/').reject(&:empty?)
[200, {}, send(func, *attrs)]
end
~/projects ➔ gem install cloby
Successfully installed cloby-0.0.1-java
1 gem installed
Installing ri documentation for cloby-0.0.1-java...
Installing RDoc documentation for cloby-0.0.1-java...
~/projects ➔ cat simple.rb
require 'cloby'
class MyClojureObj < Clojure::Object
@rbxbx
rbxbx / lambda_methods.rb
Created December 14, 2010 01:36
define methods on a lambda, who knew. Well, probably a lot of you.
Objector = lambda do |properties|
lambda do |meth|
properties[meth]
end
end
def Objector.new(props); self[props] end
@zaius
zaius / background.sh
Created January 16, 2011 23:29
How to redirect a running process output to a file and log out
ctrl-z
bg
touch /tmp/stdout
touch /tmp/stderr
gdb -p $!
# In GDB
p dup2(open("/tmp/stdout", 1), 1)
p dup2(open("/tmp/stderr", 1), 2)
class Notification
property :name, String
belongs_to :user
end
class User
has n, :notifications
end
# Find all users with no notifications
@tmm1
tmm1 / gist:818340
Created February 9, 2011 11:31
working prototype of rbtrace
~/code/rbtrace (master*) % cat server.rb
require 'rbtrace'
while true
Dir.chdir("/tmp") do
sleep rand*0.5
end
end
~/code/rbtrace (master*) % ruby server.rb &
diff --git a/ftplugin/ruby.vim b/ftplugin/ruby.vim
index 07358b2..3b40da3 100644
--- a/ftplugin/ruby.vim
+++ b/ftplugin/ruby.vim
@@ -29,8 +29,11 @@ endif
if exists("loaded_matchit") && !exists("b:match_words")
let b:match_ignorecase = 0
+ " Go go gadget match! This ignores if, unless, while, and until if they come
+ " after non-spaces, meaning they're a post condition.
@antirez
antirez / sinatra_redis_cache.rb
Created March 22, 2011 21:06
the simplest Redis caching for Sinatra -- not even tested... consider this code just an hint
# 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'
Username = <%= @var %>