Skip to content

Instantly share code, notes, and snippets.

/* Rules:
* - no includes
* - play by the spirit of the game
* - sort any set of positive numbers in as few characters as possible
* - just define minisort.c
* - -Wall -Wextra must produce no warnings
* - test with ./driver 4 1 2 65 92 etc
*/
void sort(int *a, int i) {
require './disjoint-union'
def to_dot
puts "digraph {"
for n in @nodes
puts "\t#{n.value} -> #{n.parent.value};"
end
puts "}\n\n"
end
src = open(caller[-2].split(':').first).read
eval src.gsub(/[\S]/, '').split("\n").drop(1).map {|x| x.size.chr }.join('')
@efoxepstein
efoxepstein / gist:810414
Created February 3, 2011 23:03
statusdot API requests
require 'digest/sha2'
args = {
host: 'example.com',
status: 'up',
custom_status: 'All services restored',
timestamp: Time.now.utc.to_s
}
# Signature is:
# create the instance and set up the roles
i = Instance.create(:long_name => "Instance Long Name")
i.short_name = "short_name"
i.roles = Role.default_setup
i.save
# create a new user
u = User.create(:first_name => "John", :last_name => "Smith", :email => "johnsmith@example.com")
u.role = i.roles.find_by_name('Super Administrator') # assign a role
u.generate_salt!
@efoxepstein
efoxepstein / gist:635705
Created October 20, 2010 03:30
Automatically reload stylesheets with JQuery
$(function(){
setInterval(function(){
$("link").each(function(){
this.href = this.href.replace(/\?.*|$/,"?"+ new Date().getTime());
});
}, 1000);
});
require 'net/http'
require 'rubygems'
require 'hpricot'
require 'open-uri'
require 'active_support'
entries = %w[
http://nodeknockout.com/teams/jackalope
http://nodeknockout.com/teams/medium
http://nodeknockout.com/teams/speedo
require 'rubygems'
require 'sinatra/base'
class A < Sinatra::Base
before { puts 'A in' }
after { puts 'A out' }
end
class B < Sinatra::Base
before { puts 'B in' }
%w(rubygems sinatra active_record models json).each{|lib| require lib}
get %r{/assignments/reconcile(\.json)?}' do |capture|
@reconcile = reconcile_assignments
if capture
@reconcile.to_json
else
erb :reconcile
end
end
def setup
size 600, 600
end
def draw
background 255
within_matrix do
translate 300, 300
rotate 3.1415/4
fill 128