Skip to content

Instantly share code, notes, and snippets.

通用样式

.ad {
  position: relative;
  display: block;
  max-height: 196px;
  max-width: 320px;
  border: 1px solid #d6d6d6;
 overflow: hidden;
@terryoy
terryoy / execute.txt
Last active August 29, 2015 14:08
lua study notes
# execute a program
$ lua hello.lua
# import a file and then into interactive mode
$ lua -i lib.lua
# execute some line
$ lua -e "print(math.sin(12))"
# execute with library "a" (using "-l")
@terryoy
terryoy / qiniu_download_bucket.py
Created July 11, 2014 15:47
Shell script to work with Qiniu Cloud Storage
domain_name = '<domain_name>'
bucket_name = '<bucket_name>'
import qiniu.conf
qiniu.conf.ACCESS_KEY = '<qiniu_access_key>'
qiniu.conf.SECRET_KEY = '<qiniu_secret_key>'
import qiniu.rs, qiniu.rsf
import os, urllib, sys
@terryoy
terryoy / down_001.sh
Created June 1, 2014 03:52
PDF download and merge scripts (this script specifically downloads the Ouyang Family Book from National Library of China)
#!/bin/bash
# (book part 1)
for i in {1..101}
do
wget "http://mylib.nlc.gov.cn/system/doc/pdfBooks/books/9831679/20120824_05/1302019/$i" -O "001_$i.pdf"
done
@terryoy
terryoy / FirmwareProgrammer.py
Created May 15, 2014 08:28
Python Command Wrapper of Texas Instrument Smart RF Flash Programmer on Windows
#!/bin/python
import subprocess, sys, re
PROGRAM_NAME = 'SmartRFProgConsole.exe'
FIRMWARE_NAME = 'test.hex'
# The Return Codes:
# 0 = Success
# 1 = System error
# 2 = Parameter error
@terryoy
terryoy / cmd_win.py
Created May 15, 2014 04:51
Python calling OS command line
import subprocess
def run_program(cmdargs):
"""Execute an OS program with arguments(in list form), and return the (returncode, stdout, stderr) result"""
p = subprocess.Popen(cmdargs, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output = p.communicate()
return p.returncode, output[0], output[1]
# example;
# run_program(['ls', '-l'])
@terryoy
terryoy / README
Created May 1, 2014 02:09
aliyun-oss-tools
# it depends on aliyun-oss SDK here
# http://help.aliyun.com/view/13438815.html
@terryoy
terryoy / config.ini
Last active June 11, 2019 20:50
Python example to show usage of command line arguments, configurations, and exceptions
[helloworld]
name = Terry
@terryoy
terryoy / .bashrc
Last active December 21, 2015 22:19
Useful Alias
# open a browser and view raw html (e.g. "cat some.html | viewhtml")
alias viewhtml='firefox "data:text/html;charset=utf-8;base64,$(base64 -w 0 <&0)"'
# url encode / decode
alias urlencode='python -c "import sys, urllib as ul; print ul.quote_plus(sys.argv[1])"'
alias urldecode='python -c "import sys, urllib as ul; print ul.unquote_plus(sys.argv[1])"'
# url shortener
alias shortenurl="python -c \"import sys, urllib as ul; print ul.urlopen('http://tinyurl.com/api-create.php?url=%s' % ul.quote_plus(sys.argv[1])).readline()\""
@terryoy
terryoy / start_server.sh
Created July 15, 2013 10:54
start django server script with gunicorn
#!/bin/bash
set -e
LOGFILE=/var/log/apps/djangostart/console.log
LOGDIR=$(dirname $LOGFILE)
NUM_WORKERS=3
# user/group to run as
USER=ubuntu
GROUP=ubuntu
cd /home/ubuntu/apps/djangostart/
# setup