Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

AndrewThian AndrewThian

🎯
Focusing
View GitHub Profile
View bandersnatch.json
{
"jsonGraph": {
"videos": {
"80988062": {
"interactiveVideoMoments": {
"$type": "atom",
"$size": 272836,
"value": {
"type": "bandersnatch",
"choicePointNavigatorMetadata": {
View sass-resolver.js
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 Apr 22, 2019
Automatic iterm2 window creation
View iterm2.md

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

View async-test.js
/*
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 Apr 8, 2019
How does a race condition happen when we return both a synchronous callback and asynchronous callback!
View callbacks.js
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 Feb 9, 2019
Implementing datastructures: singly linked list
View data-structures_linkedlist.js
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 Feb 9, 2019
js challenge print if number is prime.
View printPrime.js
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 Feb 9, 2019
asserts if string contains another string
View containsString.js
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 Feb 9, 2019
js challenge for asserting if brackets are balanced
View balanced.js
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 Feb 9, 2019
js challenge for asserting substrings
View substring.js
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();
You can’t perform that action at this time.