Skip to content

Commit acf280a

Browse files
committed
Merge pull request Show-Me-the-Code#154 from messyidea/master
complete 0000 and 0001
2 parents 4c78c5c + d9edf0e commit acf280a

File tree

12 files changed

+128
-0
lines changed

12 files changed

+128
-0
lines changed

messyidea/0000/0000.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# -*- coding: utf-8 -*-
2+
import Image, ImageDraw, ImageFont
3+
4+
org = Image.open('./origin.jpg')
5+
draw = ImageDraw.Draw(org)
6+
w, h = org.size
7+
fontsize = min(w, h) / 4
8+
font = ImageFont.truetype('GenBkBasI.ttf', fontsize)
9+
draw.text((w - fontsize, 0), '3', font = font, fill = (255, 0, 0))
10+
org.save('rst.jpg', 'jpeg')

messyidea/0000/GenBkBasI.ttf

260 KB
Binary file not shown.

messyidea/0000/origin.jpg

16.6 KB
Loading

messyidea/0000/rst.jpg

8.6 KB
Loading

messyidea/0001/0001.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# -*- coding: utf-8 -*-
2+
import uuid
3+
4+
def gen( num):
5+
assert isinstance(num, int) == True
6+
assert num > 0
7+
rst = []
8+
while True:
9+
temp = str(uuid.uuid1()).replace('-', '')
10+
if temp not in rst:
11+
rst.append(temp)
12+
num = num - 1
13+
if num == 0:
14+
break
15+
return rst
16+
17+
rst = gen(200)
18+
for i in rst:
19+
print i

messyidea/0002/0002.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# -*- coding: utf-8 -*-
2+
import uuid
3+
import MySQLdb
4+
5+
def gen( num):
6+
assert isinstance(num, int) == True
7+
assert num > 0
8+
rst = []
9+
while True:
10+
temp = str(uuid.uuid1()).replace('-', '')
11+
if temp not in rst:
12+
rst.append(temp)
13+
num = num - 1
14+
if num == 0:
15+
break
16+
return rst
17+
18+
rst = gen(200)
19+
for i in rst:
20+
print i
21+
22+
try:
23+
conn=MySQLdb.connect(host='localhost',user='root',passwd='root',port=3306)
24+
cur=conn.cursor()
25+
26+
cur.execute('create database if not exists Activation_code')
27+
conn.select_db('Activation_code')
28+
cur.execute('create table code(id int,uuid varchar(50))')
29+
30+
for i in range(len(rst)):
31+
cur.execute('insert into code values(%s,%s)',(i ,rst[i]))
32+
33+
conn.commit()
34+
cur.close()
35+
conn.close()
36+
37+
except MySQLdb.Error,e:
38+
print "Mysql Error %d: %s" % (e.args[0], e.args[1])
39+
40+

messyidea/0003/0003.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# -*- coding: utf-8 -*-
2+
import uuid
3+
import redis
4+
5+
def gen( num):
6+
assert isinstance(num, int) == True
7+
assert num > 0
8+
rst = []
9+
while True:
10+
temp = str(uuid.uuid1()).replace('-', '')
11+
if temp not in rst:
12+
rst.append(temp)
13+
num = num - 1
14+
if num == 0:
15+
break
16+
return rst
17+
18+
rst = gen(200)
19+
20+
r = redis.Redis(host='127.0.0.1', port=6379, db=0)
21+
22+
prefix = 'active'
23+
24+
for i in rst:
25+
r.set('%s_%s' % (prefix, i), i)
26+
print i
27+
28+
show = r.keys('*')
29+
30+
for i in show:
31+
print r.get(i)

messyidea/0004/0004.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env python
2+
# coding=utf-8
3+
4+
filename = 'input.txt'
5+
dict = {}
6+
f = open(filename, 'r')
7+
for eachLine in f:
8+
temp = eachLine.split()
9+
for i in temp:
10+
if i not in dict:
11+
dict[i] = 1
12+
else:
13+
dict[i] += 1
14+
15+
#print dict
16+
for key in dict:
17+
print key, dict[key]

messyidea/0004/input.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
a a b sd ad xs c c
2+
s t ff ss s
3+
f t ss s

messyidea/0005/0005.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env python
2+
# coding=utf-8
3+
4+
from PIL import Image
5+
6+
org = Image.open('./origin.jpg')
7+
org = org.resize((50,50), Image.ANTIALIAS)
8+
org.save('rst', 'jpeg')

0 commit comments

Comments
 (0)