Skip to content

Instantly share code, notes, and snippets.

View tomblench's full-sized avatar

Tom Blench tomblench

View GitHub Profile
@tomblench
tomblench / gist:8436408
Created January 15, 2014 13:42
Put this in .git/hooks/commit-msg for each git project
#!/usr/bin/env perl -w
my $file = $ARGV[0];
my $bad = 0;
open(my $FH, "<", $file);
while(<$FH>) {
if ((length) > 50) {
print("line $. too long\n");
import re
import string
pronMap = {"i": "you",
"you": "you",
"they": "they",
"we": "you",
"he": "he",
"she": "she",
"it": "it"};
import re
import string
from errbot import BotPlugin, botcmd
class ofhave(BotPlugin):
def callback_message(self, conn, mess):
reply = self.couldShould(mess.getBody())
if reply:
@tomblench
tomblench / gist:c02bd6adcf37f1c9cfc7
Created September 19, 2014 14:56
custom indexer
-(NSArray*)valuesForRevision:(CDTDocumentRevision*)revision
indexName:(NSString*)indexName
{
NSMutableArray *returnArray = [NSMutableArray array];
NSArray *arr = [[revision body] valueForKey:@"subjects"];
for (NSDictionary *dict in arr) {
[returnArray addObject:[dict valueForKey:@"mark"]];
}
public void test1() throws Exception {
// NB replicator is a BasicReplicator object we created earlier
MutableDocumentRevision doc = new MutableDocumentRevision();
doc.body = DocumentBodyFactory.create("{\"hello\": \"world\"}".getBytes());
doc.attachments.put("att1", new UnsavedFileAttachment(new File("/tmp/1"), "text/plain"));
BasicDocumentRevision doc1 = datastore.createDocumentFromRevision(doc);
replicator.start();
Assert.assertEquals(Replicator.State.STARTED, replicator.getState());
while(replicator.getState() != Replicator.State.COMPLETE) {
Thread.sleep(1000);
@Test
public void forceInsert_noCommonHistory() throws Exception {
// rev6 represents the current state after we lost all of the history from 1 -> 5
BasicDocumentRevision rev6 = createDbObject("6-x", bodyOne);
// rev7 represents an incoming change which has deleted set
BasicDocumentRevision rev7 = createDbObject("7-x", bodyTwo);
//BasicDocumentRevision rev7 = createDbObjectDeleted("7-x");
// rev2 represents an incoming change which will not have an ancestor because it was lost
BasicDocumentRevision rev2 = createDbObject("2-x", bodyTwo);
private BasicDocumentRevision createDbObjectDeleted(String rev) {
DocumentRevisionBuilder builder = new DocumentRevisionBuilder();
builder.setDocId(OBJECT_ID);
builder.setRevId(rev);
builder.setDeleted(true);
builder.setBody(new BasicDocumentBody(JSONUtils.EMPTY_JSON));
return builder.build();
}
package cloudant.com.testsensorupload;
import android.os.AsyncTask;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Base64;
import android.widget.TextView;
import java.io.IOException;
import java.io.InputStream;
@Test
public void blah() throws Exception {
Map<String, String> map = new HashMap<String, String>();
map.put("hello", "world");
// create a doc
DocumentRevision revision = new DocumentRevision("id1");
revision.setBody(DocumentBodyFactory.create(map));
datastore.createDocumentFromRevision(revision);
// fetch up to 100 changes since the beginning
Changes changes = datastore.changes(0, 100);
-(void)testCompactedConflictedTree
{
NSError * error;
CDTDocumentRevision *mutableRev;
mutableRev = [CDTDocumentRevision revisionWithDocId:@"aTestDocId"];
mutableRev.body = [@{ @"hello" : @"world" } mutableCopy];
CDTDocumentRevision * rev = [self.datastore createDocumentFromRevision:mutableRev error:&error];
XCTAssertNotNil(rev, @"Document was not created");