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
33 changes: 33 additions & 0 deletions Mr.Lin/0000/0000.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Author: 30987
# @Date: 2015-01-12 16:06:03
# @Last Modified by: 30987
# @Last Modified time: 2015-01-12 17:03:30
#将你的 QQ 头像(或者微博头像)右上角加上红色的数字,类似于微信未读信息数量那种提示效果。

from PIL import Image, ImageDraw, ImageFont
class Image_unread_message:
def open(self,path):
self.im=Image.open(path)
return True
def __init__(self):
self.fnt=None
self.im=None

def setFont(self,font_path,size):
self.fnt=ImageFont.truetype(font_path,size)
return True
def draw_text(self,position,str,colour,fnt):
draw=ImageDraw.Draw(self.im)
draw.text(position,str,fill=colour,font=fnt)
self.im.show()
self.im.save(str+'num'+'.jpg')
return True


test=Image_unread_message()
test.open('1.png')
test.setFont('ahronbd.ttf',80)
test.draw_text((200,-20),'4',(255,0,0),test.fnt)

Binary file added Mr.Lin/0000/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletions Mr.Lin/0001/0001.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Author: 30987
# @Date: 2015-01-12 17:03:52
# @Last Modified by: 30987
# @Last Modified time: 2015-01-12 17:21:29

#第 0001 题:做为 Apple Store App 独立开发者,你要搞限时促销,为你的应用生成激活码(或者优惠券),使用 Python 如何生成 200 个激活码(或者优惠券)?


import uuid

def creat_code(number=10):
result =[]

while True is True:
uuid_id=uuid.uuid1()
tem = str(uuid_id).replace('-','')
tmmmm=str(tem[4:])
if not tmmmm in result:
result.append(tmmmm)
if len(result) is number:
break
print result

creat_code()
43 changes: 43 additions & 0 deletions Mr.Lin/0002/0002.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Author: 30987
# @Date: 2015-01-12 17:22:35
# @Last Modified by: 30987
# @Last Modified time: 2015-01-12 22:33:53

#第 0002 题:将 0001 题生成的 200 个激活码(或者优惠券)保存到 MySQL 关系型数据库中。

import uuid
import MySQLdb

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

def coont_db(result):
num = len(result)
db= MySQLdb.connect('localhost','root','','python',charset='utf8')
cur = db.cursor()

try:
db= MySQLdb.connect('localhost','root','','python',charset='utf8')
cur = db.cursor()
print "OK"
for i in xrange(num):
cur.execute('insert into code (code_num) values("%s")' % (result[i]))
db.commit()
except:
print "数据库连接错误!"
db.rollback()
db.close()



if __name__ == '__main__':
coont_db(creat_code())
25 changes: 25 additions & 0 deletions Mr.Lin/0004/0004.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Author: 30987
# @Date: 2015-01-12 22:58:23
# @Last Modified by: 30987
# @Last Modified time: 2015-01-12 23:09:12

#第 0004 题:任一个英文的纯文本文件,统计其中的单词出现的个数。

def word_count(file_path):
file = open(file_path,'r')
num = 0
file.read()
for line in file:
line_list = line.split()
#print line_list
num += len(line_list)
file.close()
return num

if __name__ == '__main__':
try:
print 'The total number of words is :',word_count('test.txt')
except Exception, e:
print "Can't open file!"
26 changes: 26 additions & 0 deletions Mr.Lin/0004/test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Why are my contributions not showing up on my profile?


Contributions that are counted
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.
Issues and pull requests

Issues and pull requests will appear on your contributions graph if they meet both of these conditions:

They were opened within the past year.
They were opened in a standalone repository, not a fork.
Commits

Commits will appear on your contributions graph if they meet all of the following conditions:

The commits were made within the past year.
The email address used for the commits is associated with your GitHub account.
The commits were made in a standalone repository, not a fork.
The commits were made:
In the repository's default branch (usually master)
In the gh-pages branch (for repositories with Project Pages sites)
In addition, at least one of the following must be true:

You are a collaborator on the repository or are a member of the organization that owns the repository.
You have forked the repository.
You have opened a pull request or issue in the repository.
21 changes: 21 additions & 0 deletions Mr.Lin/0005/0005.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Author: 30987
# @Date: 2015-01-13 10:50:36
# @Last Modified by: 30987
# @Last Modified time: 2015-01-13 11:11:35
# 第 0005 题:你有一个目录,装了很多照片,把它们的尺寸变成都不大于 iPhone5 分辨率的大小

from PIL import Image


def change_img(path,size=(1136,640)):
im = Image.open(path)
size=(size[1],size[0]) if im.size[1]>im.size[0] else size
im.thumbnail(size,Image.ANTIALIAS) #后一个参数为滤镜
im.save('result-'+path)
#im.show()


if __name__ == '__main__':
change_img('1.jpg')
Binary file added Mr.Lin/0005/1.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 Mr.Lin/0005/Thumbs.db
Binary file not shown.
Binary file added Mr.Lin/0005/result-1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 31 additions & 0 deletions Mr.Lin/0006/0006.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Author: 30987
# @Date: 2015-01-13 11:11:49
# @Last Modified by: 30987
# @Last Modified time: 2015-01-13 17:10:27

import re

def hot_words(file_path):
file = open(file_path,'r')
file_content = file.read()
p = re.compile(r'[\W\d]*')
word_list = p.split(file_content)

word_dict = {}
for word in word_list:
if word not in word_dict:
word_dict[word] = 1
else:
word_dict[word] += 1
sort = sorted(word_dict.items(), key=lambda e: e[1], reverse=True)
sort = sorted(word_dict.items(), key=lambda e: e[1], reverse=True)

print("The most word in '%s' is '%s',it appears '%s' times" % (file_path,sort[1][0], sort[1][1]))

file.close()


if __name__ == '__main__':
hot_words('test.txt')
26 changes: 26 additions & 0 deletions Mr.Lin/0006/test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Why are my contributions not showing up on my profile?


Contributions that are counted
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.
Issues and pull requests

Issues and pull requests will appear on your contributions graph if they meet both of these conditions:

They were opened within the past year.
They were opened in a standalone repository, not a fork.
Commits

Commits will appear on your contributions graph if they meet all of the following conditions:

The commits were made within the past year.
The email address used for the commits is associated with your GitHub account.
The commits were made in a standalone repository, not a fork.
The commits were made:
In the repository's default branch (usually master)
In the gh-pages branch (for repositories with Project Pages sites)
In addition, at least one of the following must be true:

You are a collaborator on the repository or are a member of the organization that owns the repository.
You have forked the repository.
You have opened a pull request or issue in the repository.
33 changes: 33 additions & 0 deletions Mr.Lin/0007/0000.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Author: 30987
# @Date: 2015-01-12 16:06:03
# @Last Modified by: 30987
# @Last Modified time: 2015-01-12 17:03:30
#将你的 QQ 头像(或者微博头像)右上角加上红色的数字,类似于微信未读信息数量那种提示效果。

from PIL import Image, ImageDraw, ImageFont
class Image_unread_message:
def open(self,path):
self.im=Image.open(path)
return True
def __init__(self):
self.fnt=None
self.im=None

def setFont(self,font_path,size):
self.fnt=ImageFont.truetype(font_path,size)
return True
def draw_text(self,position,str,colour,fnt):
draw=ImageDraw.Draw(self.im)
draw.text(position,str,fill=colour,font=fnt)
self.im.show()
self.im.save(str+'num'+'.jpg')
return True


test=Image_unread_message()
test.open('1.png')
test.setFont('ahronbd.ttf',80)
test.draw_text((200,-20),'4',(255,0,0),test.fnt)

39 changes: 39 additions & 0 deletions Mr.Lin/0007/0007.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Author: 30987
# @Date: 2015-01-14 11:07:02
# @Last Modified by: 30987
# @Last Modified time: 2015-01-14 11:47:11
#第 0007 题:有个目录,里面是你自己写过的程序,统计一下你写过多少行代码。包括空行和注释,但是要分别列出来。
#
#

"""
此处统计的注释行# 并不会将#!/usr/bin/env python # -*- coding: utf-8 -*- 统计在内,同时if __main__里面的注释也不会进行统计


def code_count(code_file):
total_lines = 0
empty_lines = 0
comment_lines = 0

file_object = open(code_file,'r')
for line in file_object:
word_list = line.split()
#print word_list
if word_list == []:
empty_lines += 1
elif word_list[0] == '#':
comment_lines += 1
total_lines += 1

file_object.close()
#print("Total line: %s. Empty lines :%s.Comment lines:%s"% (total_lines,empty_lines,comment_lines))
return total_lines,empty_lines,comment_lines


if __name__ == '__main__':
t,e,c=code_count('0007.py')
print("Total line: %s. Empty lines :%s.Comment lines:%s"%(t,e,c))