Skip to content

Instantly share code, notes, and snippets.

View neumino's full-sized avatar

Michel neumino

View GitHub Profile
@neumino
neumino / gist:8285249
Created January 6, 2014 16:19
Ohmanous - Twitter - 2013.01.06
r.table("t1").eqJoin(
function(doc) { return doc("a")("b"); },
r.table("t2")
).map( function(left, right) {
return left.merge({
a: {
b: right
}
})
})
@neumino
neumino / gist:8210396
Last active January 1, 2016 22:29
nelish - IRC - 2013.01.01
r.db('shred').table("teams").map(function(team) {
return team.merge({
members: r.db('shred').table("users").filter(function(user) {
return team("members").contains(user("id"))
}).coerceTo("ARRAY")
})
})
// More efficient query that uses the index id
@neumino
neumino / gist:7938782
Last active December 31, 2015 05:09
emmo - IRC - 2013.12.12
conn = r.connect()
cursor = r.db('gbrl').table('race').get_all(14136, index='season_id') \
.pluck({'results':['driver', 'position']}, 'time') \
.order_by('time') \
.map( lambda race:
r.branch( # That's just a if
# Check if Andrew is in the results
race["results"]["driver"].contains("Andrew Vennaro"),
race["results"].filter(lambda doc:
@neumino
neumino / gist:7938008
Last active December 31, 2015 04:59
blazedd - IRC - 2013.12.12
r.table("users").filter( function(user) {
// map over all the keys of search
return r.expr(search).keys().map( function(key) {
// for each key, we return a boolean weather user(key) match search(key) (case insensitive)
return user(key).match( r.expr("(?i)").add(r.expr(search)(key)) ).ne(null)
}).reduce( function(left, right) { // Then for each boolean, we return left and right // so we perform a "and" operation here.
return left.and(right)
})
})
@neumino
neumino / gist:7916270
Last active December 31, 2015 01:49
ins0mnia -- IRC - 2013.12.11
r.db('todomvc').table('posts').map( function(post) {
return post.merge({
comments: r.db('todomvc').table('comments').filter( function(comment) {
comment("pid").eq( post("id") )
}).coerceTo("ARRAY")
})
})
// If you have an index on pid for the table comments, you can do
@neumino
neumino / gist:7903626
Created December 11, 2013 01:30
@bencevans - Twitter - 2013/12/10
r.db("ScrobbleGraph").table("scrobbles").groupedMapReduce(
function(doc) { return doc("date").date() },
function(doc) { return [doc] },
function(left, right) { return left.add(right)}
)
// It's better to use just an orderBy and group on the client because
// - The database won't have to keep everything in memory
// - It's faster because of the index
@neumino
neumino / gist:7828654
Created December 6, 2013 17:20
RobertZ - IRC - 2013-12-06
r.db('test').table('test').filter( function(doc) {
return doc.keys().contains( function(key) {
return key.match("^(abc)")
})
})
r.table('marvel').groupedMapReduce(
function(hero) { return hero('weightClass'), // group function
function(hero) { // map function
return {
strength: hero('strength'),
height: hero('height'),
count: 1
}
},
function(left, right) { // reduce function
@neumino
neumino / gist:7743879
Created December 2, 2013 02:11
codingkevin - IRC - 2013/12/01
r.table("authors").filter( function(author) {
return author("posts").contains( function(post) {
post("tags").contains("tagSearched")
})
}).map( function(author) {
author.merge({
posts: author("posts").filter( function(post) {
post("tags").contains("tagSearched")
})
})
@neumino
neumino / gist:7644377
Created November 25, 2013 16:46
Debian ppa
#!/bin/bash
if [ $# -eq 1 ]
NM=`uname -a && date`
NAME=`echo $NM | md5sum | cut -f1 -d" "`
then
ppa_name=`echo "$1" | cut -d":" -f2 -s`
if [ -z "$ppa_name" ]
then
echo "PPA name not found"
echo "Utility to add PPA repositories in your debian machine"