This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const regex = /^\/\/.*|\/\*(.|\s)*?\*\//gm; | |
const str = `/** | |
asdnajsndjk | |
*/ | |
// asdaskdbjkasdasdasdbjk | |
asdasdasdasdbjhbcjahbhj | |
asdbhkbajkbkcbasdasdas | |
//asdnbakjnbjknbjkansd | |
/** | |
asdnjkanskjdbnkjbjkbdkbjkbjkabsd |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var num = (len, rng) => Math.floor(10 ** (len - 1) + rng() * 9 * 10 ** (len - 1)); | |
var test = (rng, times) => { | |
var map = {} | |
for(let i=0; i<times; i++){ | |
let rn = rng() | |
map[rn] = map[rn] ? map[rn] + 1 : 1 | |
} | |
let collisions = Object.values(map).filter(val => val > 1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import sys | |
def readlines_reverse(filename): | |
with open(filename) as qfile: | |
qfile.seek(0, os.SEEK_END) | |
position = qfile.tell() | |
line = '' | |
while position >= 0: | |
qfile.seek(position) | |
next_char = qfile.read(1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* given a sorted list and a number to search returns the right insertion index to maintain sorted order | |
* @param list {number[]} | |
* @param x {number} | |
*/ | |
const bisectRight = (list, x) => { | |
if(list.length === 0) { | |
return 0 | |
} | |
let first = 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Docker useful commands: | |
# Build docker container with tag name using Docker (Dockerfile should be in current dir) | |
docker build -t <choose_image_name> | |
# Start container with required commands, (one’s specified in CMD tag in Dockerfile) | |
docker run <image_name> | |
# Start container with shell of choice | |
docker run -it o4s-transactions sh |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* strict typing extends to browser API which enables error free code at compile time.*/ | |
// this won't work because querySelector returns type Element | |
let roomNameEl:HTMLElement = el.querySelector('.room-name') | |
// this solves the problem | |
let roomNameEl:Element = el.querySelector('.room-name') | |
// this will not work cause Element doesn't have value attr | |
let roomNameEl:Element = el.querySelector('.room-name') | |
roomNameEl.value // error no such attr | |
// this will work, also notice typecasting is possible |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vm.unloadWatcher = $scope.$on('$locationChangeStart', function(event, next, current) { | |
if(!confirm("Are you sure you want to leave this page?")) { | |
event.preventDefault(); | |
} | |
}); | |
$scope.$on('$destroy', function(){ | |
vm.unloadWatcher(); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// source: http://stackoverflow.com/a/27545357/2317794 | |
var str = "1238127397812378" | |
str = str.replace(/\d(?=\d{4})/g, "*"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
prefixes = ["", "&c", "'d", "'em", "'ll", "'m", "'mid", "'mon", "'pre", "'re", "'s", "'sbl", "'sbo", "'sde", "'sfo", "'she", "'shu", "'sli", "'sna", "'str", "'t", "'til", "'tis", "'twa", "'twe", "'twi", "'two", "'un", "'ve", "1080", "10th", "1st", "2", "2nd", "3rd", "4th", "5th", "6th", "7th", "8th", "9th", "a", "a'", "a's", "a/c", "a1", "aa", "aaa", "aah", "aahe", "aahi", "aahs", "aal", "aali", "aals", "aam", "aard", "aarg", "aaro", "aarr", "aas", "aasv", "ab", "aba", "abac", "abad", "abaf", "abai", "abak", "abal", "abam", "aban", "abap", "abar", "abas", "abat", "abau", "abav", "abax", "abay", "abaz", "abb", "abba", "abbe", "abbo", "abbr", "abby", "abc", "abce", "abci", "abco", "abd", "abda", "abde", "abdi", "abdo", "abdu", "abe", "abea", "abec", "abed", "abeg", "abei", "abel", "aben", "abep", "aber", "abes", "abet", "abev", "abey", "abfa", "abhe", "abhi", "abho", "abib", "abic", "abid", "abie", "abig", "abil", "abim", "abin", "abio", "abir", "abis", "abit", "abiu", "abje", "abjo", "abju", "abka", "abl", "ab |