Skip to content

Commit 3f540ad

Browse files
committed
Merge pull request Show-Me-the-Code#109 from JiYouMCC/master
Finish 0020
2 parents dbd3162 + 009de1b commit 3f540ad

File tree

31 files changed

+125
-68
lines changed

31 files changed

+125
-68
lines changed

JiYouMCC/0000/0000.png

-2.54 KB
Binary file not shown.

JiYouMCC/0000/0000.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# -*- coding: utf-8 -*-
2-
# 第0000题:将你的QQ头像(或者微博头像)右上角加上红色的数字,类似于微信未读信息数量那种提示。
3-
41
# using PIL in http://www.lfd.uci.edu/~gohlke/pythonlibs/#pillow
52
from PIL import Image
63
from PIL import ImageFont
@@ -19,5 +16,7 @@ def write_number(image_file_path, number=1):
1916
ImageDraw.Draw(img).text((position, 0), number_txt, (255, 0, 0), font)
2017
return img
2118

19+
# need an image '0000.png'
2220
write_number('0000.png').save('result.png')
21+
# if number > 100, shows '99+'
2322
write_number('0000.png', 100).save('result100.png')

JiYouMCC/0000/readme.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
**第 0000 题:**将你的 QQ 头像(或者微博头像)右上角加上红色的数字,类似于微信未读信息数量那种提示效果。
2+
类似于图中效果
3+
4+
![头像](http://i.imgur.com/sg2dkuY.png?1)

JiYouMCC/0001/readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
**第 0001 题:**做为 Apple Store App 独立开发者,你要搞限时促销,为你的应用**生成激活码**(或者优惠券),使用 Python 如何生成 200 个激活码(或者优惠券)?

JiYouMCC/0002/0002.py

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
1-
# -*- coding: utf-8 -*-
2-
# 第 0002 题:将 0001 题生成的 200 个激活码(或者优惠券)保存到 MySQL 关系型数据库中。
31
# using sina app
42
# test page:http://mccatcivitas.sinaapp.com/showmecode2
53
import sae.const
64
import MySQLdb
75
import uuid
86

7+
HOST = sae.const.MYSQL_HOST
8+
USER = sae.const.MYSQL_USER
9+
PASSWD = sae.const.MYSQL_PASS
10+
PORT = int(sae.const.MYSQL_PORT)
11+
CHARSET = 'utf8'
12+
INIT_COMMAND = 'set names utf8'
13+
14+
15+
def make_connection(host=HOST, user=USER, passwd=PASSWD, port=PORT, charset=CHARSET, init_command=INIT_COMMAND):
16+
return MySQLdb.connect(host=host, user=user, passwd=passwd, port=port, charset=charset, init_command=init_command)
17+
918

1019
def create_code(number=200):
1120
result = []
@@ -19,12 +28,7 @@ def create_code(number=200):
1928

2029

2130
def insertCode(code, table='app_mccatcivitas.showmethecode'):
22-
conn = MySQLdb.connect(
23-
host=sae.const.MYSQL_HOST,
24-
user=sae.const.MYSQL_USER,
25-
passwd=sae.const.MYSQL_PASS,
26-
port=int(sae.const.MYSQL_PORT),
27-
charset='utf8')
31+
conn = make_connection()
2832
cur = conn.cursor()
2933
cur.execute("""insert into %s values('%s')""" % (
3034
table, code))
@@ -34,12 +38,7 @@ def insertCode(code, table='app_mccatcivitas.showmethecode'):
3438

3539

3640
def selectCodes(table='app_mccatcivitas.showmethecode'):
37-
connection = MySQLdb.connect(
38-
host=sae.const.MYSQL_HOST,
39-
user=sae.const.MYSQL_USER,
40-
passwd=sae.const.MYSQL_PASS,
41-
port=int(sae.const.MYSQL_PORT),
42-
init_command='set names utf8')
41+
connection = make_connection()
4342
cur = connection.cursor()
4443
cur.execute("""select * from %s""" % (table))
4544
result = []
@@ -50,12 +49,7 @@ def selectCodes(table='app_mccatcivitas.showmethecode'):
5049

5150

5251
def cleanUp(table='app_mccatcivitas.showmethecode'):
53-
connection = MySQLdb.connect(
54-
host=sae.const.MYSQL_HOST,
55-
user=sae.const.MYSQL_USER,
56-
passwd=sae.const.MYSQL_PASS,
57-
port=int(sae.const.MYSQL_PORT),
58-
init_command='set names utf8')
52+
connection = make_connection()
5953
cur = connection.cursor()
6054
try:
6155
cur.execute("""drop table %s""" % (table))

JiYouMCC/0002/readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
**第 0002 题**:将 0001 题生成的 200 个激活码(或者优惠券)保存到 **MySQL** 关系型数据库中。

JiYouMCC/0004/readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
**第 0004 题:**任一个英文的纯文本文件,统计其中的单词出现的个数。

JiYouMCC/0005/0005-r.jpg

-786 KB
Binary file not shown.

JiYouMCC/0005/0005.jpg

-760 KB
Binary file not shown.

JiYouMCC/0005/0005.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# -*- coding: utf-8 -*-
2-
# 第 0005 题:你有一个目录,装了很多照片,把它们的尺寸变成都不大于 iPhone5 分辨率的大小。
31
# using PIL in http://www.lfd.uci.edu/~gohlke/pythonlibs/#pillow
42
from PIL import Image
53

0 commit comments

Comments
 (0)