Skip to content

Instantly share code, notes, and snippets.

View paul's full-sized avatar

Paul Sadauskas paul

View GitHub Profile
require 'active_support/time_with_zone'
class ActiveSupport::TimeWithZone
def to_json(options = nil)
utc.xmlschema.to_json
end
end
module Jrb
$ ruby split_vs_regex.rb
user system total real
split 9.080000 0.020000 9.100000 ( 9.081937)
regex 9.810000 0.010000 9.820000 ( 9.810586)

Filtered Metrics

GET /metrics?hostname=example.com&any_part[]=cpu&any_part[]=load
{
  latest_datapoints_href: "http://tychoapp.com/metrics/datapoints/latest?hostname=example.com&any_part[]=cpu&any_part[]=load",
  datapoints_for_interval_href: "http://tychoapp.com/metrics/datapoints?hostname=example.com&any_part[]=cpu&any_part[]=load",
  items: [

{

GET /metrics?hostname=example.com&any_part[]=cpu&any_part[]=load
{
  latest_datapoints_href: "http://tychoapp.com/metrics/datapoints/latest?hostname=example.com&any_part[]=cpu&any_part[]=load",
  datapoints_for_interval_href: "http://tychoapp.com/metrics/datapoints?hostname=example.com&any_part[]=cpu&any_part[]=load",
  items: [
    {
      href: "http://tychoapp.com/metrics/example.com/cpu/0/idle",

name: "example.com/cpu/0/idle"

require 'benchmark'
class Dummy
attr_writer :setter
def orig(att, value)
send("#{att}=", value) if respond_to?("#{att}=")
end
@paul
paul / gist:981186
Created May 19, 2011 16:33 — forked from TwP/gist:981176
Using AD's ParamsParser middleware
require 'yajl'
module Ssaj
PARSER = Proc.new do |data|
HashWithIndifferentAccess.new(Yajl::Parser.parse(data))
end
ActionDispatch::ParamsParser::DEFAULT_PARSERS[Mime::SSAJ1] = PARSER
>> Regexp.compile('(')
RegexpError: premature end of regular expression: /(/
from (irb):13:in `initialize'
from (irb):13:in `compile'
from (irb):13
from :0
>> Regexp.compile('foo{1|2}')
(irb):14: warning: regexp has invalid interval
(irb):14: warning: regexp has `}' without escape
$ irb
>> require 'active_support/core_ext/numeric/time'
=> true
>> 1.hour.ago
NoMethodError: undefined method `current' for Time:Class
from /Users/rando/.rvm/gems/ree-1.8.7-2011.03@core/gems/activesupport-3.0.5/lib/active_support/duration.rb:68:in `ago'
from (irb):2
>> require 'active_support/core_ext/time/calculations'
=> true
>> 1.hour.ago

HTTP Client bug in Chrome (and Safari)

We have a resource, /clients, that serves up both html and a custom json flavor, ssjk1. We set the response Vary header to include Accept. If we first request the resource as sskj1 then sometime later as the normal browser Accept header (*/*), we should get html. However, Chrome (and Safari) make a conditional HTTP request with If-Modified-Since.

Chromium Issue

# Using javascript to tell the browser to make a web service request (sskj1)
GET /clients HTTP/1.1
Accept-Charset: UTF-8,*;q=0.5
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept: application/vnd.absperf.sskj1+json, application/vnd.absperf.ssmj1+json
Cache-Control: max-age=0
Connection: keep-alive
Cookie: ssbe_current_account=...