Skip to content

Instantly share code, notes, and snippets.

View zhaochunqi's full-sized avatar
:octocat:
Working from home

Alex Zhao zhaochunqi

:octocat:
Working from home
View GitHub Profile
def randint(*args): return 10
guess = 10
@zhaochunqi
zhaochunqi / ssh-keygen.sh
Last active August 29, 2015 14:17
生成ssh密钥
ssh-keygen -f ~/.ssh/id_rsa -t rsa -N ''
cat ~/.ssh/id_rsa.pub
@zhaochunqi
zhaochunqi / change_src.sh
Created March 19, 2015 07:57
修改源为中科大源
after="http://mirrors.ustc.edu.cn/ubuntu/"
origin_src="http://us.archive.ubuntu.com/ubuntu/"
origin_scr="http://security.ubuntu.com/ubuntu"
sudo sed -i "s;$origin_src;$after;g" /etc/apt/sources.list
sudo sed -i "s;$origin_scr;$after;g" /etc/apt/sources.list
sudo apt-get update
@zhaochunqi
zhaochunqi / Reset_LaunchPad.sh
Last active August 29, 2015 14:16
重置Apple的LaunchPad
defaults write com.apple.dock ResetLaunchPad -bool true;killall Dock
@zhaochunqi
zhaochunqi / digital_root.py
Last active August 29, 2015 14:12
Digital Root
'''
digital_root(16)
=> 1 + 6
=> 7
digital_root(942)
=> 9 + 4 + 2
=> 15 ...
=> 1 + 5
=> 6
@zhaochunqi
zhaochunqi / whatCentury.py
Created December 31, 2014 02:58
input 4 digital string , should output what century it is . Notice: 2000 is 20th century
def whatCentury(year):
# code must go here
digit_year = int(year)
digit_century = (digit_year-1)/100 + 1
a = {1:'st',2:'nd',3:'rd'}
if digit_century < 11 or digit_century > 20:
return str(digit_century)+a.get(digit_century % 10,'th')
return str(digit_century)+'th'
@zhaochunqi
zhaochunqi / send_email_by_noreply.py
Last active August 29, 2015 14:10
send email throw smtp
# -*- coding: utf-8 -*-
import smtplib
def send_email_over_smtp(to_email,email_content,login_user='no-reply@genscript.com',email_cc=None):
try:
smtpserver = smtplib.SMTP('10.168.2.119',timeout=60)
smtpserver.ehlo()
if email_cc:
header = 'To:' + to_email + '\n' +'CC:'+email_cc +'\n' + 'From: ' + login_user + '\n' + 'Subject:CR Notification\n'
@zhaochunqi
zhaochunqi / parse_html_with_xpath.py
Last active August 29, 2015 14:10
xpath parse for html
# -*- coding: utf-8 -*-
__author__ = 'alex'
from lxml.html import parse
def parse_html(html_address,xpath_expression):
page = parse(html_address)
for href in page.xpath(xpath_expression):
print href
@zhaochunqi
zhaochunqi / connect_to_mysql.py
Last active August 29, 2015 14:08
connect to a MySQL Database in Python
#!/usr/bin/python
import MySQLdb
db = MySQLdb.connect(host="localhost", # your host, usually localhost
user="john", # your username
passwd="megajonhy", # your password
db="jonhydb") # name of the data base
# you must create a Cursor object. It will let
# you execute all the queries you need
import smtplib
def send_email_over_smtps(to_email,login_user,login_pwd):
smtpserver = smtplib.SMTP("10.168.2.120",587)
smtpserver.ehlo()
smtpserver.starttls()
smtpserver.ehlo
smtpserver.login(login_user, login_pwd)
header = 'To:' + to_email + '\n' + 'From: ' + login_user + '\n' + 'Subject:testing \n'
print header