Skip to content

Instantly share code, notes, and snippets.

View simov's full-sized avatar

simo simov

View GitHub Profile
@simov
simov / monokai-theme-github-code-view-and-gist.css
Last active October 10, 2015 16:07
Monokai Theme for GitHub code view and Gist - http://stylebot.me/styles/1652
/* COMMON */
/*background*/
.type-html,
.type-css,
.type-javascript,
.type-html .highlight,
.type-css .highlight,
.type-javascript .highlight,
@simov
simov / readdirr.js
Created November 22, 2012 20:00
Recursive directory listing in NodeJS.
var fs = require('fs'),
path = require('path');
var dir = null, file = null;
exports.readdirr = function (dpath, cb) {
dir = [], file = [];
dir.push(dpath);
@simov
simov / moment-weeks.js
Created November 28, 2012 23:21
Helper functions for weeks in moment.js
var moment = require('moment');
moment.fn.isISO = true;
moment.fn.dayISO = function () {
var self = this.clone();
return self.day() == 0 ? 6 : self.day()-1;
}
@simov
simov / function-events.js
Last active December 10, 2015 13:48
The `list` function is looping through a list of asynchronous operations. The `main` function is notified about the state of the `list` function on each step.
function list (step, end) {
function loop (index) {
if (index == 10) return end();
step(index, function next () {
loop(++index);
});
}
loop(0);
}
@simov
simov / function-chain.js
Created April 27, 2013 16:19
Chaining asynchronous functions.
function chain () {
var funcs = arguments;
return function (args, cb) {
(function next (index) {
if (index == funcs.length) return cb();
funcs[index](args, function (err) {
if (err) return cb(err);
next(++index);
});
@simov
simov / sublime-shortcuts.md
Created September 4, 2013 16:21
Sublime Text 2 Shortcuts

#Sublime Text 2 Shortcuts

###Legend

key symbol
ctrl
shift
alt
tab
@simov
simov / readdirr.js
Last active August 29, 2015 14:14
Recursively read directory using generators, co and thunkify
var fs = require('fs')
, path = require('path')
, co = require('co')
, thunkify = require('thunkify')
, readdir = thunkify(fs.readdir)
, stat = thunkify(fs.stat)
var recursive = co.wrap(function* (root) {
var dirs = [], files = []
@simov
simov / readdirr2.js
Last active January 28, 2016 23:13
Recursively read directory using async/await and bluebird
let fs = require('fs')
, path = require('path')
, bluebird = require('bluebird')
, readdir = bluebird.promisify(fs.readdir)
, stat = bluebird.promisify(fs.stat)
let recursive = async (root) => {
let dirs = [], files = []
dirs.push(root)
@simov
simov / app.js
Created May 5, 2015 15:39
Modifying the global state
var file1 = require('./file1')
var file2 = require('./file2')
@simov
simov / readdirr.js
Last active August 29, 2015 14:21
Recursive asynchronous streaming of directory
import fs from 'fs'
import path from 'path'
import stream from 'stream'
import bluebird from 'bluebird'
bluebird.promisifyAll(fs)
class Readdirr extends stream.Readable {
constructor(root) {