Skip to content

Instantly share code, notes, and snippets.

View riaqn's full-sized avatar

Zesen Qian riaqn

View GitHub Profile
@riaqn
riaqn / thumbnail_extraction.py
Last active July 17, 2021 06:25
Extract thumbnails from a image of video thumbnails grid
#TODO: test each square if it's actually a screen shot
import numpy as np
#from scipy.ndimage import gaussian_filter
from scipy.signal import convolve2d
from PIL import Image, ImageDraw
import matplotlib.pyplot as plt
import cv2
import logging
log = logging.getLogger(__name__)
@riaqn
riaqn / tproxy.py
Created February 25, 2021 16:06
A async python transparent proxy server (based on iptables TPROXY, asyncio, aiosock)
import asyncio
from asyncio.streams import start_server
import socket
import aiosocks
import logging
logging.basicConfig(level = logging.WARNING)
log = logging.getLogger(__name__)
@riaqn
riaqn / fanctl.py
Last active November 7, 2020 15:32
fan control script for AMD GPU in linux
#!/bin/env python3
import time
import os
import math
os.chdir('/sys/class/drm/card0/device/hwmon/hwmon2/')
temp = 'temp1'
fan = 'fan1'
@riaqn
riaqn / cardboard.js
Created January 11, 2019 02:42
cardboard profile generation
"use strict";
var ProtoBuf = require("protobufjs")
// to and from URL-safe variant of base64 encoding
function base64ToUrl(s) {
return s.replace(/\+/g, '-').replace(/\//g, '_').replace(/\=+$/, '');
}
function base64FromUrl(s) {
@riaqn
riaqn / economist.py
Created November 9, 2015 00:12
a simple python script to push articles from The Economist to Pocket
#!/bin/env python3
from pocket import Pocket
consumer_key = "123-2343-4234-32-4-3-4"
'''
redirect_uri = "http://example.com/"
request_token = Pocket.get_request_token(consumer_key=consumer_key, redirect_uri=redirect_uri)
# URL to redirect user to, to authorize your app
auth_url = Pocket.get_auth_url(code=request_token, redirect_uri=redirect_uri)
input(auth_url)
@riaqn
riaqn / ResultSetAdapter.java
Created April 3, 2015 13:20
a Gson adapter to convert ResultSet to Json(writer only)
import java.io.*;
import java.sql.*;
import com.google.gson.*;
import com.google.gson.stream.*;
public class ResultSetAdapter extends TypeAdapter<ResultSet> {
public static class NotImplemented extends RuntimeException {}
private static final Gson gson = new Gson();
public ResultSet read(JsonReader reader)
throws IOException {
@riaqn
riaqn / china.awk
Created March 6, 2015 15:19
AWK script to atomically update IPSet based on ripe.net datebase
#!/usr/bin/awk -f
BEGIN {
FS="|";
print "create china_new hash:net" | "ipset restore"
}
$2 == "CN" && $3 == "ipv4" {
prefix=32;
while ($5 > 1) {
--prefix;
$5 = $5/2;
@riaqn
riaqn / gist:bc8c74133edc4128b937
Last active August 29, 2015 14:10
Transform OpenVZ guest into Gentoo
#!/bin/sh
set -e
IFACE=venet0
IFCONFIG="
127.0.0.2/32
192.157.208.187/32
2605:f700:40:400::c248:30c1/128
2605:f700:40:400::b363:5edb/128
2605:f700:40:400::340f:4e34/128