Skip to content

Instantly share code, notes, and snippets.

@coffeemug
coffeemug / concatMap.md
Created July 2, 2013 00:33
An example of poor API documentation

RethinkDB: The concatMap command in Javascript

Declaration

sequence.concatMap(mappingFunction) -> stream
array.concatMap(mappingFunction) -> array

Description

@coffeemug
coffeemug / gist:6417983
Last active December 22, 2015 04:38
Importing `git log` data into RethinkDB
git log --pretty=format:"%H|%ae|%at|%s" | \
python -c " \
import rethinkdb as r; \
import sys; \
r.connect().repl(); \
r.table_create('commits').run(); \
r.table('commits').insert([dict(map(lambda x, y: [x, y], \
['id', 'email', 'date', 'subject'], \
line.split('|', 3))) \
for line in sys.stdin]) \
@coffeemug
coffeemug / gist:6444786
Created September 5, 2013 01:04
RethinkDB vs. Mongo insert test
"""Compares rethinkdb with mongo. Copied from http://pastebin.com/3PqdFTjc. Example output:
mongodb: 0.110867023468
rethink: 2.25043606758
"""
import copy
import pymongo
import rethinkdb as r
import time
David, sorry you ran into these issues. The crash is a known bug, and will be fixed in the 1.12 release (along with the new cache implementation). See https://github.com/rethinkdb/rethinkdb/issues/1389 for more details.
As to the performance you're getting, could you give some additional info so we could track this down?
- Which OS/version are you running?
- Which RethinkDB version are you running? (you can tell by running `rethinkdb --version`)
- Which client driver are you using (and which version)?
- What query do you use to get out 100 documents and how are you measuing latency?
Would really appreciate your feedback so we could fix these issues.
r.table('authors').filter(lambda author:
r.table('users')['last_name'].contains(author['last_name'])).
run(conn)
### Keybase proof
I hereby claim:
* I am coffeemug on github.
* I am coffeemug (https://keybase.io/coffeemug) on keybase.
* I have a public key whose fingerprint is 61D8 8768 ADF2 C641 6ED5 2E6A 045D F3C7 4618 7048
To claim this, I am signing this object:
@coffeemug
coffeemug / age-of-em-review.markdown
Last active March 7, 2017 11:58
Age of Em Review

Every piece of speculation about the future I've ever encountered broadly pattern-matches into one of four genres: forecasting, prophecy, literary works of fiction, and rants. Age of Em doesn't autocomplete into any of these, and I think both my irritation and fascination with it come from the same source -- the audacity of creating an entirely new genre of futurism.

Here are rough properties of the existing four genres:

  • Forescasting - narrow subject matter, falsifiable details that
@coffeemug
coffeemug / rethinkdb-atomic-get-set.md
Last active February 2, 2018 15:17
Atomic get and set in RethinkDB 1.7

Suppose you have a number of nodes on a network that spin up cron jobs to perform various tasks. However, you need the nodes to cooperate to ensure that multiple nodes don't spin up the same task. You can easily implement this functionality on top of RethinkDB as follows:

// A single node atomically pushes jobs onto an array in the database
r.table('admin').get('jobs').update({ job_list: r.row('job_list').append(JOB_DESCRIPTION)) })
fn print<T>(x: T) {
// backticks inject Golang code directly. This isn't
// type-checked or processed by Axler. Any Axler variable
// must be marshalled via `<%=` and `%>`
`fmt.Printf("%v\n", <%= x %> )`
}
enum maybe<T> = none | some(T);
// `T?` is syntax sugar for `maybe<T>`. Just a convenient way
// Got implicit conversion working the compiler!
// You implement it like this:
enum maybe<T> = none | some(T);
// `T?` is just sugar for `maybe<T>`
impl<T> T? {
// the colon prefix means function is static
fn :from(x: T) -> T? {