Skip to content

Instantly share code, notes, and snippets.

🐍

Gus Caplan devsnek

🐍
Block or report user

Report or block devsnek

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@devsnek
devsnek / eyes.js
Last active May 10, 2018
another example command for the sexy command system. It puts eyes on images.
View eyes.js
"use strict";
var oxford = require('project-oxford');
var client = new oxford.Client('TOKEN');
var gm = require('gm');
var http = require('http');
var fs = require('fs');
function getFilesize(filename) {
var stats = fs.statSync(filename)
@devsnek
devsnek / funcord.js
Last active Jun 21, 2018
super cool custom discord client with nice events for your browser
View funcord.js
'use strict';
class EventEmitter {
on(e, d) {
window.addEventListener(e, eOn);
function eOn(e) { // this function is optional, but you will need to use d.details in your event listener
d.apply(this, e.detail)
}
}
View browserEvents.js
'use strict';
/**
* @class EventEmitter
* @example
* var e = new EventEmitter();
*
* e.on('hello', console.log); // 'hi how are you'
*
* e.emit('hello', 'hi', 'how are you');
View snowflake.js
const leftpad = (v, n, c = '0') => String(v).length >= n ? '' + v : (String(c).repeat(n) + v).slice(-n);
class Snowflake {
constructor ({ epoch, workerId, datacenterId } = { 1288834974657, 1, process.pid }) {
this.epoch = epoch;
this.workerId = workerId;
this.dataCenterId = datacenterId;
this.incId = 0;
}
View keybase.md

Keybase proof

I hereby claim:

  • I am guscaplan on github.
  • I am snek (https://keybase.io/snek) on keybase.
  • I have a public key whose fingerprint is 24E8 BBD2 DA10 B312 CF16 4CA2 58CC E2A2 4E2D 41DC

To claim this, I am signing this object:

@devsnek
devsnek / applyEachSeries.js
Created Dec 11, 2016
asyncawait's applyEachSeries but with each shitty dependency replaced with native code
View applyEachSeries.js
function applyEachSeries(array, ...args) {
const iterator = array[Symbol.iterator]();
const final = args.pop(); // performance?
(function cb() {
const x = iterator.next();
if (x.done) return final();
x.value(...args, cb);
})();
}
@devsnek
devsnek / callbackify.js
Last active Dec 21, 2016
with all this hype surrounding promisifying callbacks, i thought i would spice things up, and offer a function that callbackifies promises.
View callbackify.js
function callbackify (promise) {
return function execute() {
const callback = arguments[arguments.length - 1];
const args = Array.prototype.slice.call(arguments, 0, arguments.length - 1);
if (promise instanceof Promise) promise.then(r => callback(null, r)).catch(callback);
else if (typeof promise === 'function') promise(...args).then(r => callback(null, r)).catch(callback);
else throw new TypeError('`promise` must be a Promise or Function which returns a Promise!');
}
}
@devsnek
devsnek / promisify.js
Created Dec 12, 2016
also here's a promisify that blows bluebird out of the water.
View promisify.js
function promisify (fn, thisArg = null) {
return (...args) => {
return new Promise((resolve, reject) => {
const callback = (err, res) => {
if (err) return reject(err);
return resolve(res);
}
fn.apply(thisArg, [...args, callback]);
});
}
View enableSearch.txt
-----BEGIN PGP MESSAGE-----
Version: Keybase OpenPGP v2.0.61
Comment: https://keybase.io/crypto
wcFMA80pP6OGefUcAQ//eSm8iqTYlRwKjPFwIdSzi9phcT1fC2trfQ8/Pg3bEaST
O0F2N2WBR+jsbSarTFFQjS5s2xp8fEDjGSmTT8MntS3ZPai5DtN7OAYHxmGNSHx6
3DNrCCE05k2UOe3hcONY5o3hZUh6BCcmispn/a68HetohEJqd9ZYfFi5ouHHAMK7
BjuXwYV/5jHihiP/Vxe9gRFm0Hd5doVZNcTF8XbTsSDMkn9nORNUYWUirwnBVW3U
/sQmX3IjH2PskH70YAS/WVRm/U6ibB/XuQRkJ0SrSFq4N7Ld5MGDyDTr/EoAHVyg
scFqa41jawHyEBwHhGdWg0hTA7q+RvQpQwpHuC7sFkaewPVKghwLqDH2tDvNAtox
View Ratelimiter.js
class Ratelimiter {
constructor (options = { timeout: 1, limit: 5 }) {
this.tracked = {};
this.limit = options.limit;
setInterval(() => {
for (const x in this.tracked) {
if (this.tracked[x] > 0) this.tracked[x]--;
}
You can’t perform that action at this time.