This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Because Unicorn is such a brilliant piece of software, it wraps older, | |
# non-Rack versions of Rails in a Rack handler. That way Unicorn | |
# itself can target Rack and not have to worry about monkey patching | |
# Rails' dispatcher. | |
# | |
# This means we can do the same, and even more. | |
# | |
# Starting Rackhub locally: | |
# | |
# Thin: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# Usage: gemspec [-s] GEMNAME | |
# | |
# Prints a basic gemspec for GEMNAME based on your git-config info. | |
# If -s is passed, saves it as a GEMNAME.gemspec in the current | |
# directory. Otherwise prints to standard output. | |
# | |
# Once you check this gemspec into your project, releasing a new gem | |
# is dead simple: | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
= Ruby Packaging Standard | |
The aim of this document is two-fold. First, to specify a common | |
structure of how a Ruby package distributed as source (that is, but | |
not limited to, development directories, version-controlled | |
repositories, .tar.gz, Gems, ...) should conform to. | |
Second, to document common and proven ways to structure Ruby packages, | |
and to point out certain anti-patterns that sneaked into common use. | |
It is by intent not to innovate. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* This is when a refactoring really pays off. | |
* | |
* In order to make your code more modular, avoid hard-coding assumptions (or refactor them away). | |
* The most fundamental, anti-modular assumption in Object-Oriented software is the concrete type of objects. | |
* Any time you write "new MyClass" in your code (or in Ruby MyClass.new) you've hardcoded | |
* an assumption about the concrete class of the object you're allocating. These makes it impossible, for example, | |
* for someone to later add logging around method invocations of that object, or timeouts, or whatever. | |
* | |
* In a very dynamic language like Ruby, open classes and method aliasing mitigate this problem, but | |
* they don't solve it. If you manipulate a class to add logging, all instances of that class will have |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'open-uri' | |
# url dsl -- the ultimate url dsl! | |
# | |
# You just can't beat this: | |
# | |
# $ irb -r url_dsl | |
# >> include URLDSL | |
# => Object | |
# >> http://github.com/defunkt.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Object | |
def send_through(object, *args) | |
object.dispatcher_for(self).call(self, *args) | |
end | |
end | |
module Dispatcher | |
class DispatcherNotFound < StandardError; end | |
def self.extended(klass) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# put this in ~/.bash_profile or whatever | |
ruby_or_irb () { | |
if [ "$1" == "" ]; then | |
irb | |
else | |
ruby "$@" | |
fi | |
} | |
alias ruby="ruby_or_irb" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* a smart poller for jquery. | |
* (by github) | |
* | |
* simple example: | |
* | |
* $.smartPoller(function(retry) { | |
* $.getJSON(url, function(data) { | |
* if (data) { | |
* doSomething(data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FilterableEnumerable | |
def initialize(original) | |
@original = original | |
end | |
def ==(value) | |
@original.select { |v| v == value } | |
end | |
def method_missing(sym, *args, &block) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'redis' | |
require 'rfeedparser' | |
$redis = Redis.new | |
class Tweet < Struct.new(:tweet_id, :text, :author, :link) | |
def self.parse(item) | |
self.new("tweet/#{item['id']}", item.title, item.author.split.first, item.link) | |
end |
NewerOlder