Skip to content

Instantly share code, notes, and snippets.

View hustshawn's full-sized avatar
🎯
Focusing

Shawn Zhang hustshawn

🎯
Focusing
View GitHub Profile
a = [1, 2, 3]
b = [4, 5, 6]
c = [7, 8, 9]
def chain(x, y):
yield from x
yield from y
for x in chain(a, b):
print(x, end=' ')
@hustshawn
hustshawn / opencc.lua
Created May 25, 2017 04:47
Lua wrapper for OpenCC
--[[
Lua wrapper for OpenCC.
--]]
local ffi = require("ffi")
local opencc = ffi.load("/usr/lib64/libopencc.so.2")
-- Define C API bindings
ffi.cdef[[
import asyncio
from contextlib import closing
import aiohttp
from aiohttp import ClientSession
async def do_sth(session, n=0):
if n < 0:
n = 0
n %= 3
url = "http://localhost:8000/{}".format(n)
@hustshawn
hustshawn / observer.py
Last active June 14, 2017 09:58
An implementation of the observer pattern with Python
class Observable:
def __init__(self):
self.__observers = []
def register_observer(self, observer):
self.__observers.append(observer)
def notify_observers(self, *args, **kwargs):
for observer in self.__observers:
observer.notify(self, *args, **kwargs)
@hustshawn
hustshawn / asyncio_server.py
Created June 22, 2017 09:05
An echo server with asyncio. Just run it with `rc locahost 5533` once server is up.
import asyncio
class EchoProtocol(asyncio.Protocol):
def connection_made(self, transport):
self.transport = transport
def connection_lost(self, exc):
self.transport = None
@hustshawn
hustshawn / brew-install-script.sh
Last active January 16, 2020 02:23 — forked from CliffordAnderson/brew-install-script.sh
Brew install script for OSX
#!/bin/sh
# Homebrew Script for OSX
# To execute: save and `chmod +x ./brew-install-script.sh` then `./brew-install-script.sh`
echo "Installing brew..."
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
echo "Installing brew cask..."
brew install caskroom/cask/brew-cask
@hustshawn
hustshawn / .gitignore
Last active July 21, 2017 04:52
Global gitignore
# Folder view configuration files
.DS_Store
Desktop.ini
# Thumbnail cache files
._*
Thumbs.db
# Files that might appear on external disks
.Spotlight-V100
@hustshawn
hustshawn / .editorconfig
Last active July 25, 2017 06:34
The editoryconfig for Python, adopted from Django
# http://editorconfig.org
root = true
[*]
indent_style = space
indent_size = 4
insert_final_newline = true
trim_trailing_whitespace = true
end_of_line = lf
@hustshawn
hustshawn / sftp_put.py
Created August 16, 2017 10:56
A simple SFTP file uploading snippet with paramiko
import paramiko
import os
HOST = 'youdomain.com'
PORT = 22
USERNAME = 'username'
PASSWORD = 'password'
REMOTE_PATH = '/remote/sftp/path/'
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import time
from progressbar import AnimatedMarker, Bar, BouncingBar, Counter, ETA, \
FileTransferSpeed, FormatLabel, Percentage, \
ProgressBar, ReverseBar, RotatingMarker, \
SimpleProgress, Timer