Skip to content

Instantly share code, notes, and snippets.

View martin-mok's full-sized avatar

Martin martin-mok

  • /dev/null
View GitHub Profile
@martin-mok
martin-mok / workspace-clean
Created September 24, 2020 16:09 — forked from beenotung/workspace-clean
to free up disk space by deleting downloaded packages
#!/usr/bin/env node
let fs = require('fs');
let path = require('path');
let util = require('util');
let target = {
files: [
'workspace.xml',
],
dirs: [
@martin-mok
martin-mok / recursive-promise.ts
Created August 31, 2020 14:37 — forked from jguix/recursive-promise.ts
How to create a recursive promise chain. Source http://jsbin.com/qotabib/edit?js,console
// A recursive function returning Promise<number>
function recurseToZero(n) {
console.log('B. Entering recursive function for [' + n + '].');
// Once we hit zero, bail out of the recursion. The key to recursion is that
// it stops at some point, and the callstack can be "rolled" back up.
if (n === 0) {
// We could just return 0 but we do return Promise.resolve to have a consistent return type
return Promise.resolve(0);
}
// Start a NEW PROMISE CHAIN that will become the continuation of the parent
@martin-mok
martin-mok / .bash_aliases
Created August 29, 2020 03:24 — forked from vratiu/.bash_aliases
Git shell coloring
# Customize BASH PS1 prompt to show current GIT repository and branch.
# by Mike Stewart - http://MediaDoneRight.com
# SETUP CONSTANTS
# Bunch-o-predefined colors. Makes reading code easier than escape sequences.
# I don't remember where I found this. o_O
# Reset
Color_Off="\[\033[0m\]" # Text Reset
@martin-mok
martin-mok / snail-sort.md
Last active June 16, 2020 14:42
Snail Sort from codewars

My soln:

snail = function(array) {
    if(array.length===0) return [];
    let rowMin=0;
    let rowMax=array.length-1;
    let colMin=0;
    let colMax=array[0].length?array[0].length-1:0;
    let snailArr=[];
    while(rowMax>=rowMin ||colMax>=colMin ){
@martin-mok
martin-mok / c++_cheat-sheet.md
Created June 9, 2020 18:56 — forked from rubienr/c++_cheat-sheet.md
C++ Cheat Sheet

1. Clone your fork:

git clone [email protected]:YOUR-USERNAME/YOUR-FORKED-REPO.git

2. Add remote from original repository in your forked repository:

cd into/cloned/fork-repo
git remote add upstream git://github.com/ORIGINAL-DEV-USERNAME/REPO-YOU-FORKED-FROM.git
git fetch upstream
@martin-mok
martin-mok / CashRegister.js
Last active May 16, 2020 12:36
FreeCodeCamp: Cash Register
function checkCashRegister(price, cash, cid) {
function floatPrecisionCorrection(x){
return Math.round(x*100)/100;
}
let result={status:null,change:[]};
let changeTotal=floatPrecisionCorrection(cash-price);
let cidTotal=floatPrecisionCorrection(cid.reduce((a,e)=>a+e[1],0));
@martin-mok
martin-mok / word_count.js
Created February 27, 2020 23:45 — forked from jinmayamashita/word_count.js
word_count
const englishString =
"The administration will encourage federal data and universities to share data that can drive the administration of automated systems data";
const toSplitBySeparator = (splitTarget, separator) =>
splitTarget.toLowerCase().split(separator);
const countWord = stringArray => {
let word = "";
let count = 0;
const processingEndWords = [];
@martin-mok
martin-mok / CaesarsCipher.md
Last active July 5, 2023 16:56
freecodecamp: Caesars Cipher

Description

One of the simplest and most widely known ciphers is a Caesar cipher, also known as a shift cipher. In a shift cipher the meanings of the letters are shifted by some set amount. A common modern use is the ROT13 cipher, where the values of the letters are shifted by 13 places. Thus 'A' ↔ 'N', 'B' ↔ 'O' and so on. Write a function which takes a ROT13 encoded string as input and returns a decoded string. All letters will be uppercase. Do not transform any non-alphabetic character (i.e. spaces, punctuation), but do pass them on.

Tests