Skip to content

Instantly share code, notes, and snippets.

Morten Primdahl morten

Block or report user

Report or block morten

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
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?
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
redis> llen foo
(integer) 2
View gist:1407619
POST /forums/{id}/entries.{format}
curl -v -u {email_address}:{password} https://{subdomain}{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
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd,
Licensed to The Apache Software Foundation,
Benchmarking (be patient)
View gist:597004
require 'rubygems'
require 'eventmachine'
require 'evma_httpserver'
module Simpleton
include EventMachine::HttpServer
EventMachine::run do
EventMachine::start_server('', 9000, self)
You can’t perform that action at this time.