Skip to content

Instantly share code, notes, and snippets.

View jkantr's full-sized avatar

Jared Kantrowitz jkantr

  • The Witzend Group
  • Metro NY Area
View GitHub Profile
const checkStatus = (response) => {
if (response.status >= 200 && response.status < 300) return response
const error = new Error(`Error ${response.status}: ${response.statusText}`)
error.response = response
throw error
}
const parseResponse = (response) => {
const authToken = response.headers.get(`Authorization`)
return response.json().then(json => ({ authToken, json }))
import requestLanguage from 'express-request-language';
import models, { Locale, User, UrlManager } from './data/models';
app.use(async (res, req, next) => {
const locales = await Locale.findAll({}).then(locales => locales.map(loc => loc.locale));
//app.set('locales', locales);
req.locales = locales;
next();
@jkantr
jkantr / myDerps.js
Last active November 30, 2017 20:05 — forked from bobfrankly/myDerps.js
const shell = require('node-powershell');
let ps = new shell({
executionPolicy: 'Bypass',
noProfile: true
});
function psPing(thisIP) {
ps.addCommand('Test-Connection -quiet -count 1 ' + thisIP)
return ps.invoke()
@jkantr
jkantr / parsefile.js
Last active November 30, 2017 22:13 — forked from enricopolanski/node
var fs = require("fs");
var path = require("path");
var cheerio = require("cheerio");
module.exports = (mypath) => {
var inputFile = fs.readFileSync(mypath, "utf8");
var $ = cheerio.load(inputFile, {xmlMode:true});
// defines the selector
@jkantr
jkantr / app.js
Last active December 8, 2017 19:35 — forked from nomoney4me/app.js
require('dotenv').config()
const Promise = require('bluebird')
const WmiClient = require('wmi-client')
// let's boiler plate this to use later in the #map
const promisifiedClient = opts => Promise.promisifyAll(new WmiClient(opts))
/* wmi queries functions */
async function getWMI(wmi) {
@jkantr
jkantr / .js
Last active January 5, 2018 17:46 — forked from hmpmarketing/memcached.js
const Promise = require('bluebird');
const memcache = require('./memcached.js');
const lifetime = 100 // i don't actually know what this is.. fill in the correct thing :p
Promise.try(() => {
return memcache.add('foo', 'bar', lifetime);
}).then(() => {
return memcache.get('foo');
}).then((foo) => {
@jkantr
jkantr / remember.js
Last active January 5, 2018 19:10 — forked from hmpmarketing/remember.js
Cache.remember = function (key, lifetime, callback) {
return Promise.try(() => {
return memcached.getAsync(key);
}).then((value) => {
if (value !== undefined) {
return value;
} else {
return Promise.try(() => {
return callback()
}).then((value) => {
cache.remember('key', 600, function() {
return Promise.resolve('value2');
}).then((val) => {
console.log('set: ', val);
})
Cache.remember = function (key, lifetime, callback) {
return Promise.try(() => {
return memcached.getAsync(key);
}).then((value) => {
if (value !== undefined) {
console.log('exists');
return value;
} else {
return Promise.try(() => {
if (typeof callback === "function") {
// do this
cache.remember('key1', 600, function() {
return mysql.MobileAction.findOne({ where: {action_id: req.query.D} })
}).then((val) => {
console.log('set: ', val);
})