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 | |
dry_run = ARGV.delete('--dry-run') | |
force = ARGV.delete('--force') | |
if ARGV.empty? | |
puts <<-USAGE | |
minify, swiftly concat and minify JavaScript files from the command line | |
Pass a single argument to create a .min.js version: |
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
# .___.__ | |
# __| _/|__| ____ ____ | |
# / __ | | |/ \ / ___\ | |
# / /_/ | | | | \/ /_/ > | |
# \____ | |__|___| /\___ / | |
# \/ \//_____/ | |
# | |
# Make a "ding" sound on your Mac! Useful for notifying you when a command | |
# line script has finished. | |
# |
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
Post('post', { | |
validations: { | |
presence: ['title', 'body'], | |
length: { | |
title: { min: 20 }, | |
body: { max: 2000 } | |
} | |
} | |
}) |
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
var localStoragePlusRest = function() { | |
var rest_args = Array.prototype.slice.call(arguments) | |
return function(klass) { | |
var local = Model.LocalStorage(klass) | |
var rest = Model.RestPersistence.apply( | |
Model.RestPersistence, rest_args)(klass) | |
return { | |
create: function(model, callback) { |
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
<html> | |
<head> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js"></script> | |
<script src="http://github.com/documentcloud/underscore/raw/master/underscore-min.js"></script> | |
<script src="http://github.com/benpickles/js-model/raw/master/dist/js-model-0.8.1.min.js"></script> | |
<script> | |
var Post = Model('post', {}, { | |
validate: function() { | |
if (this.attr("title") != "Bar") { | |
this.errors.add("title", "should be Bar") |
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
module ActiveRecord | |
class Errors | |
def to_json | |
inject({}) { |hash, error| | |
attribute, message = error | |
hash[attribute] ||= [] | |
hash[attribute] << message | |
hash | |
}.to_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
#!/usr/bin/env ruby | |
require 'pathname' | |
require 'yaml' | |
conf = Pathname.new(Dir.pwd).join('config', 'database.yml') | |
if conf.exist? | |
env = ARGV.first || ENV['RAILS_ENV'] || 'development' | |
yaml = YAML.load(conf.read) |
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
# Brutal hack to make all string/text columns alert("hack") if they're not | |
# being properly escaped. | |
models = Dir['app/models/*.rb'].map { |path| | |
name = File.basename(path, '.*') | |
name.camelize.constantize | |
}.reject { |klass| | |
klass.superclass != ActiveRecord::Base | |
} |
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 'httparty' | |
class GoogleClosure | |
include HTTParty | |
base_uri 'closure-compiler.appspot.com' | |
def self.compile(path) | |
contents = File.read(path) |
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 'benchmark' | |
Dir.mkdir('results') unless File.exists?('results') | |
$stdout = File.new("results/#{Process.pid}.txt", 'w') | |
puts "Start: #{Time.now.strftime('%H:%M:%S')}" | |
array = (1..1000000).map { rand }; nil | |
Benchmark.bmbm do |x| |