Skip to content

Instantly share code, notes, and snippets.

View AndrewThian's full-sized avatar
🎯
Focusing

AndrewThian AndrewThian

🎯
Focusing
  • Singapore
View GitHub Profile
# find various file extensions and copy to provided directory
# https://stackoverflow.com/questions/5241625/find-and-copy-files
find / \( -name "*.html" \) -exec cp {} /<directory>;
# grep to find emails
# https://stackoverflow.com/questions/2898463/using-grep-to-find-all-emails
grep -Eiorh '([[:alnum:]_.-]+@[[:alnum:]_.-]+?\.[[:alpha:].]{2,6})' "$@" * | sort | uniq > <filename>.txt
@AndrewThian
AndrewThian / decorators.js
Created August 15, 2018 06:55
A simple gist to explain using HoF
// Simple logging functionality
const sqrt = Math.sqrt;
console.log("result", sqrt(16))
console.log("result", sqrt(9))
// ======= logging ====== //
// Introducing logging within the function
// another approach is used by libraries such as jQuery
// similar to annoymouns-closure.js but now we passing global variables as parameters
var $ = { window: {} };
(function (globalVariable) {
// Keep this variables private inside this closure scope
var privateFunction = function() {
console.log('Shhhh, this is private!');
}

Hyper config

Installing hyper-material-theme. Just follow these instructions.

Set Hyper to use WSL's Bash by default

  • Open up Hyper and type Ctrl + ,
  • Scroll down to "shell" in the config and change it to C:\\Windows\\System32\\bash.exe
  • Reload Hyper
@AndrewThian
AndrewThian / docker-help.md
Created October 2, 2018 07:25 — forked from bradtraversy/docker-help.md
Docker Commands, Help & Tips

Docker Commands, Help & Tips

Show commands & management commands

$ docker

Docker version info

@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();
@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 / 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 / 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 / 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;