March 2010
60 posts
7 tags
F*** You Larry Ellison →
EventMachine: Scalable Non-Blocking I/O in Ruby
7 tags
9 tags
Proc.new vs lambda vs proc
ruby-doc
Proc objects are blocks of code that have been bound to a set of local variables. Once bound, the code may be called in different contexts and still access those variables.
def gen_times(factor)
return Proc.new { |n| n*factor }
end
times3 = gen_times(3)
times5 = gen_times(5)
times3.call(12) #=> 36
times5.call(5) #=> 25
times3.call(times5.call(4)) ...
4 tags
Ruby 1.9.x: j and jj
j & jj the JSON conversant relatives of p & pp, i.e. they output JSON strings on one line or pretty print them over many lines with indentation respectively.
ruby-1.9.1-p378 > require 'JSON'
=> true
ruby-1.9.1-p378 > obj = [{:foo => "bar", "baz" => [1,2,3,4,5]}]
=> [{:foo=>"bar", "baz"=>[1, 2, 3, 4, 5]}]
ruby-1.9.1-p378 > j...
6 tags
class_eval vs instance_eval
In Ruby you may have seen class_eval and instance_eval and thought to yourself “What is the difference?” They both accept a string or a block as an argument, but then they diverge:
instance_eval evaluates a string as Ruby code or a block in the context of the object’s singleton class. Effectively it changes the value of self, the implicit receiver, to be that of the...
2 tags
To Yield Or Not To Yield? That Is The Question…
Today I was looking quite closely at Rails 3, specifically the changes to the routing API.
# Rails 2.x
ActionController::Routing::Routes.draw do |map|
map.resources :posts
end
# Rails 3.x
AppName::Application.routes do
resources :posts
end
The first thing I noticed was the omission of a block variable. So I thought to myself “WTF? Is the block being instance_eval’ed instead of...
3 tags
DRY Much?
I’ve been looking through the source of ActiveSupport and Rails in general, and I’ve noticed this particularly verbose style of monkeypatching a multitude of objects with the same behaviour:
# Can you safely .dup this object?
# False for nil, false, true, symbols, numbers, class and module objects; true otherwise.
class NilClass #:nodoc:
def duplicable?
false
end
end
class...
MongoDB 1.4 Ready for Production →
Why Behavioral Economists Love Farmville →
newsweek:
(Even though we honestly think it’s kind of a waste of time)
WOW
Any new slays?
– Samuel A. Kochman
The Business Model Of The Somali Pirates Of The... →
3 tags
Maybe why you don't see recursion used much in...
I’ve become interested in recursion and functional programming lately in the interests of sharpening one’s saw, and was interested to see how recursion performed in Ruby.
Consider the following code:
require 'benchmark'
def recursive_factorial(n)
n == 0 ? 1 : n * recursive_factorial(n-1)
end
def iterative_factorial(n)
(1..n).reduce :*
end
Benchmark.bmbm do |x|
...
Oh Baby!
This is what you get when you pay $99 for web... →
Pay peanuts, get monkeys.
Guy Kawasaki New York Times Interview →
Absolutely worth reading.
4 tags
4 tags
SproutCore Blog: SproutCore and the New Logo →
sproutcore:
Just in time for SproutCore 1.0, I’m excited to officially announce that SproutCore has a new logo contributed by community member “endash”. Here’s it is: Download all the logo variations hereAlong with the new logo, we’ve also updated the SproutCore website with a simpler, but I…
Great! All we need now is API documentation! :/
P.S endash is a very helpful and knowledgeable...
2 tags
Ruby Quines
A quine is a program that prints out it’s own source code. More on that here.
s='s=;puts s[0,2]+39.chr+s+39.chr+s[2,36]';puts s[0,2]+39.chr+s+39.chr+s[2,36]
This contains a string which consists of a reference to itself and everything before and after itself. It is assigned to the local variable s so the string can be reused to take substrings that match the code declared before and after...
Ryan Leslie European Tour 2010 Recap
Shot and edited by my incredibly talented friend Evan Rogers
Ev’s new blog coming up next. ;)
5 tags
ActiveRecord models are bloated.
They handle object persistence, the object graph, business logic, and proxy data to other objects (accepts_nested_attributes_for). accepts_nested_attributes_for was the straw that broke the camel’s back for me.
More on this later.
The Dropout Economy - TIME Magazine →
brandonthegreat:
“But what if the millions of so-called dropouts are onto something? As conventional high schools and colleges prepare the next generation for jobs that won’t exist, we’re on the cusp of a dropout revolution, one that will spark an era of experimentation in new ways to learn and new ways to live.”
college is for peons
As much as I love thingsthatexciteme. It clearly... →
4 tags
Quick Tip: Ruby Monkeypatch Fail
I’m contracting at the moment, developing an internal CRM application. For authorisation I’m using Ryan Bates excellent CanCan. However, due to application requirements, I can’t control access at the resource level, it has to be done at the controller level. For this I created a little patch to extend ApplicationController:
module SG
module CanCan
module...
Math Joke
Q. What’s the integral of 1/cabin?
A. A log cabin