Skip to content

Instantly share code, notes, and snippets.

View gist:3124933
1.8.7 :001 > ["asdf"].to_s
=> "asdf"
1.9.3p125 :001 > ["asdf"].to_s
=> "[\"asdf\"]"
View gist:3091781
def is_binary_data?
( self.count( "^ -~", "^\r\n" ).fdiv(self.size) > 0.3 || self.index( "\x00" ) ) unless empty?
end
@morten
morten / gist:1989043
Created Mar 6, 2012
Response structures for a JSON API
View gist:1989043

Exploring how to place navigational and other meta concerns in a JSON API.

A set of meta attributes

Mandates that there will always be a "values" key in the collection hash.

// This is a collection of boats
"boats": {
View gist:1598652
require 'benchmark'
require 'psych'
require 'yaml'
data = [ 1 , { "hello hello" => "moo moo", :aaa => [] } ] * 100
yaml = YAML.dump(data)
time = Benchmark.realtime { 10000.times { YAML.load(yaml) }}
puts "Time #{YAML}: #{time}"
View gist:1445004
redis> lpush foo 1
(integer) 1
redis> lpush foo 2
(integer) 2
redis> lpush foo 3
(integer) 3
redis> lpop foo
"3"
redis> llen foo
(integer) 2
View gist:1407619
POST /forums/{id}/entries.{format}
curl -v -u {email_address}:{password} https://{subdomain}.zendesk.com/forums/{id}/entries.json \
-H "Content-Type: application/json" -H "Accept: application/json" -X POST \
-d '{"entry": {"title": "My Entry", "body": "This is an entry. It belongs to a forum"}}'
Or pass the forum_id in the request body:
POST /entries.{format}
View gist:597012
This gist shows 2 failing runs. One where sending 17K requests,
the second sending 2 x 8500 hits. Both fail.
morten@pokker ~$ ab -c 100 -n 17000 http://0.0.0.0:9000/wibble
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)
View gist:597004
require 'rubygems'
require 'eventmachine'
require 'evma_httpserver'
module Simpleton
include EventMachine::HttpServer
def self.run
EventMachine::run do
EventMachine::start_server('0.0.0.0', 9000, self)