Skip to content

Instantly share code, notes, and snippets.

View bberry6's full-sized avatar

Berry bberry6

  • Norcross, GA
View GitHub Profile
@bberry6
bberry6 / readdir.js
Last active August 17, 2020 21:43
Can't get stack trace from promisified read dir
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));
// 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){
// 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);
}
@bberry6
bberry6 / test
Created February 26, 2016 16:57
test
******** 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'
@bberry6
bberry6 / chart.js
Last active August 29, 2015 14:25
Get row/col number and size given number of tiles
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)
@bberry6
bberry6 / getset.js
Last active August 29, 2015 14:25
get an object from redis, modify contents, and set
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);
@bberry6
bberry6 / setobject.js
Created July 24, 2015 17:29
set object using node redis
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);
@bberry6
bberry6 / chain.js
Created July 23, 2015 12:33
async looping
// 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);
}
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