I hereby claim:
- I am devsnek 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:
const handler = { | |
get: (target, name) => { | |
if (name === 'toString') return () => target.path.join('/').toLowerCase(); | |
const x = { path: target.path.concat(name) }; | |
return new Proxy(x, handler); | |
} | |
} | |
const bored = new Proxy({ path: [''] }, handler); |
const Stream = require('stream'); | |
const https = require('https'); | |
const http = require('http'); | |
const URL = require('url'); | |
/** | |
* Resumable stream via a Stream PassThrough | |
* @param {string|URL} url Input url | |
* @param {stream.Transform} [output=stream.PassThrough] Output stream | |
* @param {Object} [meta] Meta information to pass between stuff |
function makeWorker() { | |
return new Worker(URL.createObjectURL(new Blob([ | |
`onmessage = function(message) { | |
const data = message.data; | |
postMessage({ status: 1 }); | |
postMessage({ result: eval.call(this, data.code), status: 2 }); | |
}`], { type: 'text/javascript' }))); | |
} | |
function timedEval(code, timeout = 1000) { |
const util = require('util'); | |
const snekfetch = require('snekfetch'); | |
const paramable = ['channels', 'users', 'guilds', 'members']; | |
const reflectors = ['toString', 'valueOf', 'inspect', Symbol.toPrimitive, util.inspect.custom]; | |
function apiRequest(method, url, options) { | |
const request = snekfetch[method](url); | |
if (options.reason) request.set('X-Audit-Log-Reason', options.reason); |
I hereby claim:
To claim this, I am signing this object:
{ | |
"name": "promise_util", | |
"version": "1.3.0", | |
"main": "promise_util.js" | |
} |
This is a parser/lexer for mathematical expressions.
It all starts with the parse/1
function, which begins by
building an array (in a rather ineffecient way) from the
iterator returned by lex/2
. The lexer is the part of this
I had the most fun with.
It basically brute-forces the beginning of the string with regex until something matches up, at which point it removes that match from the string and yields the token.
const Module = require('module'); | |
require.fromString = (str, filename = '') => { | |
const m = new Module(filename, module.parent); | |
if (typeof __dirname !== 'undefined') m.paths = Module._nodeModulePaths(__dirname); | |
m._compile(str, filename); | |
return m.exports; | |
} |
function test(asd: number, b: number) -> number { | |
return asd + b; | |
} | |
function test2(x: string, y: string) -> boolean { | |
return true; | |
} | |
module.exports = { test, test2 }; |
class Backoff { | |
constructor(min = 500, max, jitter = true) { | |
this.min = min; | |
this.max = max !== null ? max : min * 10; | |
this.jitter = jitter; | |
this._current = min; | |
this._timeout = null; | |
this._fails = 0; | |
} |