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
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") {
cache.remember('key', 600, function() {
return Promise.resolve('value2');
}).then((val) => {
console.log('set: ', val);
})
@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) => {
@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 / 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 / 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 / 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 / .js
Last active January 2, 2021 02:58
const Promise = require('bluebird');
const fetch = require('node-fetch');
const cheerio = require('cheerio');
const getAllUrls = () => {
return fetch('http://regioni.usyouthsoccer.org')
.then(res => res.text())
.then((html) => {
const $ = cheerio.load(html);
return $('#associationscarousel').find('> li > a').toArray().map(link => $(link).attr('href'))
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 / .js
Created June 8, 2017 16:36
Fold large array into an array of arrays of N length
const foldArr = (arr, groupSize) => arr.reduce((a, b, i, g) => !(i % groupSize) ? a.concat([g.slice(i, i + groupSize)]) : a, []);