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 / 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 / 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 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 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
@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!');
}
}
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:

View discord_endpoints_dump.js
exports.Endpoints = {
APPLICATIONS: '/applications',
APPLICATION_ICON: (n, t) => `/applications/${n}/icons/${t}.jpg`,
APPLICATION_RPC: (n) => `/oauth2/applications/${n}/rpc`,
AUTHORIZE_IP: '/auth/authorize-ip',
AVATAR: (n, t, e = t.startsWith('a_') ? 'gif' : 'webp') => `/users/${n}/avatars/${t}.${e}`,
BILLING: '/users/@me/billing',
BILLING_HISTORY: '/users/@me/billing/payments',
BILLING_PAYMENT_SOURCE: '/users/@me/billing/payment-source',
BILLING_PREMIUM_SUBSCRIPTION: '/users/@me/billing/premium-subscription',
@devsnek
devsnek / sneksort.js
Created Feb 28, 2017
slowest sort algorithm ever made
View sneksort.js
const unsorted = [2, 3, 4, 5, 1, 7, 10, 20];
function snekSort(arr) {
const out = [];
for (let i in arr) {
const current = arr[i];
const next = arr[parseInt(i) + 1];
if (i == arr.length - 1) out.splice(1, 0, arr[0]); // out.unshift(arr[0]);
else if (current < next) out.push(next);
else out.unshift(next);
@devsnek
devsnek / typer.js
Created Mar 26, 2017
a better typer.js
View typer.js
function eek(element) {
const span = document.createElement('SPAN');
element.appendChild(span);
return span;
}
class Typer {
constructor(element, words = [], options = {}) {
this.element = eek(element);
this.words = words;
You can’t perform that action at this time.