Skip to content

Instantly share code, notes, and snippets.

Avatar
🐍
Pythonista learning new technologies

Zhiming Wang zmwangx

🐍
Pythonista learning new technologies
View GitHub Profile
@zmwangx
zmwangx / clf.go
Created Dec 29, 2020
Golang echo framework logging with (extended) common log format like nginx/Apache.
View clf.go
import (
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
)
func Serve() {
e := echo.New()
// Common Log Format
logFormat := `${remote_ip} - - [${time_custom}] "${method} ${path} ${protocol}" ${status} ${bytes_out}`
View 0001-Improve-crypto.patch
From 41987f1697992b48da13bbebc5e0c42036ea5dc5 Mon Sep 17 00:00:00 2001
From: Zhiming Wang <i@zhimingwang.org>
Date: Mon, 23 Nov 2020 01:01:19 +0800
Subject: [PATCH] Improve crypto
The less hand-rolled stuff the better.
- Switch from hand-rolled crappy KDF to PBKDF2;
- Switch from AES-CBC with hand-rolled padding and authentication to
Fernet;
View 0001-Add-experimental-support-for-Top-stories.patch
From 06e70e23f8086bb68d98893bbaeaa9df3639ef89 Mon Sep 17 00:00:00 2001
From: Zhiming Wang <i@zhimingwang.org>
Date: Sun, 11 Oct 2020 23:19:12 +0800
Subject: [PATCH] Add experimental support for "Top stories"
---
googler | 29 +++++++++++++++++++++++++++++
1 file changed, 29 insertions(+)
diff --git a/googler b/googler
View fps-filter.rs
extern crate ffmpeg_next as ffmpeg;
use ffmpeg::*;
use std::env;
const DEFAULT_INPUT: &str = "input.gif";
const DEFAULT_OUTPUT: &str = "output.gif";
const DEFAULT_TARGET_FPS: f64 = 25.0;
fn main() {
@zmwangx
zmwangx / aesctr.js
Created Mar 16, 2020
AES-CTR encryption & decryption in JavaScript & Python (use this for obfuscation, think thrice about using this for security)
View aesctr.js
<body>
<script>
const base64ToUInt8Array = b64 =>
Uint8Array.from(window.atob(b64), c => c.charCodeAt(0));
const textToUInt8Array = s => new TextEncoder().encode(s);
const UInt8ArrayToString = u8 => String.fromCharCode.apply(null, u8);
const UInt8ArrayToBase64 = u8 => window.btoa(UInt8ArrayToString(u8));
(async () => {
const key = await window.crypto.subtle.importKey(
@zmwangx
zmwangx / stripNonBMPCharacters.m
Created Dec 29, 2019
Strip non-BMP characters from string in Mathematica <12.
View stripNonBMPCharacters.m
surrogateQ[ch_] := # >= 55296 && # < 57344 &@First@ToCharacterCode[ch];
surrogateQ::usage =
"Tests whether the given character is a surrogate, i.e., in the \
range U+D800 to U+DFFF.";
stripNonBMPCharacters[s_] :=
StringJoin[Select[Characters[s], ! surrogateQ[#] &]];
stripNonBMPCharacters::usage =
"Strips the given string of Unicode code points outside of the \
Basic Multilingual Plane (BMP), i.e., characters beyond U+FFFF, by \
@zmwangx
zmwangx / getgoogler.py
Created Nov 15, 2019
googler installation script (working copy)
View getgoogler.py
#!/usr/bin/env python3
import builtins
import collections
import hashlib
import os
import pathlib
import shutil
import subprocess
import sys
View _m.weibo.cn.md
@zmwangx
zmwangx / read_keypress_with_timeout.py
Last active Dec 29, 2018
Python: cross-platform code to read keypress with a timeout. Good for "press any key to continue" with an expiration timer.
View read_keypress_with_timeout.py
import os
import time
from typing import Optional
if os.name == "posix":
import select
import sys
import termios
import tty
@zmwangx
zmwangx / urlgrep
Created Dec 27, 2018
Python script to extract URLs from HTML documents.
View urlgrep
#!/usr/bin/env python3
"""Extract URLs from HTML documents."""
import argparse
import re
import sys
import urllib.parse
import bs4