Skip to content

Instantly share code, notes, and snippets.

@zhenyi2697
zhenyi2697 / gist:6083195
Created July 25, 2013 19:58
Shell: change default shell for mac os
# change to zsh
chsh -s /bin/zsh
# change back to bash
chsh -s /bin/bash
@zhenyi2697
zhenyi2697 / gist:6080716
Created July 25, 2013 15:14
Python: install PIL and jpeg decoder on mac os
Download jpeg lib here: http://www.ijg.org/files/jpegsrc.v7.tar.gz
tar -zxvf jpegsrc.v7.tar.gz
cd jpeg-7
./configure
sudo make clean
sudo CC=”gcc -arch i386″./configure –enable-shared –enable-static
sudo make
@zhenyi2697
zhenyi2697 / get_mac_address.py
Created July 25, 2013 14:45
Python: get mac address of a interface
import socket
import fcntl
import struct
def getHwAddr(ifname):
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
info = fcntl.ioctl(s.fileno(), 0x8927, struct.pack('256s', ifname[:15]))
return ''.join(['%02x:' % ord(char) for char in info[18:24]])[:-1]
@zhenyi2697
zhenyi2697 / gist:6060845
Created July 23, 2013 08:39
Python: install lxml
sudo apt-get install python-dev
sudo apt-get install libxml2-dev
sudo apt-get install libxslt-dev
sudo pip install lxml
@zhenyi2697
zhenyi2697 / get_map.py
Last active December 20, 2015 02:59
Python: get map from geoportail
This gist has been converted to a project and moved to here:
https://bitbucket.org/zhenyi2697/geocrawler
@zhenyi2697
zhenyi2697 / combine_image.py
Created July 22, 2013 21:01
Python: combin_image.py
#!/usr/bin/python
import Image
new_im = Image.new('RGB', (1280, 1280))
row = 11330
col = 16620
for i in xrange(5):
for j in xrange(5):
@zhenyi2697
zhenyi2697 / get_image.py
Created July 22, 2013 20:48
Python: get image for hiking
#!/usr/bin/python
import urllib
row_start = 11330
col_start = 16620
url_prefix = 'http://wxs.ign.fr/tyujsdxmzox31ituc2uw0qwl/geoportail/wmts?SERVICE=WMTS&VERSION=1.0.0&REQUEST=GetTile&LAYER=GEOGRAPHICALGRIDSYSTEMS.MAPS&STYLE=normal&FORMAT=image/jpeg&TILEMATRIXSET=PM&TILEMATRIX=15&'
url_appendix = '&extParamId=aHR0cDovL3d3dy5nZW9wb3J0YWlsLmdvdXYuZnIvYWNjdWVpbA=='
image_path = '/Users/zhenyi2697/Desktop/cartes'
@zhenyi2697
zhenyi2697 / gist:5998071
Created July 15, 2013 07:35
Python: argparser little demo
import argparse
parser = argparse.ArgumentParser(description='cbox synchronisation program')
group = parser.add_mutually_exclusive_group(required=True)
group.add_argument('--vm', action='store', help='Name of the VM', metavar='<NAME>')
group.add_argument('--uuid', action='store', help='UUID of the VM', metavar='<VM_UUID>')
parser.add_argument('--infoi', action='store', help='Define the new ini file', metavar='<ini_file>')
parser.add_argument('--nolog', action='store_true', default=False, help='Disable logging')
parser.add_argument('--debug', action='store_true', default=False, help='Enable debug trace')
args = parser.parse_args()
@zhenyi2697
zhenyi2697 / gist:5974140
Created July 11, 2013 09:55
Python: test log system
#!/usr/bin/python
import logging
def testLog(DEBUG, LOGFILE):
if DEBUG:
log_level = logging.DEBUG
else:
log_level = logging.INFO
@zhenyi2697
zhenyi2697 / gist:5927470
Created July 4, 2013 12:55
Shell: check if it's root who run the script
# check if it's root who run the script
if [ `id -u` != "0" ]; then
exit 1
fi