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
View = {} | |
(function(){ | |
var self = View; | |
View.init = function() { | |
$('[href=#evt-name]').click(this.revealEventName); | |
$('[href=#evt-when]').click(this.revealEventWhen); | |
}, | |
View.revealEventName = function() { |
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
(defun btrees-of-size (n) | |
(cond ((= n 1) (list 'leaf)) | |
((= n 2) (list (cons 'leaf 'leaf))) | |
(t (loop for i from 1 to (- n 1) | |
append (loop for j in (btrees-of-size i) | |
append (loop for k in (btrees-of-size (- n i)) | |
collect (cons j k))))))) | |
(defun gen-combos (items n callback &optional accum) | |
(cond ((= n 0) (funcall callback accum)) |
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
# original implementation by jcl; see http://pastie.org/777044 | |
import time | |
start_time = time.time() | |
_eq_map_cache = {} | |
# | |
def get_eq_map(vals): | |
# Given a list of floating point values, returns a map from result values | |
# to an equation string returning that result. | |
global _eq_map_cache |
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
# global cache removed | |
import time | |
start_time = time.time() | |
# | |
def get_eq_map(vals): | |
# Given a list of floating point values, returns a map from result values | |
# to an equation string returning that result. | |
if len(vals) == 1: | |
return {vals[0]: str(vals[0])} |
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
def get_value_map(vals): | |
if len(vals) == 1: | |
return {vals[0]: str(vals[0])} | |
else: | |
eq_map = {} | |
for i in range(1, len(vals)): | |
for h, heq in get_value_map(vals[:i]).iteritems(): | |
for t, teq in get_value_map(vals[i:]).iteritems(): | |
eq_map[h + t] = "(" + heq + "+" + teq + ")" | |
eq_map[h - t] = "(" + heq + "-" + teq + ")" |
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 'crack' | |
xml = <<EOX | |
<credits> | |
<credit currency="GBP">100</credit> | |
<credit currency="USD">150</credit> | |
</credits> | |
EOX |
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
# see actionpack/lib/action_dispatch/routing/route_set.rb | |
module ActionDispatch | |
module Routing | |
class RouteSet | |
class Generator | |
# modified to allow :identify option ala Merb routing | |
def opts # :nodoc: | |
parameterize = lambda do |name, value| | |
to_param = lambda do |val| | |
if options[:identify] and name == :id and not val.is_a?(String) |
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
class << ActiveRecord::Base | |
def ddl_transaction(&block) | |
if connection.supports_ddl_transactions? | |
transaction { block.call } | |
else | |
block.call | |
end | |
end | |
end |
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 'goliath' | |
require 'yajl' | |
# adapted from goliath/examples/async_upload.rb | |
class AsyncUpload < Goliath::API | |
use Goliath::Rack::Params # parse & merge query and body parameters | |
use Goliath::Rack::DefaultMimeType # cleanup accepted media types | |
use Goliath::Rack::Render, 'json' # auto-negotiate response format | |
def on_headers(env, headers) |
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 | |
# usage: | |
# $ tail -5000 sidekiq.log | ./parse_sidekiq_logs.rb | |
class Averager | |
def initialize | |
@count = 0 | |
@total = 0.0 | |
end |
OlderNewer