Skip to content

Instantly share code, notes, and snippets.

View indexzero's full-sized avatar
🌎
Always bet on Open Source

Charlie Robbins indexzero

🌎
Always bet on Open Source
View GitHub Profile
@indexzero
indexzero / sanitize-filter.js
Created August 3, 2015 14:51
Simple sanitization and filtering in JavaScript
var filtered = {
bazz: true,
buzz: true
};
var maps = {
foo: function (value, acc) {
return value * 10;
},
bar: function (value, acc) {
@indexzero
indexzero / README.md
Last active August 29, 2015 14:25
TIL that env var values in "scripts" in package.json files are respected by npm.

npm-scripts-envvar

It works!

$ npm test
npm info it worked if it ends with ok
npm info using npm@2.7.5
npm info using node@v0.10.38
npm info pretest npm-scripts-envvar@1.0.0
@indexzero
indexzero / fix-npm-install.sh
Created July 17, 2015 23:43
Make npm work good on linux and stuff.
#
# 1. Set your npm prefix to ~/.node_modules
# nb. Windows users here be dragons.
#
npm c set prefix $HOME/.node_modules
mkdir $HOME/.node_modules
#
# 2. Update your path to give the bin location of
# the new prefix directory highest precedence
@indexzero
indexzero / deacronymify.js
Created May 8, 2015 21:41
PascalCase DEAcronym-er
function deacronym(anyKey) {
return anyKey.replace(/([A-Z]+)[A-Z]/g, function (match, cap, i, str) {
var sub;
if (i + match.length === str.length) {
sub = match.slice(1);
} else {
sub = !i ? cap.slice(1) : match.slice(1, -1);
}
return match.replace(sub, sub.toLowerCase());
@indexzero
indexzero / format-usage.js
Last active August 29, 2015 14:19
Concept for winston@2.0.0
var format = winston.label()
.pipe(winston.timestamp())
.pipe(winston.colorize())
var logger = winston.logger({
transports: [
winston.file({
format: format,
})
.pipe(winston.gzip())

Better local require() paths for Node.js

Problem

When the directory structure of your Node.js application (not library!) has some depth, you end up with a lot of annoying relative paths in your require calls like:

var Article = require('../../../models/article');

Those suck for maintenance and they're ugly.

Possible solutions

@indexzero
indexzero / fns.js
Created March 14, 2015 23:52
Fun with `function.apply` and `Array.reduce`
function logAndSum(sum, n) {
console.log('%s + %s = %s', sum, n, n + sum);
return n + sum;
}
function logAndSumAll () {
var args = Array.prototype.slice.call(arguments);
console.log(
args.join(' + ') + ' = ' + args.reduce(function (sum, n) { return sum + n }, 0)
);
@indexzero
indexzero / personal-blog.md
Created February 9, 2015 20:06
From new to old, and from old to new

Title: From new to old, and from old to new

If you haven’t heard already: Nodejitsu is joining the team at GoDaddy. I can only speak of my own experience, but I imagine that every startup exit is much like running the startup itself: a whirlwind of emotions that takes a high constitution to process. Now don’t read any negative connotations in that statement since a whirlwind of positive emotions is still a whirlwind of emotions. The startup rollercoaster. After all, no one said that building a technically challenging vision on a brand new technology that was still evolving while simultaneously helping the underlying technology itself (Node.js) become successful was going to be easy.

If it was easy it would just be the way.

Being a founder, CEO, and technical product manager over the last (almost) five years at Nodejitsu is and has been an amazing experience. I often tell people who are thinking of starting companies: don’t. Expressing that sentiment is only to deter those without the wherewithal a

@indexzero
indexzero / Makefile
Last active August 29, 2015 14:13 — forked from isaacs/Makefile
# Hello, and welcome to makefile basics.
#
# You will learn why `make` is so great, and why, despite its "weird" syntax,
# it is actually a highly expressive, efficient, and powerful way to build
# programs.
#
# Once you're done here, go to
# http://www.gnu.org/software/make/manual/make.html
# to learn SOOOO much more.
@indexzero
indexzero / README.md
Last active August 29, 2015 14:12
Myo C++ Header files. Who wants to write a node binding for this?

The state of Myo bindings in Node.js

... any takers? Comment on this gist! The discussion all started from a Tweet:

Who's going to be the first to write a wrapper for the @thalmic #myo C++ library? Latest headers: https://gist.github.com/indexzero/60d1224f0082f0d16f14

As pointed out by @c4milo there are a number of libraries that exist, but from first glance they all have deficiencies: