Skip to content

Instantly share code, notes, and snippets.

View thelinuxlich's full-sized avatar
🐉
Here be dragons

Alisson Cavalcante Agiani thelinuxlich

🐉
Here be dragons
View GitHub Profile
ioredis:redis write command[0] -> multi() +2s
ioredis:redis write command[0] -> lrange(processing_batch:pageviews,0,99) +0ms
ioredis:redis write command[0] -> ltrim(processing_batch:pageviews,100,-1) +0ms
ioredis:redis write command[0] -> exec() +0ms
ioredis:redis write command[0] -> multi() +0ms
ioredis:redis write command[0] -> lrange(processing_batch:devices,0,99) +0ms
ioredis:redis write command[0] -> ltrim(processing_batch:devices,100,-1) +0ms
ioredis:redis write command[0] -> exec() +0ms
ioredis:redis write command[0] -> multi() +0ms
ioredis:redis write command[0] -> lrange(processing_batch:events,0,99) +0ms
ReqlCompileError: Cannot nest writes or meta ops in stream operations. Use FOR_EACH instead in:
r.table("sessions").get("1ba7f35d-8f61-4835-af4a-9d0a80e41c704browser310320151300")
.replace(function(var_2) {
return r.branch(var_2.eq(null), r.table("sessions").insert({
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
visitor_id: "1ba7f35d-8f61-4835-af4a-9d0a80e41c70",
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
client_id: 4,
^^^^^^^^^^^^^
origin: "browser",
@thelinuxlich
thelinuxlich / query.js
Created March 30, 2015 20:28
query with between
// request arriving at 30/03/2015 15:29:59
// ids will have a 30-minute window but they can be extended by activity
// first, try to find an active session in 30 minutes
r.table("sessions").between(r.now().sub(1800),r.now(),{index: "updated_at"}).orderBy(r.desc({index: "updated_at"})).limit(1).replace(function(row) {
return r.branch(row.eq(null),
r.table("sessions").insert({ // doesn't exist so insert a row with the current 30-minute window
id: "300320151500",
created_at: r.now(),
updated_at: r.now()
}),
@thelinuxlich
thelinuxlich / query.js
Last active August 29, 2015 14:18
query
// request arriving at 30/03/2015 15:29:59
// ids will have a 30-minute window but they can be extended by activity
// this id is coming from redis or created and added to redis if it doesn't exist
r.table("sessions").get("300320151530").replace(function(row) {
return r.branch(row.eq(null),
{ // doesn't exist so insert a row with the current 30-minute window
id: "300320151500",
created_at: r.now(),
updated_at: r.now()
},
@thelinuxlich
thelinuxlich / reql.js
Created February 18, 2015 17:59
Geolocation and weather prevision all inside ReQL
var diso = moment().tz("America/Sao_Paulo").format(),
d = r.ISO8601(diso);
r.table("pending_geo_sessions").delete({
returnChanges: true,
durability: "soft"
}).do(function(data) {
return data("changes").default([]).map(function(session) {
return r.table("cached_geolocations").get(session("ip")).do(function(geo) {
return r.branch(
@thelinuxlich
thelinuxlich / shipitfile.js
Last active September 13, 2017 07:36
Shipitfile example
var project_name = "YOUR_PROJECT_NAME",
project_url = 'YOUR_GIT_URL',
project_destination_server = 'USER@SERVER',
project_destination_dir = '/PROJECT_DIRECTORY',
webhookUri = "SLACK_TOKEN_URI",
Slack = require('slack-node'),
slack = new Slack(),
notify = function(text) {
slack.webhook({
channel: "#notifications",
var cluster = require('cluster');
if(cluster.isMaster) {
cluster.fork()
.on('online', function() {
this.disconnect();
});
} else {
process.on('internalMessage', function(msg) {
console.log('internalMsg', msg);
@thelinuxlich
thelinuxlich / result.json
Created December 4, 2014 03:49
query result
[{"group":"2014-12-01T22:00:00-02:00","reduction":88},{"group":"2014-12-02T22:00:00-02:00","reduction":56},{"group":"2014-12-03T22:00:00-02:00","reduction":5}]
r.db("aidax").table("purchases").getAll("0f338aa9-0d16-4e00-8301-f5ddabf313de", {
index: "client_id"
}).eqJoin("session_id", r.db("aidax").table("sessions")).map(function(var_1) {
return var_1("left").merge({
visitor_id: var_1("right")("visitor_id"),
session_properties: var_1("right")("properties"),
weather: var_1("right")("weather").default({
}),
geo: var_1("right")("geo").default({
ReqlRuntimeError: Cannot perform get_field on a non-object non-sequence `"bad_person"` in:
r.table("events").getAll(r.args([["bad_person", "buy"], ["real_person", "buy"], ["person", "buy"]]), {
index: "person_action"
}).group("person", "thing").max("created_at").ungroup().limit(10).group(r.row("group")(0))
^^^^^^^^^^^^^^^^^
.ungroup().map(function(var_43) {
return r.object(var_43("group"), var_43("reduction").map(function(var_44) {
return {
thing: var_44("group").nth(1),
last_actioned_at: var_44("reduction")("created_at").toEpochTime()