Skip to content

Instantly share code, notes, and snippets.

#Small function to generate a comma delimited dictionary on a unix system
def gen_dictionary
f = open("| cat /usr/share/dict/words")
g = Array.new
while (foo = f.gets)
g << foo.strip
end
puts g.join(', ')
end
#Subclassing Array instead of including Enumerable
class Core < Array
attr_reader :name
def initialize( name, data )
@name = name
self[0..-1] = data
end
# List of environments and their heroku git remotes
ENVIRONMENTS = {
:staging => 'myapp-staging',
:production => 'myapp-production'
}
namespace :deploy do
ENVIRONMENTS.keys.each do |env|
desc "Deploy to #{env}"
task env do
//
// Backbone.Rails.js
//
// Makes Backbone.js play nicely with the default Rails setup, i.e.,
// no need to set
// ActiveRecord::Base.include_root_in_json = false
// and build all of your models directly from `params` rather than
// `params[:model]`.
//
// Load this file after backbone.js and before your application JS.
Some brief instructions on how to use Sprocket 2 in Rails to get CoffeeScript
powered JS and SASS powered CSS with YUI compression all via the magic of rack.
This stuff will be native in Rails 3.1 and the layout of the files on the
filesystem will be different but this guide will get you working with it
while we wait for all that to finalize.
Ignore the number prefixes on each file. This is just to ensure proper order in the Gist.
It's based on eric1234 gist https://gist.github.com/911003. ijust made it 3.1 compliant in terms of convention
@latentflip
latentflip / golf.rb
Created May 23, 2011 18:26 — forked from morganp/golf.rb
L/SH/ScotRug Code Golf
g=Golf=Hash
def g.method_missing s, a
k=[]
case s.to_s[-1]
when ?1
a.reduce :*
when ?2
a.split.sort_by{|i| i[1] }*' '
when ?3
h1 1..a
@latentflip
latentflip / wordpress2tumblr.rb
Created July 17, 2011 10:07 — forked from webcracy/wordpress2tumblr.rb
A script to import your Wordpress posts on Tumblr
# Export your Wordpress posts to Tumblr (also allows to delete some.)
# Author: Alexandre Solleiro <alex@webcracy.org>
# How-to:
# 1. Export your Wordpress posts (http://en.blog.wordpress.com/2006/06/12/xml-import-export/)
# 2. Edit the information below to match your settings
# 3. To import, type "ruby wordpress2tumblr.rb --run" in the command line
# 4. To delete some posts, type "ruby wordpress2tumblr.rb --delete 1,2,3,4" where 1,2,3,4 are post numbers. (Be careful not to use spaces between IDs)
# Edit these
WP_EXPORT_PATH = "./wordpress.2009-09-14.xml" # path to the Wordpress Export file
"hello" === "hello #true
String("hello") === "hello" #true
new String("hello") === "hello" #false
new String("hello") == "hello" #true
@latentflip
latentflip / game_of_life.coffee
Created October 28, 2012 22:52 — forked from joejag/game_of_life.coffee
Conways Game of Life in CoffeeScript
# Utility methods
flatten_nested_array = (array) ->
[].concat array...
includes = (item, coll) ->
item = key_to_array(item)
for potential_match in coll
return true if item[0] == potential_match[0] && item[1] == potential_match[1]
false
$.getJSON('https://github.com/users/'+document.location.href.split('/')[3]+'/contributions_calendar_data', weekendWork);
function weekendWork(contribs) {
var inwe = false, streak = 0, highest = 0, total = 0, possible = 0;
contribs.forEach(function (c) {
var d = new Date(c[0]).getDay();
if (d === 6) {
inwe = true;
} else if (d === 0 && inwe) {
possible++;
if (c[1] !== 0) {