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 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 })) |
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
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(); |
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 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() |
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 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 |
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
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) { |
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 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) => { |
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
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) => { |
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
cache.remember('key', 600, function() { | |
return Promise.resolve('value2'); | |
}).then((val) => { | |
console.log('set: ', val); | |
}) |
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
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") { |
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
// do this | |
cache.remember('key1', 600, function() { | |
return mysql.MobileAction.findOne({ where: {action_id: req.query.D} }) | |
}).then((val) => { | |
console.log('set: ', val); | |
}) |
OlderNewer