Skip to content

Instantly share code, notes, and snippets.

var pattern = function(value){
switch(true){
case (function(v){return v === 2})(value):
console.log('bach');
break;
case (function(v){return v === 3})(value):
console.log('bing');
break;
default:
console.log('bar!');
@goliatone
goliatone / merge.js
Created August 20, 2014 18:15
merge only an object's properties into target that are defined in a given array.
define('helpers/merge', function() {
/**
* Extend method. Deep cloning.
* @param {Object} target Object to be extended.
* @return {Object} Extended object.
*/
var _merge = function merge(target, attributes) {
var sources = [].slice.call(arguments, 2);

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

@goliatone
goliatone / queue.js
Created October 4, 2014 23:27
Simple queue
define('helpers/queue', function() {
var Queue = {};
Queue.items = [];
Queue.enqueue = function(process) {
var id = Queue.items.push(process);
setTimeout(function() {
Queue.update(id);
}, 0);
};
window.pathToRegExp = function (path, keys, options) {
keys || (keys = []);
options || (options = {});
// https://github.com/aaronblohowiak/routes.js
path = path
.concat('/?')
.replace(/\/\(/g, '(?:/')
.replace(/(\/)?(\.)?:(\w+)(?:(\(.*?\)))?(\?)?|\*/g, function(_, slash, format, key, capture, optional){
if (_ === "*"){
keys.push(undefined);
@goliatone
goliatone / repeat_with_template.js
Last active August 29, 2015 14:07
simple javascript helper, repeat method
define('helpers/repeat', ['extend'], function(extend) {
/**
* template:
* repeat(20).with({image:default.png, private:true});
*/
var repeat = function(times) {
var a = Array.apply(null, new Array(times));
a.with = function(template){
return a.map(function(){
return extend({}, template);

tmux cheatsheet

As configured in my dotfiles.

start new:

tmux

start new with session name:

@goliatone
goliatone / idneticons.html
Last active August 29, 2015 14:07
Render identicon with canvas/JS
<!doctype html>
<!-- paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/ -->
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7" lang="en"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8" lang="en"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9" lang="en"> <![endif]-->
<!--[if gt IE 8]><!-->
<html class="no-js" lang="en">
<!--<![endif]-->
<head>
<meta charset="utf-8">

Keybase proof

I hereby claim:

  • I am goliatone on github.
  • I am goliatone (https://keybase.io/goliatone) on keybase.
  • I have a public key whose fingerprint is 2800 9857 8DC3 5C2F 36C2 CA16 9978 6DBB B866 E8D7

To claim this, I am signing this object:

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