Skip to content

Instantly share code, notes, and snippets.

View sunliwen's full-sized avatar

Liwen S sunliwen

View GitHub Profile
@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 / 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 / getQueryParam.js
Created September 22, 2013 12:27
Found this useful snippet in http://getbootstrap.com/customize/
function getQueryParam(key) {
key = key.replace(/[*+?^$.\[\]{}()|\\\/]/g, "\\$&"); // escape RegEx meta chars
var match = location.search.match(new RegExp("[?&]"+key+"=([^&]+)(&|$)"));
return match && decodeURIComponent(match[1].replace(/\+/g, " "));
}
// ?id=123
// getQueryParam('id') --> 123
@sunliwen
sunliwen / south_custom_field.py
Last active December 22, 2015 08:49
how to make south aware of custom field
"""
Following error will occur if there's custom field.
```
! Cannot freeze field 'myapp.mymodel.entity_type'
! (this field has class myapp.fields.EntityTypeField)
! South cannot introspect some fields; this is probably because they are custom
! fields. If they worked in 0.6 or below, this is because we have removed the
! models parser (it often broke things).
@sunliwen
sunliwen / shorten_uuid.py
Created September 5, 2013 07:41
uuid and shortuuid in python
# `pip install shortuuid`
import uuid
long = uuid.uuid5(namespace=uuid.NAMESPACE_URL, name="http://example.com")
print long # UUID('8c9ddcb0-8084-5a7f-a988-1095ab18b5df')
import shortuuid
short = shortuuid.uuid(name="http://example.com")
print short # 'c8sh5y9hdSMS6zVnrvf53T'
# Ubuntu upstart file at /etc/init/mongodb.conf
limit nofile 32768 32768
kill timeout 300 # wait 300s between SIGTERM and SIGKILL.
pre-start script
mkdir -p /data/mongodb &> /dev/null
mkdir -p /data/logs/mongo &> /dev/null
chown mongodb:nogroup /data/mongodb &> /dev/null