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
#!/usr/bin/env python3 | |
import re | |
import subprocess | |
import sys | |
blank_pattern = re.compile(r"^\s*$") | |
comment_pattern = re.compile(r"^\#") | |
ansi_nonformat = "\033[0m" |
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
function __fish_no_subcommand | |
test (count (commandline -poc)) -eq 1 | |
end | |
function __fish_list_multipass_instance_names | |
multipass list --format=json | jq -r '.list[].name' | |
end | |
complete -c multipass -f |
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 re | |
import subprocess | |
import sys | |
exclude_pattern = "\.DS_Store$" | |
script_name, *args = sys.argv | |
if not args: | |
print("ussage: python3 {} <dir>".format(script_name), file=sys.stderr) |
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
def base64encode(message: bytes) -> str: | |
characters = ( | |
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz" "0123456789" "+/" | |
) | |
s = "" | |
for i in range(len(message)): | |
if i % 3 == 0: | |
s += characters[(message[i] & 0b11111100) // 0b00000100] | |
elif i % 3 == 1: | |
s += characters[ |
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 hashlib | |
import hmac | |
def hotp(C: bytes, K: bytes, Digit=6): | |
digest = hmac.digest(K, C, hashlib.sha1) | |
offset = digest[-1] & 0x0F | |
bin_code = bytearray(digest[i] for i in range(offset, offset + 4)) | |
bin_code[0] &= 0x7F | |
return int.from_bytes(bin_code, byteorder="big") % 10 ** Digit |
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
def _hmac(K: bytes, text: bytes, H: callable) -> bytes: | |
inner = H() | |
outer = H() | |
B = inner.block_size | |
ipad = 0x36 | |
opad = 0x5C | |
# if len(K) > B, hash it | |
if len(K) > B: | |
K = H(K).digest() |
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
FROM python:3.8-alpine | |
WORKDIR /app | |
COPY Pipfile* ./ | |
RUN pip3 install --no-cache-dir pipenv \ | |
&& pipenv install --system --deploy --clear |
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
def merge_sort(A, left=0, right=None): | |
def merge(A, left, mid, right): | |
n1 = mid - left | |
n2 = right - mid | |
L = [0] * n1 | |
R = [0] * n2 | |
for i in range(n1): | |
L[i] = A[left + i] | |
for i in range(n2): | |
R[i] = A[mid + i] |
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
# https://onlinejudge.u-aizu.ac.jp/courses/lesson/1/ALDS1/7/ALDS1_7_C | |
from collections.abc import Iterable | |
n = int(input()) | |
nodes = {} | |
for _ in range(n): | |
key, left, right = map(int, input().split()) | |
nodes[key] = (left, right) |
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
from datetime import datetime, date, time, timedelta | |
STATIONS = { | |
"A": ["A{}".format(i) for i in range(1, 14)], | |
"B": ["B{}".format(i) for i in range(1, 6)] + ["A7"], | |
} | |
DELTAS = { | |
frozenset(("A1", "A2")): timedelta(minutes=3), | |
frozenset(("A2", "A3")): timedelta(minutes=5), | |
frozenset(("A3", "A4")): timedelta(minutes=2), |
NewerOlder