Skip to content

Instantly share code, notes, and snippets.

View snej's full-sized avatar

Jens Alfke snej

View GitHub Profile
@snej
snej / gist:6216072
Created August 12, 2013 22:48
Output of 'changes' view of sync gateway, in form "key[tab]value[tab]docid". Note the discontinuity, where keys 1181-2174 appear at the start (before 401) and then later there is a gap from 994-2175.
/db: “channels” View
Key Value ID
["*",1181] ["78k9je3j3k6","1-7b6054260a204912852c3021cab9168c"] 78k9je3j3k6
["*",1182] ["kcd0neg7kac","1-ebd3a623c406b28b80d1ebf651ffacec"] kcd0neg7kac
["*",1183] ["eb33dbinaii","1-4b4a5598313a2f79321f60364b43a990"] eb33dbinaii
["*",1184] ["f41cig0kk86","1-d44e48481e63331720822afa9fbf3e1f"] f41cig0kk86
["*",1185] ["6k5anc2kaii","1-1cec51d3336824eaefc45b3b5fc492f8"] 6k5anc2kaii
["*",1186] ["j026jml39","1-92f7448c5727533df4e070d06f67386d"] j026jml39
["*",1187] ["bnn1ae3b6","1-6dd3cd60eefd7a44184db3368bdcaa7a"] bnn1ae3b6
@snej
snej / new_cas.go
Created July 12, 2013 20:43
New implementation of memcached.CAS that doesn't reserve the client connection for the duration of the transaction.
type CASState struct {
initialized bool // false on the first call to CASNext, then true
Value []byte // Current value of key; update in place to new value
Cas uint64 // Current CAS value of key
Exists bool // Does a value exist for the key? (If not, Value will be nil)
Err error // Error, if any, after CASNext returns false
resp *gomemcached.MCResponse
}
// Non-callback, loop-based version of CAS method. Usage is like this:
@snej
snej / ModelTests2.m
Created July 9, 2013 20:37
Attempting to reproduce issue couchbase/couchbase-lite-ios#63 ... no success so far.
// Append this to ModelTests.m
TestCase(API_ModelAttachments) {
// Attempting to reproduce https://github.com/couchbase/couchbase-lite-ios/issues/63
CBLDatabase* db = createEmptyDB();
NSError* error;
NSData* attData = [@"Ceci n'est pas une pipe." dataUsingEncoding: NSUTF8StringEncoding];
CBLDocument* doc;
{
@snej
snej / patch.diff
Created March 29, 2013 21:34
Patch to log credential lookup in TouchDB.
diff --git a/MYURLUtils.m b/MYURLUtils.m
index 2e3e333..db9b514 100644
--- a/MYURLUtils.m
+++ b/MYURLUtils.m
@@ -63,10 +63,14 @@
NSURLProtectionSpace* space = [self my_protectionSpaceWithRealm: realm
authenticationMethod: authenticationMethod];
NSURLCredentialStorage* storage = [NSURLCredentialStorage sharedCredentialStorage];
+ NSURLCredential* cred;
if (username)
@snej
snej / changeTracker.diff
Created March 29, 2013 17:11
Speculative fix for TDSocketChangeTracker.m that might resolve couchbaselabs/TouchDB-iOS#241
diff --git a/Source/ChangeTracker/TDSocketChangeTracker.m b/Source/ChangeTracker/TDSocketChangeTracker.m
index e151937..151355a 100644
--- a/Source/ChangeTracker/TDSocketChangeTracker.m
+++ b/Source/ChangeTracker/TDSocketChangeTracker.m
@@ -27,7 +27,7 @@
#define kMaxRetries 6
#define kInitialRetryDelay 0.2
-#define kReadLength 8192u
+#define kReadLength 4096u
@snej
snej / gist:3989063
Created October 31, 2012 18:51
CouchDB barfage
{progress,preloaded}
{progress,kernel_load_completed}
{progress,modules_loaded}
{start,heart}
{start,error_logger}
{start,application_controller}
{progress,init_kernel_started}
{apply,{application,load,[{application,stdlib,[{description,"ERTS CXC 138 10"},{vsn,"1.18.1"},{id,[]},{modules,[array,base64,beam_lib,binary,c,calendar,dets,dets_server,dets_sup,dets_utils,dets_v8,dets_v9,dict,digraph,digraph_utils,edlin,edlin_expand,epp,eval_bits,erl_bits,erl_compile,erl_eval,erl_expand_records,erl_internal,erl_lint,erl_parse,erl_posix_msg,erl_pp,erl_scan,erl_tar,error_logger_file_h,error_logger_tty_h,escript,ets,file_sorter,filelib,filename,gb_trees,gb_sets,gen,gen_event,gen_fsm,gen_server,io,io_lib,io_lib_format,io_lib_fread,io_lib_pretty,lib,lists,log_mf_h,math,ms_transform,orddict,ordsets,otp_internal,pg,pool,proc_lib,proplists,qlc,qlc_pt,queue,random,re,sets,shell,shell_default,slave,sofs,string,supervisor,supervisor_bridge,sys,timer,unicode,win32reg,zip]},{registered,[timer_server,rsh_starter,take_over_monitor,
@snej
snej / signed_json.erl
Created November 17, 2011 18:54
JSON signature verification, in Erlang
%%%' HEADER
%% @author Jens Alfke <jens@couchbase.com>
%% @copyright Apache 2.0 license
%% @doc Verification of digital signatures in parsed JSON objects. (Assumes JSON is parsed the way it is by CouchDB, not as by the original mochijson library.)
%% @end
-module(signed_json).
-export([is_signed/1, verify/1]).
-export([test/0]). % TESTING
# This is a test case for a DataMapper bug handling a relation from a table to itself.
# ruby 1.8.7 (2009-06-08 patchlevel 173) [universal-darwin10.0]
# sqlite 3.6.22
# Mac OS X 10.6.3
require 'rubygems'
require 'dm-core' #0.9.12
DataMapper::Logger.new($stdout, :debug)
DataMapper.setup(:default, 'sqlite3::memory:')
@snej
snej / BloomFilter.scala
Created February 2, 2009 05:04
Implements a Bloom filter in the Scala language.
import scala.collection.BitSet
import scala.collection.mutable
import scala.runtime.RichString
/** Abstract trait for a Bloom filter, a data structure similar to a set, but which requires
far less memory (only a few bits per item). The trade-off is that you get false positives:
the filter may think it contains items that were never added to it. But for some
applications (especially distributed ones) the memory savings are worth it.
See: <http://en.wikipedia.org/wiki/Bloom_filter> */
@cloneable