Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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
})
// 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 / 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()
@aj0strow
aj0strow / component.css
Created December 24, 2015 16:21
Webpack local styles example
:local(.green) {
height: 20px;
background: green;
}
Private Function LinearInterpolate(ByVal x2 As Integer, ByVal y2 As Double,
ByVal x3 As Integer, ByVal y3 As Double) As Double
Try
LinearInterpolate = ((y2 - y3) / (x2 - x3)) * x2 + y2
Catch ex As Exception
SharedLogger.LogException(_moduleID & ":LI", ex) 'Log any exceptions.
LinearInterpolate = (y2 + y3) / 2
End Try
@aj0strow
aj0strow / conditional-constraint.sql
Last active March 31, 2016 17:11
conditiona sql constraint
ADD CONSTRAINT with_old_syntax CHECK (status <> 'closed' OR agent_id IS NOT NULL);
ADD CONSTRAINT with_new_syntax CHECK (agent_id IS NOT NULL) WHERE (status = 'closed');
-- generically it would map as follows
CHECK (check_condition) WHERE (where_condition)
CHECK (NOT (where_condition) OR check_condition)