Skip to content

Instantly share code, notes, and snippets.

View hustshawn's full-sized avatar
🎯
Focusing

Shawn Zhang hustshawn

🎯
Focusing
  • AWS
  • Hong Kong
View GitHub Profile

30 Days of Python: Cheat Sheet

A quick reference guide for using the Python Programming language.

Strings

text = "Some string, with some stuff."

text2 = "Yet, another string here."
@hustshawn
hustshawn / scrape-img-demo.py
Last active January 17, 2017 23:07
An online scrapying img demo with selenium and beautifulsoup. Sources: "http://www.chrisburkard.com/"
import os
import requests
import shutil
import time
from bs4 import BeautifulSoup
from selenium import webdriver
url = "http://www.chrisburkard.com/"
# web_r = requests.get(url)
# web_soup = BeautifulSoup(web_r.content, "lxml")
@hustshawn
hustshawn / install_pyenv.sh
Created February 27, 2017 08:08 — forked from ysaotome/install_pyenv.sh
pyenv install for CentOS 6.5 x86_64
#!/bin/zsh
# pyenv install for CentOS 6.5 x86_64
yum install -y gcc gcc-c++ make git patch openssl-devel zlib-devel readline-devel sqlite-devel bzip2-devel
git clone git://github.com/yyuu/pyenv.git ~/.pyenv
export PATH="$HOME/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
@hustshawn
hustshawn / tmux.conf
Created March 7, 2017 06:41 — forked from spicycode/tmux.conf
The best and greatest tmux.conf ever
# 0 is too far from ` ;)
set -g base-index 1
# Automatically set window title
set-window-option -g automatic-rename on
set-option -g set-titles on
#set -g default-terminal screen-256color
set -g status-keys vi
set -g history-limit 10000

setup-aws-ubuntu-16.04

sudo apt-get update

Locale

Add below to /etc/environment

LC_CTYPE="en_US.UTF-8"
LC_ALL="en_US.UTF-8"
@hustshawn
hustshawn / email_notify.py
Created March 15, 2017 10:38 — forked from jriguera/email_notify.py
Email from Python with Jinja2
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Python 3 and compatibility with Python 2
from __future__ import unicode_literals, print_function
import os
import sys
import re
import logging
@hustshawn
hustshawn / logger_fromatter.py
Last active March 24, 2017 04:20
An alternative way to change the default log time into your timezone. eg. 'Asia/Hong_Kong'
import logging
import pytz
TIMEZONE = 'Asia/Hong_Kong'
def posix2local(timestamp, tz=pytz.timezone(TIMEZONE)):
"""Seconds since the epoch -> local time as an aware datetime object."""
return datetime.fromtimestamp(timestamp, tz)
class Formatter(logging.Formatter):
def converter(self, timestamp):

To add en_US.UTF-8 to the list of usable locales:

  • Debian, interactive: dpkg-reconfigure locales
  • Debian, automated: sed -i 's/^# *\(en_US.UTF-8\)/\1/' /etc/locale.gen && locale-gen
  • Ubuntu, automated: locale-gen en_US.UTF-8
@hustshawn
hustshawn / nginxproxy.md
Created May 5, 2017 12:17 — forked from soheilhy/nginxproxy.md
How to proxy web apps using nginx?

Virtual Hosts on nginx (CSC309)

When hosting our web applications, we often have one public IP address (i.e., an IP address visible to the outside world) using which we want to host multiple web apps. For example, one may wants to host three different web apps respectively for example1.com, example2.com, and example1.com/images on the same machine using a single IP address.

How can we do that? Well, the good news is Internet browsers

@hustshawn
hustshawn / asyncio_request.py
Created May 6, 2017 07:10
A demo to utilize asyncio to fire multiple requests
import requests
import asyncio
import time
urls = [
"www.baidu.com",
"www.sina.com",
"www.google.com.hk",
"www.sohu.com"