Skip to content

Instantly share code, notes, and snippets.

View howardlau1999's full-sized avatar
🎯
Focusing

Howard Lau howardlau1999

🎯
Focusing
View GitHub Profile
@howardlau1999
howardlau1999 / decipher_ct_xml.py
Created January 19, 2023 18:10
Decipher China Telecom router user cfg
# pip install cryptodome
from Crypto.Cipher import AES
from binascii import a2b_hex
KEY = b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
def decrypt(text):
cryptor = AES.new(KEY, AES.MODE_ECB)
plain_text = cryptor.decrypt(a2b_hex(text))
return plain_text
cfg_file = open("db_user_cfg.xml", "rb")
dec_file = open("db_user_cfg.decode.xml", "w")
#!/usr/bin/env bash
# --slave /usr/bin/$1 $1 /usr/bin/$1-\${version} \\
function register_clang_version {
local version=$1
local priority=$2
update-alternatives \
--install /usr/bin/llvm-config llvm-config /usr/bin/llvm-config-${version} ${priority} \
@howardlau1999
howardlau1999 / st.cpp
Created August 31, 2021 07:57
Segment Tree
#include <iostream>
#include <vector>
using namespace std;
class SegmentTreeNode {
public:
int sum = 0;
int delta = 0;
};
@howardlau1999
howardlau1999 / bench.cpp
Created August 13, 2021 15:12
benchmark reading lots of float numbers
#include <benchmark/benchmark.h>
#include <charconv>
#include <fcntl.h>
#include <fstream>
#include <iostream>
#include <cstdlib>
#include <sys/file.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/types.h>
@howardlau1999
howardlau1999 / ycomb.cpp
Created August 11, 2021 09:30
Y Combinator in C++20
#include <iostream>
int main() {
auto result = [](auto&& g) {
return [](auto&& f) {
return f(f);
}([&g](auto&& f) { return g([&f](auto&& x) { return f(f)(x); }); });
}([](auto&& f) {
return [&f](auto&& x) -> int { return x == 0 ? 1 : x * f(x - 1); };
})(5);
@howardlau1999
howardlau1999 / raytrace.rs
Last active March 11, 2020 13:07
Ray Tracing
use std::env;
use std::fs::File;
use std::io::prelude::*;
use std::io::BufWriter;
use std::ops::Add;
use std::ops::Div;
use std::ops::Mul;
use std::ops::Neg;
use std::ops::Sub;
@howardlau1999
howardlau1999 / HeapSort.java
Created December 26, 2018 07:22
Sort animation
import edu.princeton.cs.algs4.*;
public class HeapSort {
private static int currentSinking;
public static void sink(int[] heap, int k, int N) {
while (2 * k <= N) {
int j = 2 * k;
if (j < N && heap[j] < heap[j + 1]) j++;
if (heap[k] > heap[j]) break;// already ordered
exch(heap, k, j);
@howardlau1999
howardlau1999 / main.cpp
Created December 18, 2018 06:42
Linux dlfcn
// g++ -rdynamic -o main main.c -ldl
#include <dlfcn.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <iostream>
using namespace std;
typedef int (*calc_func)(int, int);
const char *LIB_PATH = "./libctest.so";
#include <iostream>
using namespace std;
template <class K, class V>
struct AVLNode {
K key;
V value;
AVLNode *left, *right;
AVLNode(K key, V value) : key(key), value(value), left(NULL), right(NULL) {}
@howardlau1999
howardlau1999 / calculator.cpp
Created December 5, 2018 05:21
Simple Calculator
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cctype>
#include <stdexcept>
using namespace std;