Skip to content

Instantly share code, notes, and snippets.

View carlos-wong's full-sized avatar

carlos carlos-wong

  • Lejurobot.com
  • china, shenzhen
View GitHub Profile
import smtplib
from email.mime.text import MIMEText
from email.header import Header
from email.utils import parseaddr, formataddr
def _format_addr(s):
name, addr = parseaddr(s)
return formataddr(( \
Header(name, 'utf-8').encode(), \
addr.encode('utf-8') if isinstance(addr, unicode) else addr))
@carlos-wong
carlos-wong / scan.py
Created January 7, 2019 08:24
demo for scan udp broadcast
import socket
client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # UDP
client.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
client.bind(("", 12476))
while True:
data, addr = client.recvfrom(1024)
print("received message: %s"%data)
@carlos-wong
carlos-wong / *scratch*.txt
Last active November 25, 2016 16:15
cheatsheet for gist
gist.el now maintains a local cache so as to not go to the gist server every now and then.
multi-files gist support (indicated by a '+' in the gist list)
improved gist-list buffer, based on tabulated-list.el (same codebase as package.el) New keybindings:
g : reload the gist list from server
e : edit current gist description
k : delete current gist
+ : add a file to the current gist
- : remove a file from the current gist
y : print current gist url
b : browse current gist
@carlos-wong
carlos-wong / numpy_dump_load.py
Last active November 25, 2016 15:55
python numpy.array serialize and unserialize
import pickle
a = # some NumPy array
serialized = pickle.dumps(a, protocol=0) # protocol 0 is printable ASCII
deserialized_a = pickle.loads(serialized)
@carlos-wong
carlos-wong / androidasynctaskrepeat.md
Last active November 25, 2016 15:55
android asynctask keep run repeat
public void callAsynchronousTask() {
    final Handler handler = new Handler();
    Timer timer = new Timer();
    TimerTask doAsynchronousTask = new TimerTask() {       
        @Override
        public void run() {
            handler.post(new Runnable() {
                public void run() {       
 try {
let initialState = Immutable.Map({count:1, b:2, c:3});
function counter(state = initialState, action) {
switch (action.type) {
case 'INCREMENT':
return state.set('count',state.get('count')+1);
case 'DECREMENT':
return state.set('count',state.get('count')-1);
default:
http {
include mime.types;
server {
listen 8080;
lua_code_cache off;
location / {
default_type text/html;
content_by_lua '
alias duone="du -m -d 1 | sort -n"
alias gitcurrentstatus="git remote -v && git rev-list HEAD --max-count=1"
@carlos-wong
carlos-wong / repo.py
Created April 28, 2013 16:48
python: parse arguments
def _ParseArguments(args):
cmd = None
opt = _Options()
arg = []
for i in range(len(args)):
a = args[i]
if a == '-h' or a == '--help':
opt.help = True