Skip to content

Instantly share code, notes, and snippets.

@terryoy
terryoy / compile_and_run.sh
Created January 28, 2013 05:52
Linux VGA Programming Helloworld
# pre-requisities: sudo apt-get install libsvga1 libsvga1-dev
gcc -lvga helloworld.c -o helloworld
sudo ./helloworld
# output:
# (on screen: a small red point displaying for 5 sec)
# (on console: [svgalib: allocated virtual console #8])
@terryoy
terryoy / rc.xml
Last active December 16, 2015 19:38
在Openbox里实现像Windows7那样的Window snap功能 (即Win+left或right时,附着在屏幕左边或右边并以半屏大小显示,Win+Up的时候最大化,Win+Down时取消最大化)
<!-- Add following content in .config/openbox/rc.xml -->
<!-- After saving, execute "openbox --reconfigure" to refresh -->
<!-- Ref: https://wiki.archlinux.org/index.php/Openbox#Window_snap_behaviour -->
<keybind key="W-Left">
<action name="UnmaximizeFull"/>
<action name="MaximizeVert"/>
<action name="MoveResizeTo">
<width>50%</width>
</action>
@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
@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 / 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 / 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 / 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 / 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 / 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 / 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