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 -wKU | |
require "yaml" | |
=begin | |
TODO this could all use a little DRYing up | |
=end | |
class Event | |
TYPE_PATTERN = /public\s+static\s+(?:const|var)\s+([A-Z_]+)\s+:\s+String\s+=\s+(.*?);/ | |
CLASS_PATTERN = /public\s+class\s+(\w+)\s+extends\s+Event/ |
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 User < Struct.new(:name, :phone, :email) | |
end | |
# --------------------------------------------------------------------------- | |
# Extend on demand | |
# + no dependency on User class, could be reusable | |
# + composable | |
# - cannot unextend user object once extended, but this object could be short | |
# lived | |
# --------------------------------------------------------------------------- |
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
app.get '/riders', (req, res) -> | |
redis.smembers 'riders', ( err, replies ) -> | |
pool = new RequestPool ( rider, callback ) -> redis.hgetall rider, callback | |
pool.push rider for rider in replies | |
pool.go -> alert 'Done!' |
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
# convert mov to ogv | |
ffmpeg -i RFI_CaseStudy_V3b_DS_720p.mov -vb 3221700 -f ogg RFI.ogv | |
# convert mov to webm | |
ffmpeg -i RFI_CaseStudy_V3b_DS_720p.mov -vb 3221700 -f webm RFI.webm | |
# get a screenshot at the 14s mark | |
ffmpeg -ss 00:00:14 -i RFI_CaseStudy_V3b_DS_720p.mov -vframes 1 RFI.png |
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
[{"timestamp":new Date( 2011, 0, 30 ),"identity":"john","event":"signed in"},{"timestamp":new Date( 2011, 0, 15 ),"identity":"john","event":"signed in"},{"timestamp":new Date( 2011, 0, 1 ),"identity":"john","event":"signed in"},{"timestamp":new Date( 2011, 1, 15 ),"identity":"paul","event":"signed in"},{"timestamp":new Date( 2011, 9, 15 ),"identity":"ringo","event":"signed in"},{"timestamp":new Date( 2011, 10, 15 ),"identity":"ringo","event":"signed in"},{"timestamp":new Date( 2011, 11, 15 ),"identity":"ringo","event":"signed in"}].forEach( function( event ){ db.events.insert( event ); } ); |
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 version works in Rails 3.2 | |
require 'redcarpet' | |
class ActionView::Template | |
class Redcarpet | |
def call( template ) | |
renderer.render( template.source ).inspect | |
end |
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 'fog' | |
module AWS | |
class Client | |
def initialize( options={} ) | |
@access_key = options.delete( :access_key ) or raise "AWS::Client requires an :access_key" | |
@secret_key = options.delete( :secret_key ) or raise "AWS::Client requires a :secret_key" | |
@bucket_name = options.delete( :bucket_name ) or raise "AWS::Client requires a :bucket_name" | |
@aws_region = options.delete( :aws_region ) | |
end |
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
--type-add=ruby=.erb,.haml,.rabl | |
--type-add=js=.coffee | |
--type-add=css=.sass,.scss,.less | |
--type-set=log=.log | |
--nolog |
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 DeliverMessage | |
def self.perform( id ) | |
Message.find( id ).deliver | |
end | |
def self.before_perform_ensure_not_delivered( id ) | |
raise Resque::Job::DontPerform if Message.find( id ).delivered? | |
end |
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, :b, :c ].inject( [ [] ] ) { |arr, n| arr.push( arr.last.dup << n ) }.reverse | |
# => [[:a, :b, :c], [:a, :b], [:a], []] | |
class Array | |
def countdown | |
inject( [ [] ] ) { |arr, n| arr.push( arr.last.dup << n ) }.reverse | |
end | |
end | |
query = { |
OlderNewer