Skip to content

Instantly share code, notes, and snippets.

View doron2402's full-sized avatar

Doron Segal doron2402

View GitHub Profile
@doron2402
doron2402 / promise.all.js
Created January 11, 2017 05:43
Promise.all run promise in parallel
// taken from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all
var p1 = Promise.resolve(3);
var p2 = 1337;
var p3 = new Promise((resolve, reject) => {
setTimeout(resolve, 100, "foo");
});
Promise.all([p1, p2, p3]).then(values => {
console.log(values); // [3, 1337, "foo"]
});
@doron2402
doron2402 / promise_water_fall_part_a.js
Created January 11, 2017 05:45
Running promises one after the other
p1.then((result) => {
// do something return something
}).then((result1) => {
// do something return something
}).then((result2) => {
// do something return something
}).catch((error) => {
// if there's an error will catch it here
});
@doron2402
doron2402 / waterfall-promises.js
Created January 11, 2017 05:47
Running promises waterfall using promise-waterfall-native ('npm i promise-waterfall-native')
'use strict';
const Waterfall = require('../index');
const getSomeDataFromDB = () => {
return new Promise((resolve) => {
return setTimeout(() => {
resolve([
{ id: 1 },
{ id: 2 }
]);
@doron2402
doron2402 / callback_hell.js
Created January 11, 2017 05:48
Callback hell
function isUserAuthenticate(session, callback) {
openDatabase(function(db) {
getCollection(db, 'sessions', function(col) {
find(col, {'session': session},function(result) {
result.filter(function(error, user) {
callback(error, user);
})
})
})
})
@doron2402
doron2402 / simple_callback.js
Created January 11, 2017 05:48
Simple callback without nesting (no callback hell yet.)
function passMeCallback(options, callback) {
//do something
const err = null;
const result = options;//some data goes here
return callback(err, result);
}
passMeCallback({ age: 30 }, function(err, result) {
console.log(result); //this will be the options we just passed to the function
});
@doron2402
doron2402 / docker-compose.yml
Created February 11, 2017 00:15
Druid docker-compose
version: "2"
services:
postgres:
image: postgres:9.6.1
container_name: postgres
environment:
- POSTGRES_PASSWORD=TCrGaanoC2s7gT
ports:
- "15432:5432"
@doron2402
doron2402 / Dockerfile
Created February 11, 2017 00:15
Dockerfile Druid
FROM progrium/busybox
MAINTAINER Doron Segal <doron@saildrone.com>
# Java config
ENV DRUID_VERSION 0.9.1.1
ENV JAVA_HOME /opt/jre1.8.0_40
ENV PATH $PATH:/opt/jre1.8.0_40/bin
# Druid env variable
ENV DRUID_XMX '-'
@doron2402
doron2402 / db.sql
Last active March 14, 2017 18:28
Postgres Parent<> Child (Table partitioning in PostgreSQL)
#
# Table partitioning with postgreSQL
# the master_table should be empty, data will only be inside the childs table
#
# CREATE MASTER TABLE
CREATE TABLE master_table (
id BIGINT,
username VARCHAR (50) UNIQUE NOT NULL,
description TEXT);
@doron2402
doron2402 / memwatch_detect.js
Created May 4, 2017 19:12
Using memwatch-next in order to detect memory leak node 6.10.x
'use strict';
const Memwatch = require('memwatch-next');
const Util = require('util');
if (Config.env === 'production') {
/**
* Check for memory leaks
*/
let hd = null;
Memwatch.on('leak', (info) => {
@doron2402
doron2402 / mem_leak.js
Created July 5, 2017 17:25
Node.js Memory leark
'use strict';
const Memwatch = require('memwatch-next');
const Util = require('util');
if (Config.env === 'production') {
/**
* Check for memory leaks
*/
let hd = null;
Memwatch.on('leak', (info) => {