Skip to content

Instantly share code, notes, and snippets.

View hoanbka's full-sized avatar
💭
while I < YOU: I++

Hoan Nguyen Van hoanbka

💭
while I < YOU: I++
  • Hanoi, Vietnam
View GitHub Profile
@hoanbka
hoanbka / balancedParenthesis.py
Created October 29, 2017 10:40
check a balanced Parenthesis
# (){}[]
def isBalancedParenthesis(str):
stack = []
for i in str:
if i == '(' or i == '{' or i == '[':
stack.append(i)
elif i == ')' or i == '}' or i == ']':
@hoanbka
hoanbka / readDir.py
Created October 29, 2017 09:22
Read dir
import os
def listAllFiles(path):
files = []
try:
for i in os.listdir(path):
files.append(i)
except FileNotFoundError:
print('File not found')
@hoanbka
hoanbka / async-await-callback.js
Created October 28, 2017 18:44
async/await/callbacks
/**
* Created by Hoan Nguyen on 10/29/2017.
*/
const fsp = require('fs-promise');
(async () => {
try {
const txt = await fsp.readFile('./input.txt', 'utf8');
console.log(txt);
} catch (e) {
@hoanbka
hoanbka / promise2.js
Created October 28, 2017 17:11
promise js
/**
* Created by Hoan Nguyen on 10/28/2017.
*/
var isMomHappy = true;
// Promise
var willIGetNewPhone = new Promise(
function(resolve, reject) {
if (isMomHappy) {
var phone = {
@hoanbka
hoanbka / findMaxOccurence.js
Created October 28, 2017 10:45
Find max occurence of chars in a string
function findMaxOccurence(str) {
var map = new Map();
var max = 0;
for (var i = 0; i < str.length; i++) {
if (map.has(str.charAt(i))) {
map.set(str.charAt(i), map.get(str.charAt(i)) + 1);
} else {
map.set(str.charAt(i), 1);
@hoanbka
hoanbka / decorator3.py
Created October 26, 2017 11:42
Decorator
import time
def timing_function(some_function):
"""
Outputs the time a function takes
to execute.
"""
def wrapper():
@hoanbka
hoanbka / Queue.py
Created October 26, 2017 06:30
Implementation of a simple Queue
## Implement Queue in Python
class Queue():
def __init__(self):
self.arr = []
def push(self, item):
self.arr.insert(0, item)
def pop(self):
@hoanbka
hoanbka / stack.py
Last active October 26, 2017 06:16
Implementation of a simple STACK
class Stack():
def __init__(self):
self.arr = []
def push(self, item):
self.arr.append(item)
def pop(self):
if self.arr:
self.arr.pop()
def isTangle(a, b, c):
if a <= 0 or b <= 0 or c <= 0:
return False
else:
if a + b >= c and a + c >= b and a <= b + c:
return True
def showInfo():
count = 5
@hoanbka
hoanbka / sumOfDigits.py
Created October 24, 2017 19:42
sum of digits in a string
def sumOfDigits(str):
temp = ''
sum = 0
for i in range(len(str)):
if str[i].isdigit():
temp += str[i]
else:
if temp.isdigit():
sum += int(temp)