This file contains hidden or 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
$KCODE = "u" | |
=begin | |
A remote copy-paste responder. Launch this on a specific port, | |
then open this on a remote machine. This will give you a bookmarklet. | |
Use this bookmarklet to copy selection from the browser directly to the clipboard | |
of the machine the server is running on | |
=end | |
JS = %< | |
x = document; |
This file contains hidden or 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 "tracksperanto" | |
class Unwarp < Tracksperanto::Import::FlameStabilizer | |
def parse(io) | |
extract_channels_from_stream(io) | |
end | |
end | |
file_path = ARGV.shift |
This file contains hidden or 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 'open3' | |
require 'timecode' | |
# Acts as a thick layer of duct tape that helps us to operate on Quicktimes using ffmpeg. | |
class MovieJuggler | |
attr_accessor :logger | |
class Error < RuntimeError; end | |
class MovieIsCorrupted < Error; end |
This file contains hidden or 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
namespace :deploy do | |
desc 'Bundle and minify the JS and CSS files' | |
task :precache_assets, :roles => :app do | |
root_path = File.expand_path(File.dirname(__FILE__) + '/..') | |
jammit_path = Dir["#{root_path}/vendor/gems/jammit-*/bin/jammit"].first | |
yui_lib_path = Dir["#{root_path}/vendor/gems/yui-compressor-*/lib"].first | |
assets_path = "#{root_path}/public/assets" | |
# Precaching assets | |
run_locally "ruby -I#{yui_lib_path} #{jammit_path}" |
This file contains hidden or 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
# Used for IO objects that need to report the current offset at each operation that changes the said offset | |
# (useful for building progress bars that report on a file read operation) | |
class ProgressiveIO < DelegateClass(IO) | |
# Should contain a block that accepts the current offset in bytes and the total size | |
attr_accessor :progress_block | |
# Get or set the total size of the contained IO. If the passed IO is a File object | |
# the size will be preset automatically | |
attr_accessor :total_size |
This file contains hidden or 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 "digest" | |
# Instead of storing cached fragments in pages/widgets/2345567/description it will instead make an MD5 of | |
# each fragment name and save them in directories spread evenly, with no more than 256 directories at once. | |
# This will prevent the filesystem from going totally medieval on you after widget 4568977 has been created and | |
# cached. | |
class FragmentedStore < ActiveSupport::Cache::FileStore | |
def delete(name, options=nil) | |
super(path_to_digest_tree(name), options) | |
end | |
This file contains hidden or 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 "builder" | |
require "benchmark" | |
class WithElements < Builder::XmlMarkup | |
def some_elem(&blk) | |
self << "<some-elem>" | |
blk.call(self) | |
self << "</some-elem>" | |
end |
This file contains hidden or 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 UnicodeEnforcer | |
def new(app) | |
@app = app | |
end | |
def call(env) | |
return @app.call(env) unless env["Content-Type"] =~ "utf-8" | |
req = Rack::Request.new(env) | |
req.params = force_encoding(req.params) | |
@app.call(env) |
This file contains hidden or 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 ActiveRecord::Base | |
before_validation :strip_whitespace_from_attributes!, :stringify_content_attributes! | |
private | |
# Will strip trailing and leading whitespace from all attributes and convert | |
# empty strings to nil. | |
def strip_whitespace_from_attributes! | |
for col in self.class.content_columns.collect{|c| c.name.to_sym} | |
if !self[col].nil? && self[col].respond_to?(:strip) |
This file contains hidden or 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
def cli(argv) | |
old_stdout, old_stderr, old_argv = $stdout, $stderr, ARGV.dup | |
os, es = StringIO.new, StringIO.new | |
begin | |
$stdout, $stderr = os, es | |
ARGV.replace(argv.split) | |
load(BIN_P) | |
return [0, os.string, es.string] | |
rescue Exception => boom # The binary uses exit(), we use that to preserve the output code | |
return [boom.status, os.string, es.string] if boom.is_a?(SystemExit) |