Skip to content

Instantly share code, notes, and snippets.

@tilgovi
tilgovi / gist:824248
Created February 12, 2011 23:47
[CouchDB] Finding out what was replicated
You can do something like this:
@target host
GET /target => {... "update_seq": X, ...}
POST /_replicate {"source": "<source host>/source", "target": "target"} => {...}
GET /target/_changes?since=X => { //here are your replicated changes }
This last request to /target/_changes will also include any writes to the target database that occurred between the initial GET and /_replicate as well as any writes that occurred after the replication but before the /target/_changes request. If you can only make direct requests against the target database then it is impossible to guarantee an exact answer in the presence of concurrent updates to the target.
On the other hand, if you are performing a push replication from a local database or can otherwise afford to request changes from the source after the replication finishes, you can get exactly what you want even in the presence of concurrent updates to the source and/or the target using the response body from the replication request.
@tilgovi
tilgovi / gist:841891
Created February 24, 2011 07:30
coffee-script, traits.js, and monads
coffee> [{List, Just}, fs] = [(require './lib/monad'), (require 'fs')]
[object Object]
coffee> files = (List ['src', 'lib']).bind ((dir) -> Just (fs.readdirSync dir))
[object Object]
coffee> files.log()
23 Feb 23:28:40 - [ [ 'monad.coffee~', 'list.coffee~', 'skuld.coffee~', 'skuld.coffee', 'monad.coffee' ],
[ 'skuld.js', 'monad.js' ] ]
[object Object]
@tilgovi
tilgovi / gist:841902
Created February 24, 2011 07:59
v8 Array.isArray()
> Array.isArray(Object.create(Array.prototype)) != Array.isArray(new Array())
true
@tilgovi
tilgovi / couchdb-custom-header-attachments.txt
Created May 7, 2011 00:57 — forked from max-mapper/couchdb-custom-header-attachments.txt
spec for specifying custom headers on attachments in couchdb
INLINE ATTACHMENT
{
_attachments: {
"awesome.jpeg": {
content_type: "image/jpeg",
data: "base64 data goes here",
headers: {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET, POST, OPTIONS",
@tilgovi
tilgovi / gist:969619
Created May 12, 2011 22:38
gunicorn logging reload on USR1
diff --git a/gunicorn/app/base.py b/gunicorn/app/base.py
index 6062117..a681420 100644
--- a/gunicorn/app/base.py
+++ b/gunicorn/app/base.py
@@ -38,6 +38,7 @@ class Application(object):
self.callable = None
self.logger = None
self.do_load_config()
+ self.__handlers = None
@tilgovi
tilgovi / gist:978159
Created May 18, 2011 07:48
deterministic revs for IDBCouch
diff --git a/couch.js b/couch.js
index 26fb69e..21a6e82 100644
--- a/couch.js
+++ b/couch.js
@@ -97,6 +97,198 @@ Dual licensed under the MIT and GPL licenses.
// END Math.uuid.js
+/**
+*
@tilgovi
tilgovi / gist:990375
Created May 25, 2011 05:02
Congress People Twitter Handles
[["D", "CO", "Mark Udall", "MarkUdall"], ["R", "NM", "Stevan Pearce", "RepStevePearce"], ["R", "KY", "Rand Paul", "SenRandPaul"], ["R", "OH", "Jim Renacci", "RepJimRenacci"], ["R", "VA", "Scott Rigell", "RepScottRigell"], ["R", "FL", "David Rivera", "RepRivera"], ["R", "FL", "Dennis Ross", "RepDennisRoss"], ["R", "PA", "Joseph Pitts", "RepJoePitts"], ["R", "TX", "Ronald Paul", "RepRonPaul"], ["R", "IN", "Mike Pence", "RepMikePence"], ["R", "KS", "Pat Roberts", "SenPatRoberts"], ["R", "FL", "Ileana Ros-Lehtinen", "RosLehtinen"], ["R", "CA", "Edward Royce", "RepEdRoyce"], ["R", "NY", "Thomas Reed", "TomReedCongress"], ["R", "AL", "Martha Roby", "MarthaRoby"], ["R", "IN", "Todd Rokita", "ToddRokita"], ["D", "NH", "Jeanne Shaheen", "JeanneShaheen"], ["R", "AZ", "David Schweikert", "RepDavid"], ["R", "CO", "Scott Tipton", "RepTipton"], ["D", "NY", "Gary Ackerman", "RepGaryAckerman"], ["R", "AL", "Robert Aderholt", "Robert_Aderholt"], ["R", "MO", "W. Todd Akin", "ToddAkin"], ["R", "TN", "Lamar Alexander", "SenAlexa
@tilgovi
tilgovi / gist:990451
Created May 25, 2011 06:22
Senators with Twitter Handles
[["R", "TN", "Lamar Alexander", "SenAlexander"], ["R", "NH", "Kelly Ayotte", "SenatorAyotte"], ["R", "WY", "John Barrasso", "SenJohnBarrasso"], ["D", "AK", "Mark Begich", "SenatorBegich"], ["R", "MO", "Roy Blunt", "RoyBlunt"], ["R", "AR", "John Boozman", "JohnBoozman"], ["D", "CA", "Barbara Boxer", "SenatorBoxer"], ["D", "OH", "Sherrod Brown", "SenSherrodBrown"], ["R", "NC", "Richard Burr", "SenatorBurr"], ["D", "WA", "Maria Cantwell", "US_Sen_Cantwell"], ["R", "IN", "Daniel Coats", "SenDanCoats"], ["R", "TN", "Bob Corker", "SenBobCorker"], ["R", "TX", "John Cornyn", "JohnCornyn"], ["R", "SC", "Jim DeMint", "JimDeMint"], ["R", "SC", "Lindsey Graham", "GrahamBlog"], ["R", "NV", "Dean Heller", "DeanHeller"], ["R", "NE", "Mike Johanns", "Mike_Johanns"], ["R", "WI", "Ron Johnson", "SenRonJohnson"], ["D", "SD", "Tim Johnson", "SenJohnsonSD"], ["R", "IL", "Mark Kirk", "markkirk"], ["R", "AZ", "Jon Kyl", "SenJonKyl"], ["R", "AZ", "John McCain", "SenJohnMcCain"], ["D", "MO", "Claire McCaskill", "clairecmc"], ["D", "N
chunkify(InList, BaseChunkSize) ->
%%io:format("length of list is ~p and chunk size is ~p ~n",[length(InList),BaseChunkSize]),
case byte_size(term_to_binary(InList)) of
Size when Size > BaseChunkSize ->
NumberOfChunksLikely = ((Size div BaseChunkSize) + 1),
ChunkThreshold = Size div NumberOfChunksLikely,
chunkify(InList, ChunkThreshold, [], 0, []);
_Else ->
[InList]
end.
@tilgovi
tilgovi / gist:1227319
Created September 19, 2011 19:20
Node.js call/cc function with fibers
/* This is the call-with-current-continuation found in Scheme and other
* Lisps. It captures the current call context and passes a callback to
* resume it as an argument to the function. Here, I've modified it to fit
* JavaScript and node.js paradigms by making it a method on Function
* objects and using function (err, result) style callbacks.
*/
Function.prototype.callcc = function(context /* args... */) {
var that = this,
caller = Fiber.current,
fiber = Fiber(function () {