Skip to content

Instantly share code, notes, and snippets.

View huanpc's full-sized avatar

Huan Phan huanpc

  • Singapore
View GitHub Profile
@huanpc
huanpc / docker_mysql_backup.sh
Created October 7, 2018 04:08
mysql backup by docker
# full backup and crompress
docker exec -it [mysql_container_name] mysqldump -u[user] -p[password] --all-databases --add-drop-database --add-drop-table | gzip > /mysql_backup/db_bk_$(date +%F).gz
# full mysql restore with dropping table before recreating
docker exec -it [mysql_container_name] mysql -u[user] -p[password] < gz -d -c /mysql_backup/db_bk_$(date +%F).gz
#!/usr/bin/python
edges = [[4, 6], [3, 4], [2, 3], [3, 5], [1, 2], [1, 3], [5, 6], [7, 2]]
result = []
edge_map = {}
start_nodes = []
# find start nodes
for edge in edges:
if edge[0] not in start_nodes:
# add to start_nodes
start_nodes.append(edge[0])
@huanpc
huanpc / dependency_node_traversal.py
Last active April 13, 2019 11:56
A kind of dependency graph traversal with ordering
#!/usr/bin/python
import sys
def dependency_node_traversal(edges=[]):
'''
:param edges: a list of edge, eg. [[4, 6], [3, 4], [2, 3]]
'''
if len(edges) == 0:
print("Your input graph is empty")
return
class Solution:
def longestIncreasingPath(self, matrix: List[List[int]]) -> int:
'''
return the length of longest increasing path and its path node
'''
if len(matrix) == 0: return 0
self.memo = [[-1 ] *len(matrix[0]) for j in range(len(matrix))]
self.path_memo = [[None] *len(matrix[0]) for j in range(len(matrix))]
max_path = 0
@huanpc
huanpc / consistent_hashing_implementation.py
Created April 26, 2019 03:51
Consistent hashing simple implementation
#
@huanpc
huanpc / update-golang.md
Created September 25, 2020 03:05 — forked from nikhita/update-golang.md
How to update the Go version

How to update the Go version

System: Debian/Ubuntu/Fedora. Might work for others as well.

1. Uninstall the exisiting version

As mentioned here, to update a go version you will first need to uninstall the original version.

To uninstall, delete the /usr/local/go directory by: