Skip to content

Instantly share code, notes, and snippets.

View HKAB's full-sized avatar
🌎
imagining

Nguyễn Phú Trường HKAB

🌎
imagining
View GitHub Profile
@HKAB
HKAB / sudoku_with_constraint.py
Last active August 2, 2024 08:48
Sudoku solver using ortools with two special constraints
sum_10_condition = (
((2, 1), (3, 1)),
((5, 0), (5, 1)),
((7, 0), (7, 1)),
((5, 2), (6, 2)),
((2, 2), (2, 3)),
((1, 3), (2, 3)),
((4, 3), (4, 4)),
((5, 3), (6, 3)),
((7, 2), (7, 3)),
@HKAB
HKAB / kaldi_snipset.py
Created February 25, 2023 03:42
Some Kaldi python snipsets so I don't have to retype again
# Check per_utt
with open('per_utt', 'r') as f:
lines = f.read().splitlines()
for i in range(0, len(lines), 4):
ref, hyp, _, _ = lines[i:i+4]
id = ref.split()[0]
ref = ' '.join(ref.split(" ", 1)[1].split())
hyp = ' '.join(hyp.split(" ", 1)[1].split())
@HKAB
HKAB / anki_to_json.py
Created November 30, 2022 03:27
Script to export data from Anki database in order to input cal-Heatmap for my blog
from ankipandas import Collection
import pandas as pd
import json
col = Collection("/mnt/c/Users/khoah/AppData/Roaming/Anki2", user="User 1")
col.revs['date'] = col.revs.index
col.revs['seconds'] = (col.revs.index.values/1000).astype(int)
col.revs['times'] = 1
my_dict = dict()
for s, t in zip(col.revs['seconds'].values, col.revs['times'].values):
@HKAB
HKAB / vigenere_cbc_mac.py
Created October 10, 2021 03:41
Vigenere cipher + CBC-MAC-like Hashing
def encrypt(plaintext, key):
key_length = len(key)
key_as_int = [ord(i) - ord('a') for i in key]
plaintext_int = [ord(i) - ord('a') for i in plaintext]
ciphertext = ''
for i in range(len(plaintext_int)):
value = (plaintext_int[i] + key_as_int[i % key_length]) % 26
ciphertext += chr(value + ord('a'))
return ciphertext
def decrypt(ciphertext, key):
@HKAB
HKAB / rc4.py
Last active September 27, 2021 15:55
RC4 Cipher Algorithm
N = 10
S = [0]*256
T = [0]*256
K = [10, 20, 25, 15, 40, 60, 30, 70, 75, 90]
P = [1, 2, 2, 2]
C = []
for i in range(0, 256):
S[i] = i
T[i] = K[i % N]
@HKAB
HKAB / a51.py
Last active September 27, 2021 15:55
A5/1 Cipher Algorithm
p = '111000'
# 19b, 21b, 22b
k = '1100110110101101011011001010110001101110011100010011100011101111'#1100110110101101011. 0110010101100011011100.11100010011100011101111
x = k[:19]
y = k[19:41]
z = k[41:]
s = ''
# print(x, y, z)
@HKAB
HKAB / hill_cypher.py
Last active September 27, 2021 15:56
Hill Cipher Algorithm with GUI
import numpy as np
import sys
import PySimpleGUI as sg
# Tutorial: https://www.jigsawacademy.com/blogs/cyber-security/hill-cipher/
def matrix_cofactor(matrix):
return np.linalg.inv(matrix).T * np.linalg.det(matrix)
def egcd(a, b):
@HKAB
HKAB / xss.js
Created September 10, 2021 14:34
<script>alert("it's me!")</script>
@HKAB
HKAB / banker.py
Last active September 28, 2021 04:27
Banker algorithm in OS
import numpy as np
Allocation = np.array([ [0, 1, 0],
[2, 0, 0],
[3, 0, 2],
[2, 1, 1],
[0, 0, 2]]
)
Max = np.array([[7, 5, 3],
[3, 2, 2],
@HKAB
HKAB / environments.txt
Last active September 27, 2021 16:00
My conda setup so that i can use my shitty GTX 960 to train pytorch model (CUDA 11.2)
# This file may be used to create an environment using:
# $ conda create --name <env> --file <this file>
# platform: linux-64
_libgcc_mutex=0.1=main
argon2-cffi=20.1.0=pypi_0
async-generator=1.10=pypi_0
attrs=20.3.0=pypi_0
backcall=0.2.0=pyhd3eb1b0_0
bleach=3.3.0=pypi_0
ca-certificates=2021.1.19=h06a4308_0