Skip to content

Instantly share code, notes, and snippets.

Avatar

Philip (flip) Kromer mrflip

View GitHub Profile
View optional args in lambdas.rb
# this works
a = lambda{ |b| b*3 }
# => #<Proc:0x01f5f540@(irb):125>
a.call 4
# => 12
# strangely, this does too (with a warning)
a.call 4, 6
# (irb):125: warning: multiple values for a block parameter (2 for 1)
# from (irb):131
@mrflip
mrflip / gist:7983
Created Aug 29, 2008
Tab complete the 'open' command in OSX
View gist:7983
# http://woss.name/2005/09/06/bash-completion-for-mac-os-x-open/
if [ "`uname`" = "Darwin" ]; then
_open() {
local cur prev
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
if [ "${prev}" = -a ]; then
local IFS=$'\n'
View L_project.sh
== An elementary as hell solution to stephenfry's #L challenge: ==
-- Get the twitter scrape from infochimps.org
-- http://blog.infochimps.org/2008/12/29/massive-scrape-of-twitters-friend-graph/
-- (not available yet, but sometime soon)
--
-- Then run this pig (http://wiki.apache.org/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 http://hashtags.org/tag/l
# "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
http://github.com/binarylogic/authlogic/tree/master
http://www.binarylogic.com/2008/11/21/tutorial-using-openid-with-authlogic
http://binarylogic.lighthouseapp.com/projects/18752-authlogic/tickets
http://github.com/mischa/auth_store/tree/master
http://github.com/josh/rack-openid/tree/master
--------------------
http://guides.rubyonrails.org/2_3_release_notes.html
http://weblog.rubyonrails.org/2009/1/26/nested-model-forms
http://ryandaigle.com/articles/2009/2/1/what-s-new-in-edge-rails-nested-attributes
http://gist.github.com/78393
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]
end
end
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, values.map(&:last).map(&:to_i).sum ]
end
end
View gist:134896
module Wuclan::Models
#
# Text and metadata for a twitter status update
#
class Tweet < TypedStruct.new(
:id,
:created_at,
:twitter_user_id,
:favorited,