Skip to content

Instantly share code, notes, and snippets.

View justsml's full-sized avatar
🔥
#BLM

Dan Levy justsml

🔥
#BLM
View GitHub Profile
@Daniel-Hug
Daniel-Hug / function-bind.js
Last active August 31, 2017 11:26 — forked from dsingleton/function-bind.js
Polyfill for Function.prototype.bind
Function.prototype.bind=(function(){}).bind||function(b){if(typeof this!=="function"){throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable");}function c(){}var a=[].slice,f=a.call(arguments,1),e=this,d=function(){return e.apply(this instanceof c?this:b||window,f.concat(a.call(arguments)));};c.prototype=this.prototype;d.prototype=new c();return d;};
@sixones
sixones / qsa-polyfill-ie7.js
Last active August 31, 2017 11:38 — forked from connrs/qsa-polyfill-ie7.js
IE7 polyfill for document.querySelectorAll
if (!document.querySelectorAll) {
document.querySelector = function(selector) {
return document.querySelectorAll(selector)[0];
}
document.querySelectorAll = function(selector) {
if (document.__querySelectorAllStylesheet === undefined) {
document.__querySelectorAllStylesheet = document.createStyleSheet();
}
@tomdale
tomdale / bytecode.ts
Created October 20, 2017 16:45
Glimmer.js Application proposal
// This is the API for constructing a Glimmer.js application with
// precompiled binary bytecode templates and using an async renderer
// (via requestAnimationFrame, requestIdleCallback, etc).
import Application, { DOMBuilder, AsyncRenderer, BytecodeLoader } from '@glimmer/application';
import data from './__compiled__/data';
let bytecode = fetch('./__compiled__/templates.gbx')
.then(req => req.arrayBuffer());
@justsml
justsml / rest-arrays-template.js
Last active November 27, 2017 21:07
REST Route Templates w/ Data Layer Code Included
const router = module.exports = require('express').Router();
const items = [] // in-memory 'dummy data source'
// Standard CRUD routes:
router.get('/', getAll)
router.get('/:id', getOne)
router.post('/', create)
router.put('/:id', update)
router.delete('/:id', remove)
@littledan
littledan / header.jsidl
Created December 4, 2017 18:12
Should JavaScript use a header file format (a la WebIDL) to define its standard library?
@namespace
class Math {
static abs(x: Number): Number; // Types optional; provide cast on input and assertion on ouptut
@nonwritable
static LOG10E: Number;
// ...
}
@justsml
justsml / docker-clone-backup-example.sh
Created August 3, 2015 05:44
Clone/Backup Docker - Live Stream over SSH pipe !!!!
# Save the built CONTAINER (named myapp), stream via ssh
docker save myapp | bzip2 | pv | ssh root@vhost2 'bunzip2 | docker load'
# Clone a running INSTANCE, stream via ssh
docker export web0 | bzip2 | pv | ssh root@vhost2 'bunzip2 | docker import web0'
@justsml
justsml / app.js
Last active February 4, 2018 17:17
DAN'S REFERENCE EXPRESS APP TEMPLATE:
// TODO: INSTALL PRE-REQS: `npm install express cors body-parser morgan monk`
const http = require('http')
const express = require('express')
const bodyParser = require('body-parser')
const morgan = require('morgan')
const cors = require('cors')
const app = module.exports = express()
const server = http.createServer(app)
const port = parseInt(process.env.PORT || 3000)
@chadwithuhc
chadwithuhc / declaring-values-in-function.js
Last active February 7, 2018 00:05
React Refactors for Clean Code
// Challenge: Refactor the `render()` method with declare all variables at top
render() {
return (
<li>
<div className="profile-card">
<header className="profile-header" onClick={this.toggleClass}>
<img src={this.props.profile.image} alt={this.props.profile.name} />
<h2>{this.props.profile.name}</h2>
</header>
@rafagarcia
rafagarcia / tinydomready.js
Created November 28, 2012 08:29 — forked from dciccale/README.md
Tiny Cross-browser DOM ready function (120 bytes)
// @param {function} f The function to execute when DOM is ready
function a(f,o,m){o=document,m='addEventListener';o[m]?o[m]('DOMContentLoaded',f):(o=window,o.attachEvent('onload',f));}
@justsml
justsml / cache.js
Created March 11, 2018 09:07
Debounce Promise Results using Naïve Timeout-based Expiration/Caching
module.exports = { createCachedPromise, cacheifyAll };
// TODO: Add Map/WeakMap cache isolation for arguments passed into cacheifyAll's methods
/**
* Extends all functions on an Object or Class with 'Cached' suffixed methods.
* Methods must return promises when called! Won't break existing functions/usage.
*
* -----
*