Skip to content

Instantly share code, notes, and snippets.

View jtn-ms's full-sized avatar
🏘️
working from home

Brian G. jtn-ms

🏘️
working from home
  • remote
View GitHub Profile
@jtn-ms
jtn-ms / Stupid Mistakes.md
Created July 16, 2022 09:43
Tips: Live Coding

1. confitional mistakes

  • !== instead of ===, or vice versa

2. type confusion

  • result instead of results
@jtn-ms
jtn-ms / genRandNum.go
Created July 16, 2022 05:39
Golang: Generate Random Number using net/http, math/rand
package main
import (
"encoding/json"
"math/rand"
"net/http"
"strconv"
)
func main() {
axios.get(url)
  .then(res => res.data)
  .then(data => JSON.stringify(data)
  .catch(err => console.log(err))

fetch(url)
  .then(res => res.json())
  .then(({ results }) => results.map(result => console.log(result))
 .catch(err => console.log(err));
@jtn-ms
jtn-ms / unitest.js
Created June 26, 2022 13:55
unitest template for javascript
let sum = (a,b,c) => a+b+c
const tcs = [
[1,
2,
3,
6],
["1",
"2",
@jtn-ms
jtn-ms / unitest.py
Created June 26, 2022 13:35
unitest template for python
sum = lambda a, b, c : a + b + c
tcs = [
[1,
2,
3,
6],
["1",
"2",
@jtn-ms
jtn-ms / combinations.py
Created June 26, 2022 13:27
acceleration of factorial, power, combination, permutation - K!, k^n, n! /(n-k)!*k!, n! /(n-k)!
import math
MODULO = 10**9 + 7
N =200
P = [1 for i in range(N)]
# k**i
def genPowerMatrix(k,N):
for i in range(1,N):
P[i] = 9 * P[i-1] % MODULO
@jtn-ms
jtn-ms / combinations.js
Last active June 26, 2022 12:59
acceleration of factorial, power, combination, permutation - K!, k^n, n! /(n-k)!*k!, n! /(n-k)!
// int32, float32 len(str(2**32)) = 10
// int64, float64 len(str(2**64)) = 20
const MODULO = Math.pow(10, 9) + 7;
const N =200;
var P = [].fill.call({ length: N }, 1);// Powers - k^n, k to the power of n
var F = [].fill.call({ length: N }, 1);// Factorials - k!
var C = new Array(N); // Combinations - C(n,k)=n! /(n-k)!*k!
var Pm = [].fill.call({ length: N }, 1);// Permuation
@jtn-ms
jtn-ms / isBalanced.py
Created June 24, 2022 19:45
hackerrank - balanced brackets
def isPaired(a,b):
if (a == "{" and b =="}") or\
(a == "(" and b ==")") or \
(a == "[" and b =="]"):
return True
return False
def isBalanced(s):
# Write your code here
@jtn-ms
jtn-ms / cutTheTree.py
Created June 24, 2022 12:26
hackerrank solution - cut the tree
#!/bin/python3
import math
import os
import random
import re
import sys
#
@jtn-ms
jtn-ms / bfs.py
Created June 24, 2022 12:08
hackerrank solution - breadth first search
#!/bin/python3
import math
import os
import random
import re
import sys