Skip to content

Instantly share code, notes, and snippets.

@morten
morten / gist:3124933
Created July 16, 2012 20:46 — forked from osheroff/gist:3005667
array to_s
1.8.7 :001 > ["asdf"].to_s
=> "asdf"
1.9.3p125 :001 > ["asdf"].to_s
=> "[\"asdf\"]"
def is_binary_data?
( self.count( "^ -~", "^\r\n" ).fdiv(self.size) > 0.3 || self.index( "\x00" ) ) unless empty?
end
@morten
morten / gist:1989043
Created March 6, 2012 21:22
Response structures for a JSON API

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": {
@morten
morten / gist:1598652
Last active September 29, 2015 12:08
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}"
@morten
morten / gist:1445004
Created December 7, 2011 22:21
Redis expiry
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
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}
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)
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)