Skip to content

Instantly share code, notes, and snippets.

View scientificRat's full-sized avatar
😝
Working

Zhengyue Huang scientificRat

😝
Working
  • Tsinghua University
View GitHub Profile
@scientificRat
scientificRat / make_time_lapse.py
Created July 15, 2022 12:23
make time lapse from images
import os
import glob
import moviepy.editor as mpe
IMAGE_ROOT = '/Users/huangzhengyue/work_data/jiaolou3'
OUT_FILE_NAME = 'test3.mp4'
FPS = 12
def main():
@scientificRat
scientificRat / duplicate_image_finder.py
Created November 16, 2021 12:18
find duplicate images in a folder
import os
import sys
import glob
import tqdm
import json
import shutil
import pickle
import argparse
import numpy as np
from PIL import Image
@scientificRat
scientificRat / keymap.py
Last active October 28, 2024 01:22
Use raspberry pi as Bluetooth HID mouse/keyboard emulator
#
# Taken from https://www.gadgetdaily.xyz/create-a-cool-sliding-and-scrollable-mobile-menu/
#
# Convert value returned from Linux event device ("evdev") to a HID code. This
# is reverse of what's actually hardcoded in the kernel.
#
# Lubomir Rintel <[email protected]>
# License: GPL
#
# Ported to a Python module by Liam Fraser.
@scientificRat
scientificRat / png_tight_cut.py
Last active June 19, 2020 07:17
png tight cut, cut the png background
import cv2
import os
import sys
import numpy as np
def tight_cut(path):
path = os.path.abspath(path)
file_name = os.path.basename(path)
dir_name = os.path.dirname(path)
@scientificRat
scientificRat / THU_Tsinghua_conn_tool.py
Created October 17, 2018 11:12
清华大学校园网命令行登陆/退出脚本
import requests
import argparse
import hashlib
def login(username, password):
password = '{MD5_HEX}' + hashlib.md5(password.encode('utf-8')).hexdigest()
r = requests.post('http://net.tsinghua.edu.cn/do_login.php',
data={'action': 'login', 'username': username, 'password': password, 'ac_id': 1})
print(r.text)
@scientificRat
scientificRat / print_table_console.py
Created August 14, 2018 03:37
print table to console
def print_table(head, body, padding_left=1, padding_right=2):
# calc column lens
head = list(head)
col_lens = [len(c) + padding_left + padding_right for c in head]
for i in range(len(body)):
body[i] = list(body[i])
row = body[i]
if len(row) > len(head):
head.append('')
col_lens.append(0)
@scientificRat
scientificRat / nat_traversal_local.py
Last active July 9, 2018 04:28
Nat traversal (text communication)
import socket as sc
import argparse
import os, sys
class NatTraversalTool(object):
def __init__(self, server_address, local_name, remote_name):
self.server_address = server_address
self.local_name = local_name
self.remote_name = remote_name
@akey7
akey7 / numpy_array_to_speakers.py
Created March 31, 2018 06:13
How to play a NumPy array with audio directly to a speaker.
# Use the sounddevice module
# http://python-sounddevice.readthedocs.io/en/0.3.10/
import numpy as np
import sounddevice as sd
import time
# Samples per second
sps = 44100