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 / ere-uri.md
Created August 28, 2014 22:54
Regex matching URI (with POSIX Extended Regular Expressions — ERE). #regex #ere #uri

Below are POSIX ERE expressions matching relevant expressions defined in RFC 3986 - Uniform Resource Identifier (URI): Generic Syntax, constructed according to the ABNF definitions.

# RFC 3986
# http://tools.ietf.org/html/rfc3986
#
# pct-encoded   %[0-9A-Fa-f]{2}
# reserved      [:/?#[]@!$&'()*+,;=]
# gen-delims    [:/?#[]@]
# sub-delims    [!$&'()*+,;=]

unreserved [A-Za-z0-9._~-]

@zmwangx
zmwangx / pip.txt
Last active August 29, 2015 14:06
pip: my list of installed packages, auto deps removed
beautifulsoup4
colorama
feedparser
flickrapi
grip
pipdeptree
pyimgur
python-dateutil
python-magic
requests
@zmwangx
zmwangx / npm.txt
Created September 15, 2014 11:25
npm: my list of globally installed packages, auto deps removed
cssbeautify-cli
qrcode-terminal
@zmwangx
zmwangx / preamble.tex
Created September 16, 2014 10:21
LaTeX preamble.
\documentclass{amsart}
%%%%%%%%%%%%%%%%%%%%%%%%%%% USER PACKAGES %%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{amssymb}
\usepackage{color}
\usepackage{enumerate}
\usepackage{graphicx}
\usepackage{hyperref}
\hypersetup{
% citecolor=green,
@zmwangx
zmwangx / fb-dl.py
Last active November 28, 2023 20:29
Scrape all photos from a public Facebook page.
#!/usr/bin/env python
############################### README ###############################
# External dependencies:
# * libmagic
# * python-dateutil
# * python-magic
# * requests
#
# The shell command call at the end was tested with GNU date from GNU
@zmwangx
zmwangx / html-to-text.py
Created September 29, 2014 00:33
BeautifulSoup: parse out text from HTML snippet, keeping linebreaks at <br /> or <p>.
#/usr/bin/env python
# credit: http://stackoverflow.com/a/5925525/1944784
from bs4 import BeautifulSoup
html = '<p>anything<br />stupid</p>'
elem = BeautifulSoup(html)
def text_with_newlines(elem):
text = ''
for e in elem.descendants:

Keybase proof

I hereby claim:

  • I am zmwangx on github.
  • I am zmwangx (https://keybase.io/zmwangx) on keybase.
  • I have a public key whose fingerprint is C2A3 AE48 64FA 2C34 D078 5535 EC6B D45D E39C 2FE2

To claim this, I am signing this object:

@zmwangx
zmwangx / tee.py
Created October 2, 2014 04:01
Setting up tee in python.
# credit: http://shallowsky.com/blog/programming/python-tee.html
import sys
class tee :
def __init__(self, _fd1, _fd2) :
self.fd1 = _fd1
self.fd2 = _fd2
def __del__(self) :
<table class="updates" style="border: 1px solid #ddd;" width="99%" cellspacing="0">
<tbody>
<tr>
<th align="center">Year</th>
<th align="center">Month<br>
Day</th>
<th align="center">Gap<br>
(days)</th>
<th align="center">Version</th>
<th align="center">Size</th>