Skip to content

Instantly share code, notes, and snippets.

@ScottKaye
ScottKaye / HandyDandyPrototypes.js
Last active July 10, 2023 19:16
A collection of potentially useful prototypes to make some things easier. Each of these should be crushable with http://www.iteral.com/jscrush/ . "Don't modify objects you don't own" is completely thrown out the window here in favour of coolness.
//Get a range of numbers between two numbers
//Usage: [1, 10].range returns [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Object.defineProperty(Array.prototype, "range", {
get: function () {
var range = [this[0]], i;
for (var i = this[0], len = this[1]; i < len; range.push(++i));
return range;
}
});
// Golfed TypeScript:
@JamieMason
JamieMason / asyncMap.js
Last active November 22, 2018 19:16
Map over an Array using an asynchronous handler, maintaining a pool of concurrent handlers to be pending at all times until the Array is fully processed (as opposed to waiting until each async handler has finished before calling the next).
/**
* Map over an Array using an asynchronous handler, maintaining a pool of concurrent handlers to be pending at all times until the Array is fully processed (as opposed to waiting until each async handler has finished before calling the next).
*
* @param {Array} list
* @param {Function} handler Called on each iteration (done:Function, element:Mixed, index:Number, list:Array)
* @param {Number} [options.maxConcurrent=5] The maximum number of handlers which can be running concurrently
* @param {Function} [options.done] Called once every handler has responded (responses:Array)
* @return {Array} The Array which is being populated with the values passed by handler to done()
*/
exports.map = function (list, handler, options) {
@bradmontgomery
bradmontgomery / dummy-web-server.py
Last active March 31, 2025 12:04
a minimal http server in python. Responds to GET, HEAD, POST requests, but will fail on anything else.
#!/usr/bin/env python
"""
Very simple HTTP server in python (Updated for Python 3.7)
Usage:
./dummy-web-server.py -h
./dummy-web-server.py -l localhost -p 8000
Send a GET request: