Skip to content

Instantly share code, notes, and snippets.

View scturtle's full-sized avatar
🐢

scturtle

🐢
View GitHub Profile
@scturtle
scturtle / server.py
Last active May 13, 2023 23:56
python socks5 proxy server with asyncio (async/await)
#!/usr/bin/env python3.5
import socket
import asyncio
from struct import pack, unpack
class Client(asyncio.Protocol):
def connection_made(self, transport):
self.transport = transport
self.server_transport = None
@scturtle
scturtle / dig_torch_mlir.py
Last active May 12, 2023 09:42
dig into torch-mlir
import torch
from torch import nn
# import torch_mlir
from torch_mlir.passmanager import PassManager
from torch_mlir.dialects.torch.importer.jit_ir import ClassAnnotator, ModuleBuilder
torch.manual_seed(42)
@scturtle
scturtle / im2col.py
Last active May 6, 2023 07:28
conv2d forward and backward implementation
import torch
from torch import nn
import numpy as np
# https://github.com/arasdar/DL/blob/master/uri-dl/uri-dl-hw-2/assignment2/cs231n/layers.py
# https://github.com/brandontrabucco/conv-python/blob/master/main.py
def get_output_shape(x, kernel, stride):
(_, _, ih, iw), (kh, kw) = x.shape, kernel
oh = (ih - kh) // stride + 1
#include <algorithm>
#include <cassert>
#include <random>
#include <vector>
constexpr unsigned int bit_floor(unsigned int num) {
return num == 0 ? 0 : 1 << (31 - __builtin_clz(num));
}
template <typename It, typename T, typename Cmp>
@scturtle
scturtle / polling.py
Created June 25, 2015 12:28
telegram bot (long polling)
#!/usr/bin/env python3
import requests
prefix = 'https://api.telegram.org/bot'
key = ''
geturl = prefix + key + '/getUpdates'
sendurl = prefix + key + '/sendMessage'
timeout = 60
@scturtle
scturtle / ast_dump.py
Created December 16, 2017 15:59
Dump Clang AST with python bindings.
#!/usr/bin/env python3
import sys
import clang.cindex
INDENT = 4
K = clang.cindex.CursorKind
def is_std_ns(node):
return node.kind == K.NAMESPACE and node.spelling == 'std'
@scturtle
scturtle / addlrc.py
Last active March 4, 2023 10:10
download from music.163.com
import eyed3
import re
import glob
def get_lyric(lrc):
text = open(lrc).read()
text = re.sub(r'(?:\[.*\])+', '', text).strip()
text = map(lambda l: l.strip(), text.split('\n'))
ans = []
for l in text:
@scturtle
scturtle / icp.py
Created March 31, 2017 12:57
Least-Squares Fitting of Two 3-D Point Sets
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from transforms3d import euler
fig = plt.figure()
ax = fig.gca(projection='3d')
p1 = np.zeros((3, 100))
p1[0, :] = np.linspace(1, 3, 100)
@scturtle
scturtle / arguments.cc
Created October 30, 2022 14:15
c++ argparser (adapted from Corrade)
#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <optional>
#include <iomanip>
enum class Type {
PositionalArgument,
@scturtle
scturtle / ocr.py
Created August 27, 2014 03:06
OCR with CV
import cv2
import cv2.cv as cv
import tesseract
def show(im):
msg = 'press any key to continue'
cv2.namedWindow(msg, cv2.WINDOW_NORMAL)
cv2.imshow(msg, im)
cv2.waitKey(0)
cv2.destroyAllWindows()