Skip to content

Instantly share code, notes, and snippets.

@tomshen
tomshen / sync-callbacks-promises.js
Created January 22, 2014 01:12
Demonstrating three different ways to delete files whose names are stored in an array.
var companies = [/* ... */];
/* WITH SYNC */
var fs = require("fs");
companies.forEach(fs.unlinkSync(company)); // this is blocking
console.log("All files deleted");
/* WITH CALLBACKS */
var fs = require("fs");
var RenderObject = function(rend, drawingContext){
var currentCtx = (drawingContext !== undefined) ? drawingContext : ctx;
if ( (rend.visible == undefined) ? true : rend.visible){
currentCtx.save();
if (rend.x != undefined && rend.y != undefined)
currentCtx.translate(rend.x, rend.y);
else if (rend.loc != undefined)
currentCtx.translate(rend.loc.getX(), rend.loc.getY());
@tomshen
tomshen / toolbelt.md
Last active December 14, 2015 16:10
Tom's Toolbelt

Very outdated.

Tom's Toolbelt

A highly opinionated list of the things I use to make other things.

I develop on OS X and deploy to Ubuntu. A Macbook Air with a retina display would be a perfect laptop. I use Sublime Text 3 to write almost all my code. Homebrew is my package manager of choice.

Table of Contents

@tomshen
tomshen / learning.md
Last active August 29, 2015 14:07
Best-in-class tutorials and guides
@tomshen
tomshen / bug.sml
Created March 28, 2016 03:46
Type the following into a SML/NJ REPL.
fun sml n j = (j+1, if n = j then j else j+1)
@tomshen
tomshen / ffmpeg-timelapse.md
Created May 25, 2017 12:57
How to Create a Time-lapse with ffmpeg

How to Create a Time-lapse with ffmpeg

Given a directory containing:

.
├── LRT_00001.jpg
├── LRT_00002.jpg
├── LRT_00003.jpg
├── LRT_00004.jpg
@tomshen
tomshen / youtube-download.md
Created May 25, 2017 13:00
How to Download a YouTube Video in MP4 with Subtitles

How to Download a YouTube Video in MP4 with Subtitles

Install youtube-dl:

brew install youtube-dl
pip install youtube-dl

and run the following:

@tomshen
tomshen / surf-macos.md
Created July 12, 2017 12:55
[WIP] Installing surf 2.0 on macOS 10.12.5
# Install dependencies
brew install cmake enchant gstreamermm gtk+3 libnotify libsecret libsoup webp
git clone git@github.com:hunspell/hyphen.git
cd hyphen
autoreconf -fvi
./configure
make
make install
@tomshen
tomshen / rename-files.md
Created August 8, 2017 08:23
How to rename multiple files with a find/replace

How to rename multiple files with a find/replace

for f in *Huge*; do mv $f ${f/Huge/Monstrous}; done

Source

"use strict";
// This file was originally written by @drudru (https://github.com/drudru/ansi_up), MIT, 2011
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var ANSI_COLORS = [[{ color: "0, 0, 0", "class": "ansi-black" }, { color: "187, 0, 0", "class": "ansi-red" }, { color: "0, 187, 0", "class": "ansi-green" }, { color: "187, 187, 0", "class": "an