Skip to content

Instantly share code, notes, and snippets.


Philip (flip) Kromer mrflip

View GitHub Profile
View optional args in lambdas.rb
# this works
a = lambda{ |b| b*3 }
# => #<Proc:0x01f5f540@(irb):125> 4
# => 12
# strangely, this does too (with a warning) 4, 6
# (irb):125: warning: multiple values for a block parameter (2 for 1)
# from (irb):131
mrflip / gist:7983
Created Aug 29, 2008
Tab complete the 'open' command in OSX
View gist:7983
if [ "`uname`" = "Darwin" ]; then
_open() {
local cur prev
if [ "${prev}" = -a ]; then
local IFS=$'\n'
== An elementary as hell solution to stephenfry's #L challenge: ==
-- Get the twitter scrape from
-- (not available yet, but sometime soon)
-- Then run this pig ( code
-- to extract all twitter screen names with three or more L's
-- It's not properly case insensitive but who cares.
View gist:50411
# Words by L-fraction, from lull to zill to algebraically
# All words valid in US Scrabble that are
# composed of 21% or more L's (including space),
# sorted by descending L-fraction. For help in
# @stephenfry's
# "L challenge"
View Nested Model Forms
Nested Model Forms
Posted by michael January 26, 2009 @ 08:55 AM
The most popular request on our new Feedback site was for the ability to easily manage multiple models in a single form. Thankfully Eloy Duran has a patch that does just this. But before we roll it into rails 2.3 we want to get some more feedback from you guys. Eloy's written this brief introduction to the patch, so take a look, and add any feedback you have to the lighthouse ticket.
In Rails it has always been a little tricky to create a single form for both a model and its associations. Last summer, the :accessible option was committed as a first stab at a unified solution for dealing with nested models. However, this feature was pulled before the 2.2 release because it only supported nested models during object creation.
The resulting discussion on the core mailing list and our need for mass assignment have resulted in this patch for ticket #1202 which is now up for scrutinizing.
View gist:78483
View gist:111459
// IE also doesn't set the accept headers correctly, so you have
// to request a file with the right extension (.js, probably).
// If you're not using one of the ruby remote form doodads,
// you'll want to ensure the form is sent to /widget/69.js
// and not the default /widget/69 :
// make forms do remote requests
jQuery.fn.submitWithAjax = function(){
this.submit(function () {
// Amend the URL for submitting this form to have a .js extension
View freq_user.rb
module FreqUser
class Mapper < Wukong::Streamer::StructStreamer
# extract just the word
def process thing, &block
next unless thing.is_a? TweetToken
yield [thing.user_id, thing.word]
View word_count.rb
# Three more ways to cheat:
# Stack up all the values in a list then sum them at once:
require 'active_support/core_ext/enumerable'
class Reducer1 < Wukong::Streamer::ListReducer
def finalize
yield [ key, ]
View gist:134896
module Wuclan::Models
# Text and metadata for a twitter status update
class Tweet <