Skip to content

Instantly share code, notes, and snippets.

Timo Kissing tkissing

  • LogMeIn
  • Goleta, CA
Block or report user

Report or block tkissing

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
tkissing / .bashrc
Created May 16, 2017
Bash function to clone a repo into ~/Stash/${PROJECT}/${REPO} and run `npm i` in it all in one go (pass clone URL as argument)
View .bashrc
stashclone() {
if [[ "${1}" =~ \/([^\/]+)\/([^\/]+).git$ ]]; then
PROJ=`echo "${BASH_REMATCH[1]}" | awk '{ print toupper($1); }'`
if [ -d "${RDIR}" ]; then
echo "${RDIR} is already there"
View chai-assert-for-tape.js
const chai = require('chai');
module.exports = (t) => {
return Object.keys(chai.assert).reduce((prev, curr) => {
let assertion = chai.assert[curr];
if (typeof assertion == 'function') {
prev[curr] = (...args) => {
try {
assertion.apply(chai.assert, args);
tkissing / new-promise-reject.js
Created Dec 9, 2016
Using throw inside new Promise()
View new-promise-reject.js
new Promise((resolve, reject) => {
resolve( => {
if ( {
reject(Error('Found a foo!'));
// the .map will continue to loop
// even resolve will still be called although it won't have any more effect
tkissing /
Last active Jun 28, 2016 — forked from tracker1/
Anatomy of a JavaScript/Node project.

Directory structure for JavaScript/Node Projects

While the following structure is not an absolute requirement or enforced by the tools, it is a recommendation based mostly on what the JavaScript and in particular Node community at large have been following by convention.

Beyond a suggested structure, no tooling recommendations, or sub-module structure is outlined here.


  • src/ is for the code you write manually independent of the module format
  • lib/ is for modules compiled from src/ into a format compatible with standard require in the node versions indicated by engines in your package.json (UMD, CommonJS)
  • dist/ is for modules or scripts compiled from src/ into formats not compatible with standard require in the node versions indicated by engines in your package.json (AMD, browser globals/IIFE)
View original.js
// promise code
function add5 (x) {
return x + 5
function add5Promise (x) {
return Promise.resolve(x).then(function (x) {
return add5(x)
View pubsub-observable.js
define(function(require) {
var ko = require('knockout');
function observeEvent(pubsub, options) {
var o = ko.observable();
Object.keys(options).forEach(function(evt) {
var value = options[evt];
pubsub.on(evt, function() {
tkissing / gist:786bd8381fd5688bb9c9
Created Mar 31, 2015
Careful when using .then(successHandler, errorHandler) - it might not do what you mean to do!
View gist:786bd8381fd5688bb9c9
(function() {
p = Promise.resolve(3);
p.then(function() { throw Error('e'); }, console.warn.bind(console, 'You will not see this one'));
p.then(function() { throw Error('e'); }).then(null, console.warn.bind(console, 'You will see this one'));
tkissing / from-yesterday
Created Mar 26, 2015
npm registry weirdness
View from-yesterday
cat node_modules/chai-as-promised/package.json | grep version
"version": "4.3.2",
tkissing / gist:b4944c285c761efeff9e
Created Mar 10, 2015
setInterval wrapper that returns "stop" method.
View gist:b4944c285c761efeff9e
function startInterval(func, freq) {
var id = setInterval(func, freq);
return function() {
if (id) {
id = null;
return true;
return false;
tkissing / gist:e5fa4908150c82d73131
Last active Feb 12, 2019
Singleton JavaScript modules that are easy to test! (Hint: Avoid object literals)
View gist:e5fa4908150c82d73131
// using AMD syntax here to avoid confusion about scope and file boundaries,
// but the concept translates 1:1 to CommonJS (node/io) modules
define('badSingleton', function(require, exports, module) {
var dependency = require('dependency');
var privateState;
module.exports = {
foo: function() {
You can’t perform that action at this time.