Skip to content

Instantly share code, notes, and snippets.

View analytik's full-sized avatar
😐
b u r n o u t

Milan B analytik

😐
b u r n o u t
View GitHub Profile
@analytik
analytik / run.js
Created July 23, 2017 10:06
Nodemon's lib/monitor/run.js 1.11.0 with my logging changes
var debug = require('debug')('nodemon');
var utils = require('../utils');
var bus = utils.bus;
var childProcess = require('child_process');
var spawn = childProcess.spawn;
var exec = childProcess.exec;
var watch = require('./watch').watch;
var config = require('../config');
var child = null; // the actual child process we spawn
var killedAfterChange = false;
@analytik
analytik / package.json
Created June 3, 2017 09:56
package.json that does not install correctly under npm 5.0.0-5.0.2
{
"name": "broken",
"private": true,
"version": "0.0.1",
"scripts": {
"test-football-formulas": "jasmine www/formulas/test/football_formulas_tests.js",
"dev-scripts": "npm run hgrc && npm run create-env",
"dev": "webpack-dev-server --config=webpack.config.js --progress --hot",
"preinstall": "npm prune",
"predevsilent": "npm run dev-scripts",
// By slack user ronz
query
.changes({includeInitial: true, includeStates: true, includeTypes: true})
.pluck('type', 'state')
.filter(row => row('type').ne('change'))
.fold(
0,
(acc, next) => r.branch(
r.or(next('type').eq('add'), next('type').eq('initial')),
acc.add(1),
@analytik
analytik / rethinkdb total read and written bytes per table
Created January 1, 2017 14:14
Sum up reads and writes across the cluster, in bytes read/written to disk - does not include cache hits
r.db("rethinkdb").table("stats")
.hasFields('db', 'table')
.group('db', 'table')
.map(doc => ({
reads: doc('storage_engine')('disk')('read_bytes_total').default(0),
writes: doc('storage_engine')('disk')('written_bytes_total').default(0)
}))
.ungroup()
.map(doc => ({
db: doc('group').nth(0),
r.db("rethinkdb").table("table_config")
.hasFields('db', 'name')
.concatMap(doc => [{
db: doc('db'),
table: doc('name'),
shards: doc('shards').count(),
replicas: doc('shards').nth(0)('replicas').count(),
}])
// this part is dumb - assuming you have 4 main servers,
// and that ONLY tables with 5 total replicas have 5 replicas
r.db("rethinkdb").table("stats")
.hasFields('db', 'table')
.group('db', 'table')
.map(doc => doc('storage_engine')('disk')('space_usage')('data_bytes').default(0))
.sum()
.ungroup()
.map(doc => ({db: doc('group').nth(0), table: doc('group').nth(1), size: doc('reduction').div(1024).div(1024)}))
.orderBy(r.desc('size'));
r.db('rethinkdb').table('table_status')
.filter(r.row('status')('ready_for_writes').not())
.forEach((tbl)=>{
return r.db(tbl('db')).table(tbl('name')).reconfigure({emergency_repair: 'unsafe_rollback'});
})
@analytik
analytik / Testing eachAsync for memory leaks
Last active June 29, 2016 12:56
Testing memory usage for a large number of events with changefeeds and eachAsync
var Promise = require('bluebird');
var util = require('util');
var heapdump = require('heapdump');
function log(message) {
console.log(new Date().toISOString() + ' - ' + message);
}
function gc() {
log('-- Forced GC');
@analytik
analytik / Combine similar transactions
Created April 5, 2016 06:07
An example on how to use fold introduced in RethinkDB 2.3 to combine similar consequential documents
return r.db('db1').table('table1')
.getAll('asdfgh', {index: 'user_id'})
.orderBy(r.desc('created'))
.fold([], function (acc, doc) {
return r.branch(
acc.isEmpty(),
acc.add([doc]),
acc.nth(-1)('transaction_type').eq(doc('transaction_type')),
acc.slice(0, -1).append(acc.nth(-1).merge({
amount: acc.nth(-1)('amount').add(doc('amount'))
@analytik
analytik / happylog.js
Last active January 28, 2024 17:09
Generate a list of headings and subheadings for every day in DokuWiki format for the purpose of keeping a track of nice things that happened to you
/**
* Created by milan on 2016-04-02.
* HappyLog skeleton generator (DokuWiki format)
*/
"use strict";
let strftime = require('strftime');
let day = new Date();
day.setDate(1);
day.setMonth(day.getMonth());
let month = day.getMonth();