Skip to content

Instantly share code, notes, and snippets.

View jchris's full-sized avatar

Chris Anderson jchris

View GitHub Profile
require 'rubygems'
require 'json'
require 'open-uri'
scores = JSON.parse(open('http://spreadsheets.google.com/feeds/list/pVNrsh7EqwD6HkFTmS3v9aw/od6/public/values?alt=json').read); nil
# scores['feed']['entry'].length
newscores = {}
scores['feed']['entry'].each do |e|
@jchris
jchris / couchdb.yml
Created October 20, 2008 21:59 — forked from sco/couchdb.yml
---
development: &defaults
:url: http://0.0.0.0:5984/gathering
production: &production
<<: *defaults
:url: http://0.0.0.0:5984/gathering
@jchris
jchris / jquery.xdompost.js
Created November 10, 2008 23:20
for the cross domains
// cargo culted bits from here: http://dev.jquery.com/ticket/3342
// Usage:
// $.xdom.post('http://example.com/post-to-here',{"foo":"bar"});
// Sends a POST to http://example.com/post-to-here with content foo=bar
(function($) {
$.xdom = $.xdom || {};
function now(){
$ab -n 10000 -c 10 http://127.0.0.1:5984/blogdb/_view/couchdb-example-blog/recent?key=%222008-11-03T17:49:47Z%22
This is ApacheBench, Version 2.0.40-dev <$Revision: 1.146 $> apache-2.0
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Copyright 2006 The Apache Software Foundation, http://www.apache.org/
Benchmarking 127.0.0.1 (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
$ab -n 10000 -c 10 http://127.0.0.1:5984/blogdb/657a25a45525ee93eb8a0aaae7e637dfThis is ApacheBench, Version 2.0.40-dev <$Revision: 1.146 $> apache-2.0
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Copyright 2006 The Apache Software Foundation, http://www.apache.org/
Benchmarking 127.0.0.1 (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
/**
* Support for generating SHA-1 of a stream.
*
* Based on http://pajhome.org.uk/crypt/md5/sha1.js.
*/
function naked_sha1_head() {
var w = Array(80);
var a = 1732584193;
var b = -271733879;
require 'rubygems'
require 'couchrest'
# this is the CouchDB where all the old databases are
OLD_HOST = "http://127.0.0.1:5984"
# this is the CouchDB we want to copy to
NEW_HOST = "http://127.0.0.1:5985"
old_couch = CouchRest.new(OLD_HOST)
@jchris
jchris / benchbulk.sh
Created March 15, 2009 02:48
benchmarking CouchDB bulk inserts in bash
#!/bin/bash
# usage: time benchbulk.sh dbname
# it takes about 30 seconds to run on my old MacBook
BULKSIZE=1000
DOCSIZE=100
INSERTS=10
ROUNDS=10
DBURL="http://localhost:5984/$1"
require 'lib/yajl/http_stream'
require 'uri'
uri = URI.parse('http://jchrisa.net/toast/_changes')
Yajl::HttpStream.get(uri) do |hash|
# will take a few seconds, since the response is a single ~4MB JSON string
# if the response was a bunch of individual JSON strings, this would be fired
# for every string parsed off the stream, as they were parsed
puts hash.inspect
end
// Copyright J. Chris Anderson 2007
// Retain this notice.
// Released under the LGPL 2.1
// http://creativecommons.org/licenses/LGPL/2.1/
XSPF = {
XMLfromString: function(string) {
if (window.ActiveXObject) {
var doc = new ActiveXObject("Microsoft.XMLDOM");
doc.async = "false";