Skip to content

Instantly share code, notes, and snippets.

View philmander's full-sized avatar

Phil Mander philmander

View GitHub Profile
var Q = require("q");
var HTTP = require("q-http");
function httpReadRetry(url, timeout, times) {
return HTTP.read(url)
.then(function (content) {
return content;
}, function (error) {
if (times == 0)
throw new Error("Can't read " + JSON.stringify(url));
@tlrobinson
tlrobinson / storage-decorators.js
Created November 2, 2011 18:12
Example localStorage decorators
// Storage decorator base class
function StorageDecorator(storage) {
this._storage = storage;
}
StorageDecorator.prototype.getItem = function(key) {
return this._storage.getItem(key);
}
StorageDecorator.prototype.setItem = function(key, value) {
return this._storage.setItem(key, value);
@mweststrate
mweststrate / mobx-webcomponent.html
Last active January 22, 2024 08:25
MobX + webcomponents
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/[email protected]/lib/mobx.umd.js"></script>
<script>
var MobxDemo = Object.create(HTMLElement.prototype);
MobxDemo.attachedCallback = function() {
var state = mobx.observable({
counter : parseInt(this.getAttribute("counter"))
})
@WaldoJeffers
WaldoJeffers / compose.js
Last active January 3, 2024 16:47
JavaScript one-line compose (ES6)
const compose = (...fns) => fns.reduce((f, g) => (...args) => f(g(...args)))
// Usage : compose functions right to left
// compose(minus8, add10, multiply10)(4) === 42
//
// The resulting function can accept as many arguments as the first function does
// compose(add2, multiply)(4, 10) === 42
const { getRandomWordSync, getRandomWord } = require("word-maker");
const fs = require("fs");
console.log("It works!");
// YOUR CODE HERE
//Additional functions
//asynchronous in loop