Skip to content

Instantly share code, notes, and snippets.

View zmwangx's full-sized avatar
🐍
Pythonista learning new technologies

Zhiming Wang zmwangx

🐍
Pythonista learning new technologies
View GitHub Profile
@zmwangx
zmwangx / self-hosted-gitlab-manually-confirm-user-email.md
Created June 7, 2024 12:50
Manually confirm user email with `gitlab-rails console`
  • Run gitlab-rails console;

  • Find the user:

    user = User.User.find_by_username('username')
  • Look at the list of emails and find the one you want to confirm:

@zmwangx
zmwangx / caddy-acl.md
Created October 13, 2023 02:29
Granting caddy (official Debian package) access to existing certificates in /etc/letsencrypt/live

Caddy can be instructed to load existing certificates:

example.com {
	reverse_proxy :32767
	tls /etc/letsencrypt/live/example.com/fullchain.pem /etc/letsencrypt/live/example.com/privkey.pem
}

However, caddy.service uses user caddy and group caddy:

When a file is being copied in on macOS, the com.apple.FinderInfo xattr is set to the 32-byte value

627a7920 00000000 00000000 00000000 00000000 00000000 00000000 00000000

which would show up as bzy with xattr -p com.apple.FinderInfo /path/to/file. (This may only be true when there are no additional attributes likes flags.) This can be used to test whether a file copy has completed.

Conversely, one can also use

xattr -wx com.apple.FinderInfo '627a7920 00000000 00000000 00000000 00000000 00000000 00000000 00000000' /path/to/file
@zmwangx
zmwangx / APFS volume without Time Machine local snapshots.md
Created April 11, 2023 07:03
How to make ~/Downloads (or any other directory) a separate APFS volume without Time Machine local snapshots

Tested on macOS 13.3.1.

  • In Disk Utility, create new APFS volume under internal SSD's Container disk1.

  • Unmount the volume.

  • ⌘I to open the Info panel of the volume, copy the Volume UUID. Alternatively, the UUID can be copied from the output of diskutil info disk1s7, where disk1s7 should be replaced with the corresponding device node.

  • sudo vifs to edit /etc/fstab, adding the following entry:

@zmwangx
zmwangx / youtube-i18nlanguages.txt
Created November 5, 2022 05:13
YouTube I18nLanguages
af Afrikaans
am Amharic
ar Arabic
as Assamese
az Azerbaijani
be Belarusian
bg Bulgarian
bn Bangla
bs Bosnian
ca Catalan
@zmwangx
zmwangx / clf.go
Created December 29, 2020 09:44
Golang echo framework logging with (extended) common log format like nginx/Apache.
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}`
From 41987f1697992b48da13bbebc5e0c42036ea5dc5 Mon Sep 17 00:00:00 2001
From: Zhiming Wang <[email protected]>
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;
From 06e70e23f8086bb68d98893bbaeaa9df3639ef89 Mon Sep 17 00:00:00 2001
From: Zhiming Wang <[email protected]>
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
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 March 16, 2020 13:19
AES-CTR encryption & decryption in JavaScript & Python (use this for obfuscation, think thrice about using this for security)
<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(