Skip to content

Instantly share code, notes, and snippets.

@buptxge
buptxge / 0_reuse_code.js
Created March 10, 2016 03:57
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@buptxge
buptxge / .vimrc
Created March 11, 2016 04:20
.vimrc and molokai.vim
syntax enable
syntax on
set nu
set smartindent
set tabstop=4
set shiftwidth=4
set expandtab
set softtabstop=4
set hlsearch
@buptxge
buptxge / datetime_struct.py
Last active March 14, 2016 01:22
Python get structed time string
import datetime
import time
#Get now time string
timestr = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
#Calc time delta
t1 = datetime.datetime.now()
time.sleep(3)
t2 = datetime.datetime.now()
@buptxge
buptxge / gist:7bb0787afdf1ac691769
Created March 11, 2016 09:09
ProcessPoolExector test
import concurrent.futures
import math
import time
PRIMES = [
112272535095293,
112272535095293,
112582705942171,
112272535095293,
115280095190773,
@buptxge
buptxge / mysql_helper.py
Created March 15, 2016 07:38
Python MySQLdb insert code by dict(key-value)
placeholders = ', '.join(['%s'] * len(myDict))
columns = ', '.join(myDict.keys())
sql = "INSERT INTO %s ( %s ) VALUES ( %s )" % (table, columns, placeholders)
cursor.execute(sql, myDict.values())
import codecs
import chardet
bytes = min(32, os.path.getsize(filename))
raw = open(filename, 'rb').read(bytes)
if raw.startswith(codecs.BOM_UTF8):
encoding = 'utf-8-sig'
else:
result = chardet.detect(raw)
@buptxge
buptxge / quicksort.py
Created March 22, 2016 07:27
QuickSort python example.
import random
def sort(a,low,high):
if low>=high:
return
i = low
j = high
mid_value = a[i]
while(True):
@buptxge
buptxge / register.py
Created April 7, 2016 08:15
Windows python register script.
#
# script to register Python 2.0 or later for use with win32all
# and other extensions that require Python registry settings
#
# written by Joakim Loew for Secret Labs AB / PythonWare
#
# source:
# http://www.pythonware.com/products/works/articles/regpy20.htm
#
# modified by Valentine Gogichashvili as described in http://www.mail-archive.com/[email protected]/msg10512.html
@buptxge
buptxge / print_with_win32print.py
Created April 7, 2016 08:38
Print image using win32print and PIL
import win32print
import win32ui
from PIL import Image, ImageWin
PHYSICALWIDTH = 110
PHYSICALHEIGHT = 111
printer_name = win32print.GetDefaultPrinter ()
file_name = "new.jpg"