Skip to content

Instantly share code, notes, and snippets.

View AndrewThian's full-sized avatar
🎯
Focusing

AndrewThian AndrewThian

🎯
Focusing
  • Singapore
View GitHub Profile
@AndrewThian
AndrewThian / callbacks.js
Created April 8, 2019 04:53
How does a race condition happen when we return both a synchronous callback and asynchronous callback!
const fs = require('fs');
const cache = {};
function zalgoRead(filename, cb) {
const file = cache[filename];
if (typeof file !== 'undefined') {
console.log('reading from cache');
cb(null, file);
return
/*
Task:
- request all files asynchronously
- print them out in order of file1 > file2 > file3
- print result as soon as it returns
- after all done, print "Completed!"
- only rely on promise without any promise helper (i.e Promise.all)
*/
// ======= implementation 1 ======== //
@AndrewThian
AndrewThian / iterm2.md
Last active April 22, 2019 03:40
Automatic iterm2 window creation

Steps

We'll be using itermocil to aid the creation process.

  1. Simply follow the installation process in the itermocil repo (best way to install is brew, which we already have)

  2. Create a folder .itermocil in your home folder

  3. itermocil uses a yaml based configuration file. The filename is the key to trigger the iterm creation process. E.g the w99.yml would be instantiated with itermocil w99

const argv = require('minimist')(process.argv.slice(2));
const stats = require('./sass-colors');
const readline = require('readline');
const fs = require('fs');
const rl = readline.createInterface({
input: fs.createReadStream(argv.f),
console: false,
});
{
"jsonGraph": {
"videos": {
"80988062": {
"interactiveVideoMoments": {
"$type": "atom",
"$size": 272836,
"value": {
"type": "bandersnatch",
"choicePointNavigatorMetadata": {