Skip to content

Instantly share code, notes, and snippets.

@zachwolf
zachwolf / grunt-task-input-listener.js
Last active August 29, 2015 13:56
Listen for input during a grunt watch task
var spawn = require('child_process').spawn;
module.exports = function(grunt) {
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function (data) {
data = (data + '').trim().toLowerCase();
if (data === "test") {
@zachwolf
zachwolf / app.html
Last active August 29, 2015 14:02
modernizr with jquery and tests
<script>
// only load scripts if it's for desktop
if (Modernizr.mq('(min-width: 500px)')) {
Modernizr.load([
{
load: '//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js',
complete: function () {
// only load jquery if the cdn version isn't available
if ( !window.jQuery ) {
Modernizr.load('scripts/lib/jquery.js');
@zachwolf
zachwolf / chain.js
Created October 9, 2014 16:39
Make a JavaScript objects methods chainable
/**
* Allows for chaining on an object.
* Functions will be able to be called normally,
* but all other types need to be accessed using
* `Chain.set(prop, val)` and `Chain.get(prop)`
*
* I haven't tested this in many browsers yet.
* Until then, it's probably safer to use something like
* LeaVerou's Chainvas
* http://leaverou.github.io/chainvas/
@zachwolf
zachwolf / deepclone.js
Created January 30, 2015 23:30
Deep clone function
/**
* Creates a copy of a mutable object to a certain depth.
* Useful when nested obects need to be cloned, since _.clone only
* produces a shallow copy.
*
* NOTE: this function is overkill if you want to copy the whole thing without a depth limit.
* Alternatively, just stringify and parse the object like:
function deepClone (obj) {
return JSON.parse(JSON.stringify(obj));
let Foo = (function () {
let __secrets = new WeakMap();
class Foo {
constructor () {
__secrets.set(this, Math.floor(Math.random()*100));
}
get bar() {
return __secrets.get(this);
}
@zachwolf
zachwolf / gist:edb5b1ae8216f2ef8e40
Created November 21, 2015 06:45
terminal whatnot
# add folder to zip
> zip -r filename.zip directory/*
@zachwolf
zachwolf / build-less.js
Created February 7, 2016 06:39
builds less files on request
var Promise = require('bluebird')
, less = Promise.promisifyAll(require('less'))
, path = require('path')
, fs = require('fs')
, through = require('through2')
app.get('/node_modules/bootstrap/less/glyphicons.less', (req, res) => {
res.header("Content-type", "text/css");
fs.createReadStream(path.join(__dirname, './node_modules/bootstrap/less/glyphicons.less'))
[ignore]
<PROJECT_ROOT>/node_modules/material-ui/styles/withStyles.js.flow
<PROJECT_ROOT>/node_modules/react-scrollbar-size/node_modules/react-event-listener/.*
<PROJECT_ROOT>/node_modules/jss/lib/renderers/DomRenderer.js.flow
<PROJECT_ROOT>/node_modules/jss/lib/rules/ConditionalRule.js.flow
<PROJECT_ROOT>/node_modules/jss/lib/rules/FontFaceRule.js.flow
<PROJECT_ROOT>/node_modules/jss/lib/rules/KeyframesRule.js.flow
<PROJECT_ROOT>/node_modules/jss/lib/rules/StyleRule.js.flow
<PROJECT_ROOT>/node_modules/jss/lib/rules/ViewportRule.js.flow
<PROJECT_ROOT>/node_modules/jss/lib/rules/SimpleRule.js.flow
const MARKER = '__jss-snapshot-serializer-marker__';
const jssClassNameRegexp = /(^(?:[^-]+)-\w+)(?:(?:-\d+){1,2})/i;
const collectElements = (element, elements = []) => {
if (typeof element !== 'object') {
return elements;
}
elements.push(element);