Skip to content

Commit 6878058

Browse files
committed
Merge pull request Show-Me-the-Code#11 from renzongxian/master
merged Show-Me-the-Code:master from renzongxian:master
2 parents 8d22b9c + c5277f6 commit 6878058

7 files changed

Lines changed: 208 additions & 0 deletions

File tree

renzongxian/0000/0000.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Source:https://github.com/Show-Me-the-Code/show-me-the-code
2+
# Author:renzongxian
3+
# Date:2014-11-30
4+
# Python 3.4
5+
6+
"""
7+
8+
第 0000 题:将你的 QQ 头像(或者微博头像)右上角加上红色的数字,类似于微信未读信息数量那种提示效果
9+
10+
"""
11+
12+
from PIL import Image, ImageDraw, ImageFont
13+
import sys
14+
15+
16+
def add_num_to_img(file_path):
17+
im = Image.open(file_path)
18+
im_draw = ImageDraw.Draw(im)
19+
font = ImageFont.truetype("arial.ttf", int(im.size[0]/5))
20+
im_draw.text((int(im.size[0]-im.size[0]/10), 5), "4", (256, 0, 0), font=font)
21+
del im_draw
22+
im.save(file_path)
23+
24+
if __name__ == "__main__":
25+
if len(sys.argv) <= 1:
26+
print("Need at least 1 parameter. Try to execute 'python 0000.py $image_path'")
27+
else:
28+
for infile in sys.argv[1:]:
29+
try:
30+
add_num_to_img(infile)
31+
print("Success!")
32+
except IOError:
33+
print("Can't open image!")
34+
pass

renzongxian/0000/image.png

36.4 KB
Loading

renzongxian/0001/0001.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Source:https://github.com/Show-Me-the-Code/show-me-the-code
2+
# Author:renzongxian
3+
# Date:2014-11-30
4+
# Python 3.4
5+
6+
"""
7+
8+
做为 Apple Store App 独立开发者,你要搞限时促销,为你的应用生成激活码(或者优惠券),
9+
使用 Python 如何生成 200 个激活码(或者优惠券)?
10+
11+
"""
12+
13+
import uuid
14+
15+
16+
def generate_key():
17+
key_list = []
18+
for i in range(200):
19+
uuid_key = uuid.uuid3(uuid.NAMESPACE_DNS, str(uuid.uuid1()))
20+
key_list.append(str(uuid_key).replace('-', ''))
21+
return key_list
22+
23+
if __name__ == '__main__':
24+
print(generate_key())

renzongxian/0002/0002.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# -*- coding:utf8 -*-
2+
# Source:https://github.com/Show-Me-the-Code/show-me-the-code
3+
# Author:renzongxian
4+
# Date:2014-12-06
5+
# Python 2.7, MySQL-python does not currently support Python 3
6+
7+
"""
8+
9+
将 0001 题生成的 200 个激活码(或者优惠券)保存到 MySQL 关系型数据库中。
10+
11+
"""
12+
13+
import uuid
14+
import MySQLdb
15+
16+
17+
def generate_key():
18+
key_list = []
19+
for i in range(200):
20+
uuid_key = uuid.uuid3(uuid.NAMESPACE_DNS, str(uuid.uuid1()))
21+
key_list.append(str(uuid_key).replace('-', ''))
22+
return key_list
23+
24+
25+
def write_to_mysql(key_list):
26+
# Connect to database
27+
db = MySQLdb.connect("localhost", "test", "test1234", "testDB")
28+
29+
# Use function cursor() to open the cursor operation
30+
cursor = db.cursor()
31+
32+
# If the table exists, delete it
33+
cursor.execute("drop table if exists ukey")
34+
35+
# Create table
36+
sql = """create table ukey (
37+
key_value char(40) not null
38+
)"""
39+
cursor.execute(sql)
40+
41+
# Insert data
42+
try:
43+
for i in range(200):
44+
cursor.execute('insert into ukey values("%s")' % (key_list[i]))
45+
# Commit to database
46+
db.commit()
47+
except:
48+
# Rollback when errors occur
49+
db.rollback()
50+
51+
# Close database
52+
db.close()
53+
54+
55+
if __name__ == '__main__':
56+
write_to_mysql(generate_key())

renzongxian/0003/0003.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# -*- coding:utf8 -*-
2+
# Source:https://github.com/Show-Me-the-Code/show-me-the-code
3+
# Author:renzongxian
4+
# Date:2014-12-06
5+
# Python 2.7
6+
7+
"""
8+
9+
将 0001 题生成的 200 个激活码(或者优惠券)保存到 Redis 非关系型数据库中。
10+
11+
"""
12+
13+
import uuid
14+
import redis
15+
16+
17+
def generate_key():
18+
key_list = []
19+
for i in range(200):
20+
uuid_key = uuid.uuid3(uuid.NAMESPACE_DNS, str(uuid.uuid1()))
21+
key_list.append(str(uuid_key).replace('-', ''))
22+
return key_list
23+
24+
25+
def write_to_redis(key_list):
26+
re = redis.StrictRedis(host='localhost', port=6379, db=0)
27+
for i in range(200):
28+
re.sadd('ukey', key_list[i])
29+
30+
31+
if __name__ == '__main__':
32+
write_to_redis(generate_key())

renzongxian/0004/0004.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Source:https://github.com/Show-Me-the-Code/show-me-the-code
2+
# Author:renzongxian
3+
# Date:2014-12-07
4+
# Python 3.4
5+
6+
"""
7+
8+
任一个英文的纯文本文件,统计其中的单词出现的个数。
9+
10+
"""
11+
12+
import sys
13+
14+
15+
def word_count(file_path):
16+
file_object = open(file_path, 'r')
17+
18+
word_num = 0
19+
for line in file_object:
20+
line_list = line.split()
21+
word_num += len(line_list)
22+
23+
file_object.close()
24+
return word_num
25+
26+
if __name__ == "__main__":
27+
if len(sys.argv) <= 1:
28+
print("Need at least 1 parameter. Try to execute 'python 0004.py $image_path'")
29+
else:
30+
for infile in sys.argv[1:]:
31+
try:
32+
print("The total number of words is ", word_count(infile))
33+
except IOError:
34+
print("Can't open file!")
35+
pass

renzongxian/0004/test

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Why are my contributions not showing up on my profile?
2+
Your profile contributions graph is a record of contributions you've made to GitHub repositories. Contributions are only counted if they meet certain criteria. In some cases, we may need to rebuild your graph in order for contributions to appear.
3+
4+
Contributions that are counted
5+
6+
Issues and pull requests
7+
8+
Issues and pull requests will appear on your contributions graph if they meet both of these conditions:
9+
10+
They were opened within the past year.
11+
They were opened in a standalone repository, not a fork.
12+
Commits
13+
14+
Commits will appear on your contributions graph if they meet all of the following conditions:
15+
16+
The commits were made within the past year.
17+
The email address used for the commits is associated with your GitHub account.
18+
The commits were made in a standalone repository, not a fork.
19+
The commits were made:
20+
In the repository's default branch (usually master)
21+
In the gh-pages branch (for repositories with Project Pages sites)
22+
In addition, at least one of the following must be true:
23+
24+
You are a collaborator on the repository or are a member of the organization that owns the repository.
25+
You have forked the repository.
26+
You have opened a pull request or issue in the repository.
27+
You have starred the repository.

0 commit comments

Comments
 (0)