Skip to content

Instantly share code, notes, and snippets.

View AndrewThian's full-sized avatar
🎯
Focusing

AndrewThian AndrewThian

🎯
Focusing
  • Singapore
View GitHub Profile
{
"jsonGraph": {
"videos": {
"80988062": {
"interactiveVideoMoments": {
"$type": "atom",
"$size": 272836,
"value": {
"type": "bandersnatch",
"choicePointNavigatorMetadata": {
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,
});
@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

/*
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 / 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
@AndrewThian
AndrewThian / data-structures_linkedlist.js
Created February 9, 2019 05:27
Implementing datastructures: singly linked list
class LinkedList {
constructor(head=null) {
this.head = head;
this.count = 0;
}
add (newData) {
// create node
// reference previous node to new node
let temp = new Node(null, newData);
let current = this.head;
@AndrewThian
AndrewThian / printPrime.js
Created February 9, 2019 05:26
js challenge print if number is prime.
function printPrime (num) {
for (let counter = 1; counter <= num; counter++) {
let prime = true;
for (let j = 2; j <= counter; j++) {
// if it can modus without remainder and it's not it self, means it's not prime
if (counter % j === 0 && counter !== j) {
prime = false;
}
}
if (prime) {
@AndrewThian
AndrewThian / containsString.js
Created February 9, 2019 05:25
asserts if string contains another string
function checkstring(str) {
let pointer = 0;
let len = str.length
let smileCount = 0
let smileyBank = []
while (pointer < len - 1) {
const currentSymbol = str[pointer]
const nextSymbol = str[pointer + 1]
if (currentSymbol === ":") {
console.log(currentSymbol, nextSymbol)
@AndrewThian
AndrewThian / balanced.js
Created February 9, 2019 05:24
js challenge for asserting if brackets are balanced
function balanced(str) {
const stack = []
let top;
for (let i = 0; i < str.length; i++) {
const char = str[i]
if (char === "(" || char === "{" || char === "[") {
console.log("pushing to stack")
stack.push(char)
} else {
if (stack.length === 0) {
@AndrewThian
AndrewThian / substring.js
Last active February 9, 2019 05:23
js challenge for asserting substrings
function substring(str) {
if (str.length <= 1) {
return str.length
}
let startpoint = 0;
let max = 0;
let len = str.length;
let lookup = new Map();
let dictionary = new Map();