Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env python
import time
def time_zone(t):
if t.tm_isdst == 1 and time.daylight == 1:
tz_sec = time.altzone
tz_name = time.tzname[1]
else:
tz_sec = time.timezone
@xianghuzhao
xianghuzhao / checksum.py
Created November 2, 2016 10:06
File checksum
#!/usr/bin/env python
import zlib
import hashlib
class Adler32CheckSum():
@staticmethod
def checksum(filename, blocksize=1048576):
value = 1
with open(filename, "rb") as f:
@xianghuzhao
xianghuzhao / term-size.py
Created November 2, 2016 10:05
Terminal Size
def get_terminal_size_linux():
def ioctl_GWINSZ(fd):
try:
import fcntl, termios, struct
cr = struct.unpack('hh',
fcntl.ioctl(fd, termios.TIOCGWINSZ, '1234'))
return cr
except:
pass
cr = ioctl_GWINSZ(0) or ioctl_GWINSZ(1) or ioctl_GWINSZ(2)
@xianghuzhao
xianghuzhao / load-object.py
Last active November 2, 2016 10:04
Load Object
def loadObject(moduleName, className):
try:
m = __import__(moduleName, globals(), locals(), [className])
except ImportError, e:
raise Exception('Could not from %s import %s' % (moduleName, className))
return getattr(m, className)()
import imp
@xianghuzhao
xianghuzhao / python-version.sh
Created November 2, 2016 10:01
Get python version in shell
#!/bin/sh
get_python_version() {
version_str=$(python -V 2>&1)
temp=${version_str##* }
python_version_major=${temp%%.*}
temp=${temp#*.}
python_version_minor=${temp%%.*}
}