Skip to content

Instantly share code, notes, and snippets.

View cheald's full-sized avatar

Chris Heald cheald

View GitHub Profile
require 'rubygems'
require 'rack'
require 'json'
Rack::Handler::Thin.run proc{ |env|
req = Rack::Request.new(env)
begin
json = JSON.parse(req.body.read)
[200, {"Content-Type" => "text/plain"}, json.inspect]
rescue JSON::ParserError
@cheald
cheald / curl.rb
Created September 15, 2012 19:24
domain = Curl::Easy.http_head(url) do |c|
c.follow_location = true
c.timeout = 4
end.last_effective_url
diff --git a/lib/draper/railtie.rb b/lib/draper/railtie.rb
old mode 100644
new mode 100755
index 598e44f..04d35fa
--- a/lib/draper/railtie.rb
+++ b/lib/draper/railtie.rb
@@ -24,13 +24,13 @@ module Draper
initializer "draper.extend_action_controller_base" do |app|
ActiveSupport.on_load(:action_controller) do
var s = "translate(-320px, 0)";
var iter = 1000000;
var substr = function() {
for(var i = 0; i < iter; i++) {
parseInt(s.substring(s.indexOf('(')+1, s.indexOf(",")-2))
}
}
var substr_const = function() {
<html manifest='/application.manifest'>
<body>
This is a bootstrapper page for the Mashable application manifest.
</body>
</html>
local foo = {}
function foo:Bar(text)
-- `self` is foo, `text` is the passed in parameter
end
foo.Bar(foo, "text")
foo:Bar("text")
local otherFoo = {}
-- In this invocation, "self" will be otherFoo in the method
class Host < ActiveRecord::Base
validates_associated :access_points, :switches
before_validation :set_group_sizes
def set_group_sizes
associated = (self.access_points + self.switches).group_by(&:ip)
associated.each do |ip, o|
o.each do |obj|
obj.devices_on_ip = o.length
end
@cheald
cheald / erb.txt
Created October 17, 2012 10:41
Templating benchmarks
## ERB
hamlerbslim git:(master*) ruby-1.9.3 % ab -n 1000 -c 1 http://0.0.0.0:5423/erb
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 0.0.0.0 (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
require 'rubygems'
require 'benchmark'
require 'erubis'
class Context
def initialize
@items = {
"Headline 1" => %w[Link1 Link2 Link3 Link4 Link5 Link6 Link7],
"Headline 2" => %w[Link1 Link2 Link3 Link4 Link5 Link6 Link7],
"Headline 3" => %w[Link1 Link2 Link3 Link4 Link5 Link6 Link7],