Skip to content

Instantly share code, notes, and snippets.

@devsnek
devsnek / eyes.js
Last active July 20, 2020 14:25
another example command for the sexy command system. It puts eyes on images.
"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 December 27, 2020 08:31
super cool custom discord client with nice events for your browser
'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)
}
}
'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');
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;
}

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 December 11, 2016 04:17
asyncawait's applyEachSeries but with each shitty dependency replaced with native code
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 December 21, 2016 02:17
with all this hype surrounding promisifying callbacks, i thought i would spice things up, and offer a function that callbackifies promises.
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 December 12, 2016 23:41
also here's a promisify that blows bluebird out of the water.
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]);
});
}
-----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
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]--;
}