Skip to content

Instantly share code, notes, and snippets.

View neumino's full-sized avatar

Michel neumino

View GitHub Profile
@neumino
neumino / gist:8789766
Created February 3, 2014 18:44
IRC - richcorbs - 2014/02/03
r.table('stuff').filter({'this_field' => 'this value'}).grouped_map_reduce(
lambda {|doc| doc[:this_other_field]} },
lambda {|doc| [doc] },
lambda {|left, right| left+right}
).run(conn)
@neumino
neumino / gist:8920871
Created February 10, 2014 17:55
10/02/2014 - @miguelping - Twitter
r.table("foo").groupedMapReduce(
function(doc) { return doc("categorie") },
function(doc) { return doc.pluck("a", "b") },
function(left, right) {
return {
a: left("a").add(right("a")),
b: left("b").add(right("b"))
}
}
).run(...)
@neumino
neumino / gist:455aa5b1cb8d8a732f5c
Created June 18, 2014 21:33
Pivot example with r.object
r.db('test').table('marks')
.group('name')
.concatMap(function(row){return [row('course'), row('mark')];})
.ungroup()
.map(function(res){
return r.expr({name: res('group')})
.merge(r.object(r.args(res('reduction'))));
})
// Index:
r.table("heroes").indexCreate("idEquipment", function(doc) {
return doc("equipment").map(function(equipment) {
return [doc("id"), equipment]
})
}, {multi: true}).run(conn, callback)
// Query
r.table("heroes").getAll([1, "boots"], {index: "idEquipment"}).run(conn, callback)
Possibly unhandled TypeError: Cannot call method 'call' of undefined
at tryCatch1 (/home/michel/projects/rethinkdb-all/thinky/node_modules/bluebird/js/main/util.js:43:21)
at CatchFilter$_doFilter [as doFilter] (/home/michel/projects/rethinkdb-all/thinky/node_modules/bluebird/js/main/catch_filter.js:80:27)
at tryCatch1 (/home/michel/projects/rethinkdb-all/thinky/node_modules/bluebird/js/main/util.js:43:21)
at Promise$_callHandler [as _callHandler] (/home/michel/projects/rethinkdb-all/thinky/node_modules/bluebird/js/main/promise.js:627:13)
at Promise$_settlePromiseFromHandler [as _settlePromiseFromHandler] (/home/michel/projects/rethinkdb-all/thinky/node_modules/bluebird/js/main/promise.js:641:18)
at Promise$_settlePromiseAt [as _settlePromiseAt] (/home/michel/projects/rethinkdb-all/thinky/node_modules/bluebird/js/main/promise.js:800:14)
at Promise$_settlePromises [as _settlePromises] (/home/michel/projects/rethinkdb-all/thinky/node_modules/bluebird/js/main/promise.js:934:14)
at
r.expr([{ v: 1 }, { v: 2 }, { v: 3 }, { v: 4 }]).map(function(doc) {
return [doc('v')]
}).reduce(function(left, right) {
return left.union(right).orderBy(function(element) { return element.mul(-1)}).limit(2)
}).nth(1)
r.table('posts').indexStatus('oldIndex').​nth(0).do(function(oldIndex) {
return r.table('posts').indexCreate('newIndex', oldIndex("function"), {multi: oldIndex("multi")}).do(function() {
return r.table('posts').indexWait('newIndex').do(function() {
return r.table('posts').indexRename('newIndex', 'oldIndex', {overwrite: true})
})
})
})
r.table('story').indexCreate('storyAndId', [r.row("storyAuthor"), r.row("id")] )
var authorId = '1';
r.table('comment').orderBy({index: r.desc('created')})
.eqJoin(function(comment) {
return [authorId, comment("parentId")]
}, r.table('story'), {index: "storyAndId"})
.limit(20)
r.db('test').table('foo').update(function(doc) {
return doc.merge({foo: {channel: doc("id").add(doc("name")) }})
})
from pytz import timezone
import pickle
timezone = timezone('US/Pacific')
print timezone
f = open('test.txt', 'w')
pickle.dump(timezone, f)
f.close()