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 / pil_s3.py
Created December 3, 2020 09:04 — forked from ghandic/pil_s3.py
Load image from S3 directly into memory as PIL image and write to S3 directly from memory from PIL image
import boto3
from PIL import Image
from io import BytesIO
import os
class S3ImagesInvalidExtension(Exception):
pass
class S3ImagesUploadFailed(Exception):
pass
@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 git@github.com: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 = [];