Skip to content

Instantly share code, notes, and snippets.

@donabrams
donabrams / ImmutableTransducerTest.js
Created July 16, 2015 16:50
Tests for transducer protocol support for Immutable.js
/*global describe, it */
let {expect} = require('chai');
let {Map, List, Set, Stack} = require('immutable');
let t2 = require('transduce');
describe('Immutable Transducer support', ()=> {
it('List supports transducer protocols', () => {
let val = t2.into(List(), t2.filter(()=>true), ['a', 'b', 'c']).toJS();
expect(val).to.deep.equal(['a', 'b', 'c']);
});
@donabrams
donabrams / gist:b69a4e25827dc2ce7305
Last active March 2, 2017 06:12
Mutation related rules in eslint
http://eslint.org/docs/rules/no-extend-native
http://eslint.org/docs/rules/no-return-assign
http://eslint.org/docs/rules/no-param-reassign
http://eslint.org/docs/rules/no-native-reassign
http://eslint.org/docs/rules/no-extend-native
http://eslint.org/docs/rules/no-ex-assign
http://eslint.org/docs/rules/no-func-assign
http://eslint.org/docs/rules/no-ex-assign
@donabrams
donabrams / testStreams.js
Last active August 29, 2015 14:24
Node Streams (through and though2)
var through2 = require('through2');
var through = require('through');
var fs = require('fs');
//This is what most people use
fs.createReadStream('testStreams.js')
.pipe(through2(function(chunk, enc, cb) {
console.log('t2', 's1');
cb(null, chunk);
}, function(cb) {
@donabrams
donabrams / gist:3713730
Created September 13, 2012 11:34
How to make a webpage have exactly no design
br {
display: none !important;
}
html * {
display: inline !important;
font-size: 6pt !important;
float: none !important;
word-wrap: nowrap !important;
white-space: nowrap !important;
position: static !important;
@donabrams
donabrams / gist:3621626
Created September 4, 2012 14:24
Newton's Metod
newtonApprox = (x0, f, fprime, error) ->
x1 = x0 - f(x0)/fprime(x0)
if Math.abs(x1-x0) < error
x1
else
newtonApprox(x1, f, fprime, error)
@donabrams
donabrams / clean.sh
Created August 20, 2012 18:28
GIT clean branches that have already been merged
alias cleanbr='!git branch -r --no-color --merged | grep -v \"/\\(master\\|develop\\|integration\\)$\" | sed \"s/\\// :/\" | xargs -L1 git push && git branch --no-color --merged | grep -v \" \\(master\\|develop\\|integration\\)$\" | xargs -L1 git br -d'
@donabrams
donabrams / gist:3194901
Created July 28, 2012 21:37
heroku node web app skeleton with scalable webserver, rss, and websockets
var MONGO_URI = process.env.MONGOLAB_URI || 'mongodb://127.0.0.1:27017/test';
var PORT = process.env.PORT || 8000;
var url = require('url');
var REDIS_URI = url.parse(process.env.REDISTOGO_URL || "redis://dev:[email protected]/");
var express = require('express');
var sio = require('socket.io');
var rss = require('rss');
var RedisStore = require('connect-redis')(express);
var redisAuth = REDIS_URI.auth.split(':');
@donabrams
donabrams / emBasedLayout.coffee
Created July 28, 2012 21:33
Change em-based size by adjusting font-size
# reflexive layout based on em's
(($el, scale) ->
win = $(window)
# simplified version of fittext.js
resize = ->
$el.css 'font-size', win.width()/scale
resize()
win.on 'resize', resize
) $("body"), 80.0
@donabrams
donabrams / hasHiddenOverflow.js
Created July 16, 2012 20:51
jquery plugin to detect overflow
$.fn.hasHiddenOverflow = function() {
var el = this.first()[0];
console.log(el);
return el.scrollHeight > el.clientHeight || el.scrollWidth > el.clientWidth;
};
@donabrams
donabrams / chromeReset
Created July 16, 2012 20:50
Force Chrome GUI reset
//Work around to force refresh of #pains in chrome
var pains = $("#pains");
console.log($("#pains").css("-webkit-transform"));
if ($("#pains").css("-webkit-transform") == "translateZ(1px)") {
$("#pains").css("-webkit-transform","none");
}
else {
$("#pains").css("-webkit-transform",'translateZ(1px)');
}