Skip to content

Instantly share code, notes, and snippets.

@aj0strow
aj0strow / websocket-reconnect.coffee
Last active December 3, 2015 01:05
Auto-reconnecting websockets without changing any code
{EventEmitter} = require "events"
backoff = require "backoff"
WebSocket = require "ws"
class EverSocket extends EventEmitter
constructor: (url, options) ->
@connected = false
@reconnect = true
@backoff = backoff.fibonacci()
// node lock-catcher.js myprogram.go
var reader = require('line-reader')
var file = process.argv[2]
var prev = null
reader.eachLine(file, function (line) {
if (prev && /Lock/.test(prev) && !/defer/.test(line)) {
console.error('You probably messed up.')
}
@aj0strow
aj0strow / self-closing-jsx-tags.js
Created November 5, 2015 22:28
Codemod script to prefer self-closing JSX tags
// jscodeshift -t self-closing-jsx-tags.js ./src
module.exports = function(file, api) {
let j = api.jscodeshift
let root = j(file.source)
root.find(j.JSXElement)
.filter(function (path) {
return !path.value.children.length
})
@aj0strow
aj0strow / typos.txt
Created October 30, 2015 17:05
Inspired Book typos
Chapter 9 / Mira / Page 59
"Through you off" -> "Throw"
Chapter 11 / After 10 Qs / Page 70
"rather than the a crisp"
Chapter 16 / Limitations / Page 103
"What product to build?"
"FaceBook" inconsistent
@aj0strow
aj0strow / style.css
Created October 17, 2015 21:25
Atom text editor theme for small fonts
/*
If you have font size around 12, it's pretty annoying to have no space at the top
of the file. To fix, add this class selection.
*/
atom-text-editor:not(.mini)::shadow {
.scroll-view { padding-top: 10px; }
.gutter { padding-top: 10px; }
@aj0strow
aj0strow / run.sh
Created September 21, 2015 18:10
Webpack testing with mocha in the browser
open http://localhost:8080/bundle
webpack-dev-server --config webpack.test.js --hot
@aj0strow
aj0strow / subscribe.js
Created July 15, 2015 20:37
MongoDB capped collection event stream
var through = require('through2')
function subscribe (collection, params) {
var options = {
tailable: true,
awaitData: true,
noTimeout: true,
numberOfRetries: Number.MAX_VALUE,
}
@aj0strow
aj0strow / examples.js
Created May 25, 2015 21:03
YQL finance data
YQL('yahoo.finance.quotes')
.where({ symbol: [ '^IXIC' ] })
.select([ 'Symbol', 'LastTradePriceOnly', 'Change', 'PercentChange' ])
.then(function (results) {
console.log(results)
})
YQL('yahoo.finance.historicaldata')
.where('symbol', '=', 'PRFC')
.where({ startDate: new Date(2015, 4, 1), endDate: new Date(2015, 4, 23) })
@aj0strow
aj0strow / index.js
Created December 28, 2014 23:30
firebase child readable stream
var PassThrough = require('stream').PassThrough
function createChildStream(ref) {
var stream = new PassThrough({ objectMode: true })
ref.limitToLast(1).once('child_added', function(snap) {
var stopKey = snap.key()
ref.on('child_added', function(snap) {
stream.push(snap.val())
if (snap.key() == stopKey) {
ref.off('child_added')
@aj0strow
aj0strow / diff.rb
Created December 16, 2014 21:22
diff heroku env
require 'set'
one = ARGV.shift
two = ARGV.shift
xs, ys = [ one, two ].map do |app_name|
text = `heroku config -a #{app_name}`
Set.new(text.scan(/^(\w+):/))
end