Skip to content

Instantly share code, notes, and snippets.

View tobi's full-sized avatar

Tobias Lütke tobi

View GitHub Profile
@tobi
tobi / gist:911797
Created April 9, 2011 21:32
wtf.js
var ary = ['a', 'b', 'c'];
var funcs = [];
for (var i = 0; i < ary.length; i++) {
var c = ary[i]
funcs.push(function() { console.log(c) })
};
for (var i = 0; i < funcs.length; i++) {
@tobi
tobi / shopify_stats.rb
Created March 6, 2011 18:58
What would a stats server backed by redis look like?
require 'rubygems'
require 'redis'
$redis = Redis.new
class Request
def referrer
'http://www.google.com/search?q=Shopify+Store'
end
@tobi
tobi / gist:798674
Created January 27, 2011 15:59
smart_mta.rb
# SmartMta
class SmartMta
include HTTParty
base_uri 'http://smartmta.sendlabs.com/rest/json'
cattr_accessor :api_key
def self.add_sender(email)
# simple extension to ActiveMerchant for basic support of recurring payments with Express Checkout API
#
# See http://http://clockobj.co.uk/2008/09/07/ruby-on-rails-paypal-express-recurring-payments-using-active-merchant/
# for details on getting started with this gateway
#
#
module ActiveMerchant #:nodoc:
module Billing #:nodoc:
class PaypalExpressRecurringNvGateway < Gateway
include PaypalNvCommonAPI
..................................................................................................................................................................................................F.............
Failures:
1) Money allocating money betweeen different interest parties #allocate keeps currencies intact
Failure/Error: Money.ca_dollar(0.05).allocate([1]).should == [Money.ca_dollar(0.05)]
private method `pretty_print' called for #<RSpec::Mocks::ErrorGenerator:0x1029d8c50>
# ./spec/money_spec.rb:1070
@tobi
tobi / time_and_json.rb
Created November 3, 2010 13:38
Unexpected behavior of json before core mixins are loaded
[tobi@i7:~]% irb
ree-1.8.7-2010.02 > require 'rubygems'
=> true
ree-1.8.7-2010.02 > require 'json'
=> true
ree-1.8.7-2010.02 > JSON.parse([ Time.now ].to_json)[0].class
=> String
ree-1.8.7-2010.02 > require 'json/add/core'
=> true
ree-1.8.7-2010.02 > JSON.parse([ Time.now ].to_json)[0].class
<html>
<body>
<script>
var TestCase = function(testcase) {
var success = 0;
var failure = 0;
def self.accelerated_belongs_to(record)
klass = record.to_s.camelize.constantize
if !klass.respond_to?(:current)
raise ArgumentError, "#{record} does not implement the current class method that is needed for accelerated_belongs_to."
end
self.belongs_to record
alias_method :"#{record}_without_acceleration", record
includes = Product.includes_from_params(params)
conditions = Product.conditions_from_params(params)
@product_count = shop.products.count(:all, :include => includes, :conditions => conditions)
@products = shop.products.find(:all,
:limit => page_limit,
:offset => page_offset,
:conditions => conditions,
require 'fiber'
module Rack
class Fabric
def initialize(app)
@app = app
end
def call(env)
fib = Fiber.new do