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 / Postfix: sender-dependent SASL authentication.md
Last active May 10, 2024 14:18
Postfix: sender-dependent SASL authentication — relay to multiple SMTP hosts, or relay to the same host but authenticate as different users (e.g., two Gmail accounts)

This is a sequel to "Postfix: relay to authenticated SMTP".

I would like to send mail from two different Gmail accounts using Postfix. Here is the relevant section in the Postfix documentation: Configuring Sender-Dependent SASL authentication.

As a concrete example, here's how to set up two Gmail accounts (only relevant sections of the config files are listed below):

/etc/postfix/main.cf:
    # sender-dependent sasl authentication
    smtp_sender_dependent_authentication = yes

sender_dependent_relayhost_maps = hash:/etc/postfix/sender_relay

@zmwangx
zmwangx / Save URL to Safari reading list.scpt
Created February 2, 2014 07:44
AppleScript for saving URL to Safari reading list.
set theUrl to do shell script "pbpaste | grep -o -E \"\\b(https?|ftp|file)://[-A-z0-9+&@#/%?=~_|.;]*[A-z0-9+&@#/%=~_|]\" | head -1"
if theUrl = "" then
set html to do shell script "osascript -e '«class HTML» of (the clipboard as record)' | perl -ne 'print chr foreach unpack(\"C*\",pack(\"H*\",substr($_,11,-3)))'"
set theUrl to do shell script "echo " & quoted form of html & " | grep -o -E \"\\b(https?|ftp|file)://[-A-z0-9+&@#/%?=~_|.;]*[A-z0-9+&@#/%=~_|]\" | head -1"
end if
using terms from application "Safari"
tell application "Safari"
add reading list item theUrl as string
end tell
@zmwangx
zmwangx / markdown-latex-etc.md
Last active April 26, 2024 12:37
An incomplete guide to Markdown, LaTeX, and more, initially written for Jiawen Li.

Markdown, LaTeX, etc.

Caution

  • (10/30/2016) I am not sure when and how this gist gained quite a few stars... But as stated in the v1.13 change log (from 06/16/2015): some content may be outdated, and I am not going to fix them. Moreover, having learned much myself, I do not necessarily agree with every point made in this document from 2.5 years ago. Therefore, please take views from this document with a grain of salt, and do further research as you see fit.

  • This document was initally written for a friend of mine, Jiawen Li, so it might reflect some personal tastes here and there. For instance, some discussions are geared towards Windows, though *nix is obviously superior. For another example, when I say "you seem to love Sublime Text a lot," I'm certainly not expecting most people to love Sublime (in fact I never used it for more than three minutes in a row).

  • This document is written in Markdown. The Markdown rendering engine on GitHub Gist is somewhat limited a

@zmwangx
zmwangx / mac-keys-unicode.md
Last active April 21, 2024 20:29
Unicode characters for special keys on the Mac keyboard (not necessarily Mac specific). #symbols

⌘ – ⌘⌘ – the Command Key symbol
⌥ – ⌥⌥ – the Option Key symbol
⇧ – ⇧⇧ – the Shift Key symbol
⌃ – ⌃⌃ – the Control Key symbol
⎋ – ⎋⎋ – the ESC Key symbol
⇪ – ⇪⇪ – the Capslock symbol
⏎ – ⏎⏎ – the Return symbol
⌫ – ⌫⌫ – the Delete / Backspace symbol
⇥ – ⇥⇥ – the Tab Key symbol

@zmwangx
zmwangx / No longer able to make public gists secret.md
Last active April 11, 2024 22:22
No longer able to make public gists private — message to GitHub

We've been able to toggle visibility of gists since 2014 (https://github.com/blog/1837-change-the-visibility-of-your-gists), but I just noticed that I can no longer make public gists private. That is, when I edit private gists I still see the "Make Public" button, but not the other way round — there's only a "Delete" button when I edit public gists; the "Make Secret" which should be next to it (as shown in the screencast in the linked blog post) is nowhere to be found. I made a screenshot and a screencast demonstrating the issue, both of which are attached. Could you please confirm this issue? Was this an intentional change, and why? Thank you for your attention.

gist-unable-to-make-secret

![gist-unable-to-make-secret](https://cloud.githubusercontent.com/assets/4149852/16898407/c76db210-4c0b-11e6-9108-0450f1edebb4.gif)
@zmwangx
zmwangx / .gitignore
Last active April 1, 2024 11:36
This program demonstrates how to correctly use openpty(3) from libutil on Linux to execute a command that must be run in a tty, and capture its (arbitrarily long) output.
pty
pty.o
@zmwangx
zmwangx / fonts.reg
Created October 20, 2018 17:19
How to make Chinese filenames not so ugly in Windows 10
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts]
"Segoe UI (TrueType)"="-segoeui.ttf"
"Segoe UI Black (TrueType)"="-seguibl.ttf"
"Segoe UI Black Italic (TrueType)"="-seguibli.ttf"
"Segoe UI Bold (TrueType)"="-segoeuib.ttf"
"Segoe UI Bold Italic (TrueType)"="-segoeuiz.ttf"
"Segoe UI Emoji (TrueType)"="-seguiemj.ttf"
"Segoe UI Historic (TrueType)"="-seguihis.ttf"
@zmwangx
zmwangx / urlgrep
Created December 27, 2018 19:43
Python script to extract URLs from HTML documents.
#!/usr/bin/env python3
"""Extract URLs from HTML documents."""
import argparse
import re
import sys
import urllib.parse
import bs4
@zmwangx
zmwangx / thumbnails.sh
Last active March 3, 2024 15:51
Script to generate thumbnails of a video and combine into one tile image. Uses FFmpeg and ImageMagick.
#!/bin/zsh
# Script to generate thumbnails of a video and combine into one tile image.
#
# CAUTION:
# FFprobe might fail to extract duration info from a MKV container. Use
# ffmpeg -i video.mkv -c:v copy -c:a copy video.mp4
# to swap to an MP4 container.
#
# Dependencies:
# 1. ffmpeg