Skip to content

Instantly share code, notes, and snippets.

View sunliwen's full-sized avatar

Liwen S sunliwen

View GitHub Profile
@sunliwen
sunliwen / https_server.py
Created November 3, 2018 08:47
py https server
#!/usr/bin/env python3
# Ported to Python 3 by Telmo "Trooper" (telmo.trooper@gmail.com)
#
# Original code from:
# http://www.piware.de/2011/01/creating-an-https-server-in-python/
# https://gist.github.com/dergachev/7028596
#
# To generate a certificate use:
# openssl req -new -x509 -keyout server.pem -out server.pem -days 365 -nodes
@sunliwen
sunliwen / chrome_unsecure.sh
Created November 3, 2018 08:38
Chrome unsecure
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --unsafely-treat-insecure-origin-as-secure=http://0.0.0.0:8000
@sunliwen
sunliwen / sh
Created July 3, 2018 14:32
brew a python 3.6 after 3.7 release
# refs: https://stackoverflow.com/questions/51125013/how-can-i-install-a-previous-version-of-python-3-in-macos-using-homebrew/51125014#51125014
brew uninstall --ignore-dependencies python3
brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/f2a764ef944b1080be64bd88dca9a1d80130c558/Formula/python.rb
brew switch python 3.6.5_1
@sunliwen
sunliwen / keybase.md
Created September 5, 2017 01:17
keybase.md

Keybase proof

I hereby claim:

  • I am sunliwen on github.
  • I am sunliwen (https://keybase.io/sunliwen) on keybase.
  • I have a public key ASABIfKL8I_F9v4CepwlSJS9Fo8No_qdVEuOx9tQxEIt6wo

To claim this, I am signing this object:

@sunliwen
sunliwen / smtplib_ssl.py
Created March 17, 2016 11:06
smtplib ssl qq mail
import os, sys
import smtplib
from smtplib import SMTP_SSL
from email.header import Header
from email.mime.text import MIMEText
mailInfo = {
"from":"user@domain.com",
"to":"someone@anotherdomain.com",
"hostname":"smtp.exmail.qq.com",
@sunliwen
sunliwen / mac_openssl_include.sh
Last active March 8, 2021 23:22
On Mac - fatal error: 'openssl/aes.h' file not found #include <openssl/aes.h>
# Install pip install cryptography, path issue with openssl/aes.h will occur. The reason is Apple deprecated openssl and the compiler can't find the one installed by homebrew.
# So the following line will help.
env LDFLAGS="-L$(brew --prefix openssl)/lib" CFLAGS="-I$(brew --prefix openssl)/include" pip install cryptography
@sunliwen
sunliwen / test_json_decimal.py
Last active August 29, 2015 14:08
Demonstrate how to loads/dumps json with float value as decimal.Decimal in Python
import json
import decimal
import pprint
# refs: https://djangosnippets.org/snippets/2410/
# refs: http://stackoverflow.com/questions/1960516/python-json-serialize-a-decimal-object
class DecimalEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, decimal.Decimal):
return float(obj)
# http://lxml.de/installation.html#using-lxml-with-python-libxml2
STATIC_DEPS=true pip install lxml
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDN0sO2/S6Q19vOz2ZO7Y+TAFzHQb1LCtlbcGNFACq0M3PXFVQ1rTyayiNcrnfz+ckfCZe38IUZLoAJXiqg2A7Ww8vazuG8exdR1+GXWYSAFsAkJkqptQ2B/fl0ZelJZLEVJVDJw4Y0d/oYlhpL8FKuvrHQJLscPfuxB/VxJBxsaWDQvrNb862R/A5A28VpE1/pZRWp1e/6qtDwxhYhJPoPsdur9l8TOWz/AzBpqxpSB3zKGIK07hHBSYtfZXBO8gcOaGU4s+btAodJ5L0U0E3hXlUGc0e+ZYFU6f6Sz2tzYiwPfS9sYVjBN14vzZh4Bz5cZZQurjcgwaPhyxCzh9ql sunliwen@gmail.com
# vim: ft=sh:ts=4:sw=4:autoindent:expandtab:
# Source: https://github.com/django/django/blob/stable/1.5.x/extras/django_bash_completion
# #########################################################################
# This bash script adds tab-completion feature to django-admin.py and
# manage.py.
#
# Testing it out without installing
# =================================
#