Skip to content

Instantly share code, notes, and snippets.

View nhusher's full-sized avatar

Nicholas Husher nhusher

View GitHub Profile
@nhusher
nhusher / grunt-config.js
Last active December 17, 2015 08:18
A wrapper around the YUI3 Shifter build tool that lets you build YUI projects with grunt.
grunt.initConfig({
// Runs the YUI3 build tool on a directory. Docs: <http://yui.github.io/shifter/>
"shifter": {
"crm-src": {
// (optional) version - What to fill in on the "@VERSION@" field in built files
"version": "CRM",
// (optional) lint can be 'config' or false
// if "config", shifter will use the nearest .jshintrc JSON file as JSHint config
// if "false", shifter will skip the lint step entirely.
"lint" : "config",
@nhusher
nhusher / grunt-yui-rollup.js
Last active December 28, 2015 03:29
Builds a custom rollup version of the YUI project that is tailored to the needs of your YUI3 application.
/*jslint node:true */
module.exports = function (grunt) {
var YUI = require('yui').YUI,
path = require('path'),
yuiVersion = require('../../package.json').dependencies.yui;
grunt.registerMultiTask('yui-rollup', 'Creates a YUI library rollup.', function () {
var Y = YUI(),
loader,
@nhusher
nhusher / 1.stale-branches.sh
Last active August 29, 2015 13:56
This script lists all the branches in the repo that have been merged into master and their last-modified date, along with the author of the last modification. Useful for tracking down stale feature branches that aren't being actively developed.
git branch -a --merged master | grep remotes\/ | sed 's/^[ \t]*//' | xargs -n 1 git log --pretty=format:"%an - %d - %ar %n" -1 | sort | cat
// Takes a string and performs the count operation:
function counts(s) {
var reg = /([\u00BF-\u1FFF\u2C00-\uD7FF\w\d][^,]+),\s*(\d+)/;
// Reduce over each line in the string, modifying an accumulator object at every iteration
return s.split("\n").reduce(function (a, c) {
if (c = reg.exec(c)) { // The regex matches, so it's of the form NAME,NUM, at least in part
// c[0] = full regex string
// c[1] = the first match (the name)
@nhusher
nhusher / 1.trie.js
Last active August 29, 2015 14:00
A working HAMT implementation in JS.
//
// --- Utility Functions ----------------------------------------------------
//
/*
Found at <http://blog.faultylabs.com/2011.php?p=jsbitfun>
@param bits {Number} An integer to run popCnt on.
@return The number of 1 bits in the number.
*/

Programmers get very attached to their favorite languages, and I don't want to hurt anyone's feelings, so to explain this point I'm going to use a hypothetical language called Blub. Blub falls right in the middle of the abstractness continuum. It is not the most powerful language, but it is more powerful than Cobol or machine language.

And in fact, our hypothetical Blub programmer wouldn't use either of them. Of course he wouldn't program in machine language. That's what compilers are for. And as for Cobol, he doesn't know how anyone can get anything done with it. It doesn't even have x (Blub feature of your choice).

As long as our hypothetical Blub programmer is looking down the power continuum, he knows he's looking down. Languages less powerful than Blub are obviously less powerful, because they're missing some feature he's used to. But when our hypothetical Blub programmer looks in the other direction, up the power continuum, he doesn't realize he's looking up. What he sees are merely weird languages. H

(defn fizz-buzzes
"A lazy-seq of the fizz-buzz collection"
([] (fizz-buzzes (fizz-buzzer 1) 2))
([n i] (cons n (lazy-seq (fizz-buzzes (fizz-buzzer i) (inc i))))))
(defn fizz-buzzer
"Returns string 'Fizz' if divides evenly by 3
Returns string 'Buzz' if divides evenly by 5
Returns string 'FizzBuzz' if divides evenly by 3 and 5
Else returns i"
(ns crm-clj.core
(:require [clojure.tools.namespace.repl :refer [refresh]]
[liberator.core :refer [resource defresource]]
[ring.middleware.params :refer [wrap-params]]
[compojure.core :refer [defroutes ANY]]
[ring.adapter.jetty :refer [run-jetty]]
[com.stuartsierra.component :as component ]))
(defn handler [request]
{ :status 200
.
├── Procfile
├── README.md
├── project.clj
├── resources
│ ├── index.html
│ └── public
│ └── styles.css
└── src
├── clj

Diagnosing a threading problem can be similar to how I imagine Formula 1 engineers must feel when trying to diagnose an engine failure. The engine runs flawlessly for hours and then suddenly, with little or no warning, fails spectacularly, showering following cars with oil and lumps of crankcase.

When the car is dragged back to the workshop, the poor engineers are faced with a pile of wreckage and somehow need to figure out what caused the failure. The problem was probably something tiny—a failed oil-pump bearing or broken valve, but how can they tell what it was from the mess on the bench?

What tends to happen is that they put as much data logging in place as possible and send the driver back out with a new engine. Hopefully the data will contain something informative the next time a failure happens.