This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const {readdir} = require('fs'); | |
const {promisify} = require('util'); | |
const readdirAsync = promisify(readdir); | |
async function runit(){ | |
let files = await readdirAsync('./someExistingFile'); | |
} | |
runit().catch(e => console.log(e.stack)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// winston is some logger class that does printing to screen | |
const Winston = require('winston'); | |
class MyLoggerDefault { | |
constructor(loggerConfig){ | |
this.logger = new Winston(loggerConfig); | |
} | |
log(...whatev){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// winston is some logger class that does printing to screen | |
const Winston = require('winston'); | |
class MyLogger(){ | |
init(config){ | |
this.logger = new Winston(config); | |
} | |
log(...whatev){ | |
this.logger.log(whatev); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
******** vdsr -> watch config event ************************************************ | |
check perms for user | |
join room "watchConfigEvents<params.serial>" for client socket | |
add watchConfigEvents to local var for users | |
get user authorized device list * | |
iterate over device list | |
compare last known profile with profiles in the database | |
if hashes match | |
use status 'up to date' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
n=156 | |
x=300 | |
y=55 | |
var numCols = Math.ceil(Math.sqrt(n*x/y)); | |
var numRows = Math.ceil(numCols*y/x); | |
var colSize = x/Math.sqrt(n*x/y); | |
var rowSize = y/(Math.sqrt(n*x/y)*y/x) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getSet(key, obj, transmute){ | |
return new Bluebird(function(resolve, reject){ | |
function setAtomic(key, obj, count){ | |
var counts = count; | |
var atomicClient = baseRedis.createClient(); | |
// lock the key | |
atomicClient.watch(key); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Bluebird = require('bluebird'); | |
var redis = require('redis'); | |
function setObject(key, obj){ | |
return new Bluebird(function(resolve, reject){ | |
function setAtomic(key, obj, count){ | |
var counts = count; | |
var atomicClient = redis.createClient(); | |
atomicClient.watch(key); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// make a promise for your retrieving of users (or make a generic hget function) | |
// this is similar to what the promise redis library does under the hood | |
// https://github.com/maxbrieiev/promise-redis | |
function getUser(user){ | |
// create the Promise object | |
return new Promise(function(resolve, reject){ | |
client.hget('user_'+user, 'avatar', function(error, resp){ | |
if(error){ | |
reject(error); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create table groups ( groupID serial primary key, name text); | |
create table grouplinks (parent int references groups(groupID), child int references groups(groupID), stuff int default 1, primary key (parent, child), check (parent <> child)); | |
insert into groups(name) values('Foo Company'); | |
insert into groups(name) values('Bar LP'); | |
insert into groups(name) values('Baz Industries'); | |
insert into groups(name) values('Qux GmbH'); | |
-- Setup the hierarchy to look like this... | |
-- Foo |