Skip to content

Instantly share code, notes, and snippets.

View whiledoing's full-sized avatar

whiledoing whiledoing

View GitHub Profile
@whiledoing
whiledoing / dijkstra.py
Last active December 28, 2019 11:10 — forked from kachayev/dijkstra.py
[python-dijkstra] Dijkstra shortest path algorithm based on python heapq heap implementation #python #algorithm
from collections import defaultdict
from heapq import *
def dijkstra(edges, f, t):
g = defaultdict(list)
for l,r,c in edges:
g[l].append((c,r))
# dist records the min value of each node in heap.
q, seen, dist = [(0,f,())], set(), {f: 0}
@whiledoing
whiledoing / mac-brew-link-python-workable
Last active December 28, 2019 11:09
[mac operation] mac operation backup #mac #osx
@whiledoing
whiledoing / markdown-table-example.md
Last active October 7, 2023 09:34
[markdown-example] markdown example demo #markdown
Left-Aligned Center Aligned Right Aligned
col 3 is some wordy text $1600
col 2 is centered $12
zebra stripes are neat $1
@whiledoing
whiledoing / repeated-timer-example.py
Last active April 15, 2018 15:12
[python-repeated-timer] repeated timer impl with threading.Timer #python
from threading import _Timer
class RepeatedTimer(_Timer):
"""
See: https://hg.python.org/cpython/file/2.7/Lib/threading.py#l1079
"""
def run(self):
while not self.finished.is_set():
self.finished.wait(self.interval)
self.function(*self.args, **self.kwargs)
@whiledoing
whiledoing / cVimrc
Last active May 1, 2024 20:52
[chrome-extension-cVimrc] #chrome
set nohud
map h J
map l K
map c x
map C X
set cncpcompletion
let barposition = "bottom"
set typelinkhints
set noautofocus
@whiledoing
whiledoing / using-class.py
Last active June 29, 2017 19:46
[python-context-manager] using class and context manager method to implement python context manager #python
class Context(object):
def __init__(self, name):
self.file = open(name)
def __enter__(self):
return self.file
def __exit__(self, ctx_type, ctx_value, ctx_traceback):
self.file.close()