Skip to content

Instantly share code, notes, and snippets.

{ disableIndentCorrections = :true; }
#!/usr/bin/env ruby
require 'rest-client'
require 'nokogiri'
addresses = (1..10).inject([]) do |addresses, page|
$stderr.puts "fetching page #{page}"
html = RestClient.get 'http://mcserverlist.net/lists/top', params: {page: page}
doc = Nokogiri::HTML(html)
addresses += doc.css('.ip-and-port').map {|node| node.text.strip }
@chrislloyd
chrislloyd / grp.rb
Created April 10, 2012 23:14
Handy grouping funtion
#!/usr/bin/env ruby
require 'active_support/core_ext'
abort("usage: #{__FILE__} day|week|month") unless %w(day week month).include?(ARGV[0])
$stdin.readlines.map {|l|
timestamp, amount = l.strip.split(',', 2)
[Time.at(timestamp.to_i), amount.to_i]
}.group_by {|(time, _)|
case ARGV[0]
namespace :db do
task :pivot => :environment do
schema = Mongoid::Config.master[:schema_info]
pivots = Dir[File.join('db', 'pivots', '*.rb')]
previous_pivots = schema.find.map {|p| p['file']}
pivots_to_run = (pivots - previous_pivots).sort
@chrislloyd
chrislloyd / malfunction
Created November 30, 2011 03:59
malfunction
all for the best - thom yorke
feels like ecstasy - 65daysofstatic
evan spring - plaid
szerencsétlen - venetian snares
known(1) - autechre
sweet love for planet earth - fuck buttons
it's guy time (i don't mind) - 65daysofstatic
the end - enduser
down - drumcorps
skip divided (modselektor remix) - thom yorke
task1.hs:43:22:
Could not deduce (a ~ Query)
from the context (Data a)
bound by a type expected by the context: Data a => a -> a
at task1.hs:(42,14)-(44,22)
`a' is a rigid type variable bound by
a type expected by the context: Data a => a -> a at task1.hs:42:14
In the expression: a
In a case alternative: (SNot (SNot a)) -> a
In the expression:
require 'benchmark'
require 'redis'
require 'digest/md5'
n = 10000
redis = Redis.new
Benchmark.bm do |bm|
bm.report do
n.times { Digest::MD5.hexdigest 'christopher.lloyd@gmail.com' }
eg1 = ['not', ['nor', ['var', 'a'], ['var', 'c']]]
eg2 = ['nor', ['nor', ['var', 'a'], ['var', 'b']], ['var', 'a']]
eg3 = ['not', ['nor', ['var', 'a'], ['var', 'b']]]
findVars = (q) ->
switch q[0]
when 'nor'
# Intersect these two vals
findVars(q[1]) + findVars(q[2])
when 'not' then findVars(q[1])

So why is the asset pipeline awesome?

  1. Works on Heroku. Also, Cedar is awesome.
  2. Minifies/gzips assets in production, leaves them raw in dev.
  3. gem 'backbone-rails' and in your application.js.coffee #= require backbone. Bam!
@chrislloyd
chrislloyd / heroku-switch.sh
Created July 23, 2011 14:06
Switch Heroku accounts
heroku-switch() {
cd $HOME/.heroku
ln -fs $1.credentials credentials
}