Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added JiYouMCC/0000/0000.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions JiYouMCC/0000/0000.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
# 第0000题:将你的QQ头像(或者微博头像)右上角加上红色的数字,类似于微信未读信息数量那种提示。

# using PIL in http://www.lfd.uci.edu/~gohlke/pythonlibs/#pillow
from PIL import Image
from PIL import ImageFont
from PIL import ImageDraw


def write_number(image_file_path, number=1):
img = Image.open(image_file_path)
font_size = img.size[0] if img.size[0] < img.size[1] else img.size[1]
font_size = font_size / 4
number_txt = str(number) + ' ' if number < 100 else '99+'
font = ImageFont.truetype("arial.ttf", size=font_size)
if font.getsize(number_txt)[0] > img.size[0] or font.getsize(number_txt)[1] > img.size[1]:
return img
position = img.size[0] - font.getsize(number_txt)[0]
ImageDraw.Draw(img).text((position, 0), number_txt, (255, 0, 0), font)
return img

write_number('0000.png').save('result.png')
write_number('0000.png', 100).save('result100.png')
17 changes: 17 additions & 0 deletions JiYouMCC/0001/0001.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# -*- coding: utf-8 -*-
# 做为 Apple Store App 独立开发者,你要搞限时促销,为你的应用生成激活码(或者优惠券),使用 Python 如何生成 200 个激活码(或者优惠券)?

import uuid


def create_code(number=200):
result = []
while True is True:
temp = str(uuid.uuid1()).replace('-', '')
if not temp in result:
result.append(temp)
if len(result) is number:
break
return result

print create_code()
78 changes: 78 additions & 0 deletions JiYouMCC/0002/0002.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# -*- coding: utf-8 -*-
# 第 0002 题:将 0001 题生成的 200 个激活码(或者优惠券)保存到 MySQL 关系型数据库中。
# using sina app
# test page:http://mccatcivitas.sinaapp.com/showmecode2
import sae.const
import MySQLdb
import uuid


def create_code(number=200):
result = []
while True is True:
temp = str(uuid.uuid1()).replace('-', '')
if not temp in result:
result.append(temp)
if len(result) is number:
break
return result


def insertCode(code, table='app_mccatcivitas.showmethecode'):
conn = MySQLdb.connect(
host=sae.const.MYSQL_HOST,
user=sae.const.MYSQL_USER,
passwd=sae.const.MYSQL_PASS,
port=int(sae.const.MYSQL_PORT),
charset='utf8')
cur = conn.cursor()
cur.execute("""insert into %s values('%s')""" % (
table, code))
conn.commit()
cur.close()
conn.close()


def selectCodes(table='app_mccatcivitas.showmethecode'):
connection = MySQLdb.connect(
host=sae.const.MYSQL_HOST,
user=sae.const.MYSQL_USER,
passwd=sae.const.MYSQL_PASS,
port=int(sae.const.MYSQL_PORT),
init_command='set names utf8')
cur = connection.cursor()
cur.execute("""select * from %s""" % (table))
result = []
rows = cur.fetchall()
for row in rows:
result.append(str(row[0]))
return result


def cleanUp(table='app_mccatcivitas.showmethecode'):
connection = MySQLdb.connect(
host=sae.const.MYSQL_HOST,
user=sae.const.MYSQL_USER,
passwd=sae.const.MYSQL_PASS,
port=int(sae.const.MYSQL_PORT),
init_command='set names utf8')
cur = connection.cursor()
try:
cur.execute("""drop table %s""" % (table))
except Exception, e:
print e
connection.commit()
cur.execute(
"""create table %s (code char(32) not null primary key)""" % (table))
connection.commit()
cur.close()
connection.close()


def Process():
cleanUp()
code = create_code()
for c in code:
insertCode(c)
result = selectCodes()
return result
3 changes: 3 additions & 0 deletions JiYouMCC/0003/0003.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-
# 第 0003 题:将 0001 题生成的 200 个激活码(或者优惠券)保存到 Redis 非关系型数据库中。
# fail to install redis, skip it
28 changes: 28 additions & 0 deletions JiYouMCC/0004/0004.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# -*- coding: utf-8 -*-
# 第 0004 题:任一个英文的纯文本文件,统计其中的单词出现的个数。
import io
import operator


def get_count_table(file='0004.txt', ignore=[',', '.', ':', '!', '?', '”', '“', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0'], lower=True):
txt = open(file).read()
for i in ignore:
txt = txt.replace(i, ' ')
if lower:
txt = txt.lower()
words = txt.split(' ')
dic = {}
for word in words:
if word is '':
continue
if word in dic:
dic[word] += 1
else:
dic[word] = 1
return dic


result = sorted(
get_count_table().items(), key=operator.itemgetter(1), reverse=True)
for item in result:
print item[0], item[1]
1 change: 1 addition & 0 deletions JiYouMCC/0004/0004.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Then I looked, and behold, on Mount Zion stood the Lamb, and with him 144,000 who had his name and his Father’s name written on their foreheads.And I heard a voice from heaven like the roar of many waters and like the sound of loud thunder. The voice I heard was like the sound of harpists playing on their harps,and they were singing a new song before the throne and before the four living creatures and before the elders. No one could learn that song except the 144,000 who had been redeemed from the earth.It is these who have not defiled themselves with women, for they are virgins. It is these who follow the Lamb wherever he goes. These have been redeemed from mankind as firstfruits for God and the Lamb,and in their mouth no lie was found, for they are blameless.The Messages of the Three AngelsThen I saw another angel flying directly overhead, with an eternal gospel to proclaim to those who dwell on earth, to every nation and tribe and language and people.And he said with a loud voice, “Fear God and give him glory, because the hour of his judgment has come, and worship him who made heaven and earth, the sea and the springs of water.”Another angel, a second, followed, saying, “Fallen, fallen is Babylon the great, she who made all nations drink the wine of the passion1 of her sexual immorality.”And another angel, a third, followed them, saying with a loud voice, “If anyone worships the beast and its image and receives a mark on his forehead or on his hand,10 he also will drink the wine of God’s wrath, poured full strength into the cup of his anger, and he will be tormented with fire and sulfur in the presence of the holy angels and in the presence of the Lamb.And the smoke of their torment goes up forever and ever, and they have no rest, day or night, these worshipers of the beast and its image, and whoever receives the mark of its name.”Here is a call for the endurance of the saints, those who keep the commandments of God and their faith in Jesus.2And I heard a voice from heaven saying, “Write this: Blessed are the dead who die in the Lord from now on.” “Blessed indeed,” says the Spirit, “that they may rest from their labors, for their deeds follow them!”The Harvest of the EarthThen I looked, and behold, a white cloud, and seated on the cloud one like a son of man, with a golden crown on his head, and a sharp sickle in his hand.And another angel came out of the temple, calling with a loud voice to him who sat on the cloud, “Put in your sickle, and reap, for the hour to reap has come, for the harvest of the earth is fully ripe.”So he who sat on the cloud swung his sickle across the earth, and the earth was reaped.Then another angel came out of the temple in heaven, and he too had a sharp sickle.And another angel came out from the altar, the angel who has authority over the fire, and he called with a loud voice to the one who had the sharp sickle, “Put in your sickle and gather the clusters from the vine of the earth, for its grapes are ripe.”So the angel swung his sickle across the earth and gathered the grape harvest of the earth and threw it into the great winepress of the wrath of God.And the winepress was trodden outside the city, and blood flowed from the winepress, as high as a horse’s bridle, for 1,600 stadia.
Binary file added JiYouMCC/0005/0005-r.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added JiYouMCC/0005/0005.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions JiYouMCC/0005/0005.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# -*- coding: utf-8 -*-
# 第 0005 题:你有一个目录,装了很多照片,把它们的尺寸变成都不大于 iPhone5 分辨率的大小。
# using PIL in http://www.lfd.uci.edu/~gohlke/pythonlibs/#pillow
from PIL import Image


def change_image_size(image_path='0005.jpg', size=(1136, 640)):
im = Image.open(image_path)
size = (size[1], size[0]) if im.size[1] > im.size[0] else size
im.thumbnail(size, Image.ANTIALIAS)
im.save('result-' + image_path)

change_image_size('0005-r.jpg')
change_image_size('0005.jpg')