Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
123 commits
Select commit Hold shift + click to select a range
ceb0229
Finish 0023
JiYouMCC Dec 17, 2014
147b069
Create 0023.md
JiYouMCC Dec 17, 2014
a093547
Finish 0021
JiYouMCC Dec 17, 2014
c41c896
Merge branch 'master' of https://github.com/JiYouMCC/python
JiYouMCC Dec 17, 2014
fec027c
创建了0000.py文件及相关目录。
ddkangfu Dec 17, 2014
5a695d8
Draft for 0024
JiYouMCC Dec 18, 2014
54fc423
第0007题,主要用于程序中空行、注释行、程序代码行,考虑了单行注释和多行注释,并且可以通过增加其中三个对应的字典内容来统计比如c程序代码各行数
burness Dec 18, 2014
c52ac25
multi comment a bug here in c multi comment
burness Dec 18, 2014
c5cafe6
fix a bug in c multi comment in 0007
burness Dec 18, 2014
bd40c1b
Finish 0024
JiYouMCC Dec 18, 2014
b78ac1d
Create 0024.md
JiYouMCC Dec 18, 2014
0355f43
Finish 0022
JiYouMCC Dec 18, 2014
3000e9f
Merge pull request #20 from JiYouMCC/master
horx Dec 19, 2014
3d83489
Merge pull request #19 from burness/master
horx Dec 19, 2014
fbbbeba
Add the solution to 0009
Dec 19, 2014
2c5f6a9
Add the solution to 0008
Dec 20, 2014
4d0b5d5
Rename the result image to avoid overwriting the original image
Dec 20, 2014
5296e3b
Merge pull request #21 from renzongxian/master
horx Dec 20, 2014
12b6bf3
Add a blank line in the end
Dec 20, 2014
e56dc5a
Add the problem number in the problem description.
Dec 20, 2014
68bb59d
Merge pull request #22 from renzongxian/master
horx Dec 21, 2014
3554008
add Yixiaohan dir and 0000 solution
Yixiaohan Dec 21, 2014
f57234e
0001 Done.
ddkangfu Dec 21, 2014
4310d50
004
ddkangfu Dec 21, 2014
6f06399
0004 done.
ddkangfu Dec 21, 2014
b88fab3
Add the Solution to 0010.
Dec 21, 2014
eb7a933
Add the Solution to 0011.
Dec 21, 2014
1757753
Add the Solution to 0012.
Dec 22, 2014
2af0731
Add the Solution to 0014.
Dec 22, 2014
5be4828
Add the Solution to 0015.
Dec 22, 2014
f011ea3
0003 done.
ddkangfu Dec 22, 2014
1d55b76
0002 done.
ddkangfu Dec 22, 2014
7a05d95
Merge pull request #24 from renzongxian/master
horx Dec 23, 2014
481473d
Add the Solution to 0016.
Dec 23, 2014
7912fd8
Add the Solution to 0017, but it's not perfect
Dec 23, 2014
9dedd47
Add the Solution to 0017, but it's not perfect
Dec 23, 2014
1d18d69
Some result files
Dec 23, 2014
68e964c
Some result files
Dec 23, 2014
19dcb68
Delete result.txt
Dec 23, 2014
9eb7321
Merge pull request #25 from renzongxian/master
horx Dec 24, 2014
e43e29d
first blood
cailurus Dec 24, 2014
c138a9a
deleted the pycharm files
cailurus Dec 24, 2014
4c5fb0c
added the 0001
cailurus Dec 24, 2014
bc1a0fa
added gitigore
cailurus Dec 24, 2014
b4cc6e0
deleted ignored files
cailurus Dec 24, 2014
f080ff9
modified the number of codes to 200
cailurus Dec 24, 2014
099bcbc
Merge pull request #26 from ailurus1991/solving
horx Dec 24, 2014
6a7d96a
Add the solution to 0021.
Dec 24, 2014
b5e9813
Change the date in the comment.
Dec 24, 2014
c469927
Add the solution to 0022.
Dec 24, 2014
28f9331
Add the solution to 0013.
Dec 24, 2014
93bddfb
Merge pull request #27 from renzongxian/master
horx Dec 24, 2014
b1f266f
Add the solution to 0023.
Dec 25, 2014
3bf31e2
added 0004
cailurus Dec 25, 2014
a20c48a
Merge pull request #5 from Show-Me-the-Code/master
Dec 25, 2014
9a5e0e0
Merge pull request #29 from renzongxian/master
horx Dec 25, 2014
99a921d
Merge pull request #28 from ailurus1991/solving
horx Dec 25, 2014
ea2e30f
added 0005 and 0006
cailurus Dec 25, 2014
cc73f19
Merge pull request #30 from ailurus1991/solving
horx Dec 26, 2014
a29d8b1
10
cailurus Dec 26, 2014
b84c733
10
cailurus Dec 26, 2014
3f8d7b7
Merge pull request #31 from ailurus1991/solving
horx Dec 26, 2014
fbed0e0
Merge branch 'master' of github.com:Show-Me-the-Code/python
ddkangfu Dec 27, 2014
3ec12ca
added 0004
robot527 Dec 28, 2014
9c03abd
第0008题和第0009题
burness Dec 28, 2014
0104be1
fix 0009 readme.md
burness Dec 28, 2014
d5f3389
fix 0009 readme
burness Dec 28, 2014
17f110a
Merge pull request #32 from robot527/master
horx Dec 28, 2014
4974168
0000 done.
ddkangfu Dec 31, 2014
aaf9b72
Merge branch 'master' of github.com:Show-Me-the-Code/python
ddkangfu Dec 31, 2014
86bfcd2
Merge pull request #33 from ddkangfu/master
horx Jan 1, 2015
76ee6ce
add todolist app
Jan 1, 2015
e1421b1
0005 Done.
ddkangfu Jan 1, 2015
65e15bf
Add a simple solution to 0024.
Dec 28, 2014
269e982
add 0007(count one file omitting multiple-line comment)
robot527 Jan 2, 2015
5482757
count all files
robot527 Jan 2, 2015
ebdfd61
0007 Done.
ddkangfu Jan 2, 2015
d279323
增加了0000, 0005, 0007的题目说明。
ddkangfu Jan 3, 2015
978fea3
Merge pull request #35 from renzongxian/master
horx Jan 3, 2015
8e90287
Merge pull request #34 from defshine/master
horx Jan 3, 2015
f5de2aa
Merge pull request #36 from robot527/master
horx Jan 3, 2015
00c75f9
创建了0000.py文件及相关目录。
ddkangfu Dec 17, 2014
7e5a5a8
0001 Done.
ddkangfu Dec 21, 2014
360acab
004
ddkangfu Dec 21, 2014
b444193
0004 done.
ddkangfu Dec 21, 2014
6ea28cf
0003 done.
ddkangfu Dec 22, 2014
5b43ec4
0002 done.
ddkangfu Dec 22, 2014
e94be2c
10
cailurus Dec 26, 2014
bb83084
10
cailurus Dec 26, 2014
f6ff7c3
added 0004
robot527 Dec 28, 2014
246fb8b
0000 done.
ddkangfu Dec 31, 2014
9365043
add todolist app
Jan 1, 2015
3fd48b0
Add a simple solution to 0024.
Dec 28, 2014
11db6ec
add 0007(count one file omitting multiple-line comment)
robot527 Jan 2, 2015
9895a8b
count all files
robot527 Jan 2, 2015
a329bbb
0011
cailurus Jan 3, 2015
b24fefc
Merge branch 'master' of https://github.com/Show-Me-the-Code/python i…
cailurus Jan 3, 2015
33b9667
Merge pull request #37 from ailurus1991/solving
horx Jan 3, 2015
4d81f45
Merge pull request #38 from burness/master
horx Jan 4, 2015
8285cc1
0011-0013 ok
burness Jan 4, 2015
20060bf
add 0000 problem
PanChuan Jan 4, 2015
c30d193
begin to code with problem 0001
PanChuan Jan 4, 2015
0c00ade
0008 Done.
ddkangfu Jan 4, 2015
af8bccd
0009 Done.
ddkangfu Jan 4, 2015
7686048
Merge pull request #39 from burness/master
horx Jan 5, 2015
0f86b08
make 0000 draftly done
PanChuan Jan 5, 2015
2cab884
Delete mawen.jpg
PanChuan Jan 5, 2015
efb3cdf
make 0000 done
PanChuan Jan 5, 2015
2155c8f
0013 Done.
ddkangfu Jan 5, 2015
4fa5217
0014 Done.
ddkangfu Jan 5, 2015
3552352
Merge pull request #40 from ddkangfu/master
horx Jan 6, 2015
6ff6f06
make 0001 done
PanChuan Jan 6, 2015
d2b9b47
0015 Done.
ddkangfu Jan 6, 2015
d1f26d1
Merge pull request #41 from PanChuan/master
horx Jan 7, 2015
88c6d2f
add 0014-0019
burness Jan 7, 2015
f2a08b0
Merge pull request #42 from burness/master
horx Jan 7, 2015
dddea20
0016 Done.
ddkangfu Jan 7, 2015
883e986
add solution for 0023
Jan 7, 2015
6cbe452
Merge pull request #43 from ddkangfu/master
horx Jan 8, 2015
3de0a9a
Merge pull request #44 from defshine/master
horx Jan 8, 2015
301c11f
fix several bugs
robot527 Jan 10, 2015
7a10790
Merge pull request #45 from robot527/master
horx Jan 11, 2015
a58d659
Delete .DS_Store
horx Jan 11, 2015
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,6 @@ docs/_build/

# PyBuilder
target/

# Mac File
.DS_Store
27 changes: 27 additions & 0 deletions JiYouMCC/0021/0021.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# -*- coding: utf-8 -*-
# 第 0021 题: 通常,登陆某个网站或者 APP,需要使用用户名和密码。密码是如何加密后存储起来的呢?请使用 Python 对密码加密。
import os
from hashlib import sha256
from hmac import HMAC

SALT_LENGTH = 8


def encrypt_password(password, salt=None):
if salt is None:
salt = os.urandom(SALT_LENGTH)
if isinstance(password, unicode):
password = password.encode('UTF-8')
result = password
for i in xrange(8):
result = HMAC(result, salt, sha256).digest()
return salt + result


def validate_password(hashed, input_password):
return hashed == encrypt_password(input_password, salt=hashed[:SALT_LENGTH])


password = 'secret'
encrypt = encrypt_password(password)
print validate_password(encrypt, password)
21 changes: 21 additions & 0 deletions JiYouMCC/0022/0022.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
# 第 0022 题: iPhone 6、iPhone 6 Plus 早已上市开卖。请查看你写得 第 0005 题的代码是否可以复用。
# using PIL in http://www.lfd.uci.edu/~gohlke/pythonlibs/#pillow
# 我承认我是先看到22才看到5的
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')

# ip6
change_image_size(image_path='0005.jpg', size=(1334, 750))

# ip6plus
change_image_size(image_path='0005.jpg', size=(1920, 1080))
17 changes: 17 additions & 0 deletions JiYouMCC/0023/0023.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
第 0023 题: 使用 Python 的 Web 框架,做一个 Web 版本 留言簿 应用。
---------------------------------------

以前在sea上弄过一个差不多的:http://jillyou.sinaapp.com/guest/
不过sea弄django syncdb比较痛苦,所有sql拼接出的
直接django真够傻瓜的……

代码版本用的sqlite3,本地调试的时候用的mysql

'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'guestbook',
'USER': '',
'PASSWORD': '',
'HOST': '',
'PORT': '',
}
Binary file added JiYouMCC/0023/guestbook/db.sqlite3
Binary file not shown.
Empty file.
Empty file.
4 changes: 4 additions & 0 deletions JiYouMCC/0023/guestbook/guestbook/commits/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from django.contrib import admin
from models import Message

admin.site.register(Message)
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations


class Migration(migrations.Migration):
dependencies = []
operations = [
migrations.CreateModel(
name='Message',
fields=[
('id', models.AutoField(
verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('name', models.CharField(max_length=30)),
('message', models.TextField(max_length=65535)),
('date', models.DateTimeField()),
],
options={
},
bases=(models.Model,),
),
]
Empty file.
10 changes: 10 additions & 0 deletions JiYouMCC/0023/guestbook/guestbook/commits/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from django.db import models


class Message(models.Model):
name = models.CharField(max_length=30)
message = models.TextField(max_length=65535)
date = models.DateTimeField()

def __unicode__(self):
return self.name + ':' + self.message[:25]
1 change: 1 addition & 0 deletions JiYouMCC/0023/guestbook/guestbook/commits/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from django.test import TestCase
36 changes: 36 additions & 0 deletions JiYouMCC/0023/guestbook/guestbook/commits/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# -*- coding: utf-8 -*-
from django.shortcuts import render
from django.http import HttpResponse, HttpResponseRedirect
import datetime
from models import Message


def guestbook(request):
try:
name = request.COOKIES["name"]
except:
name = u"这家伙连名字也没有"
return render(request, 'guestbook.html', {'commits': selectTextMsg(), 'name': name})


def guesttalk(request):
response = HttpResponseRedirect("/guest")
if request.method == "GET":
name = request.GET.get('name', '')
commit = request.GET.get('commits', '')
date = datetime.datetime.now()
if len(name) > 0 and len(commit) > 0 and len(name) < 41 and len(commit) < 4096:
response.set_cookie("name", name.encode('utf8'))
insertTextMsg(name, date, commit)
return response


def insertTextMsg(user, date, message):
message = Message(name=user,
message=message,
date=date,)
message.save()


def selectTextMsg():
return Message.objects.all().order_by("-date")
41 changes: 41 additions & 0 deletions JiYouMCC/0023/guestbook/guestbook/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
SECRET_KEY = '+m8si5lo@6467j75%wz#z+cvsxl=)u_c(2-o^&+&^++*-48t$5'
DEBUG = True
TEMPLATE_DEBUG = True
ALLOWED_HOSTS = []
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'guestbook.commits',
)
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
ROOT_URLCONF = 'guestbook.urls'
WSGI_APPLICATION = 'guestbook.wsgi.application'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
LANGUAGE_CODE = 'zh-cn'
TIME_ZONE = 'Asia/Shanghai'
USE_I18N = True
USE_L10N = True
USE_TZ = True
STATIC_URL = '/static/'
TEMPLATE_DIRS = (
os.path.join(BASE_DIR, 'guestbook/template'),
)
25 changes: 25 additions & 0 deletions JiYouMCC/0023/guestbook/guestbook/template/guestbook.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<html>
<head>
<meta charset="utf-8">
<title>简易留言本</title>
</head>
<body>
<h1>简易留言本</h1>
<form action="/guesttalk" method="get">
名字:<input type="text" name="name" maxlength ="40" value="{{ name }}" />
<br>
<textarea name="commits" maxlength="1000" rows="10" cols="80" ></textarea>
<br>
<input type="submit">
<input type="reset">
</form>
<div>
{% for commit in commits %}
<div>
<h3>{{ commit.date|date:"Y-n-j H:i:s" }} {{ commit.name }}</h2>
</div>
<div style="word-break:break-all">{{ commit.message|escape|linebreaks|wordwrap:"75" }}</div>
{% endfor %}
</div>
</body>
</html>
9 changes: 9 additions & 0 deletions JiYouMCC/0023/guestbook/guestbook/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from django.conf.urls import patterns, include, url
from django.contrib import admin
from commits.views import guestbook, guesttalk

urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
url(r'^guest/', guestbook),
url(r'^guesttalk', guesttalk),
)
5 changes: 5 additions & 0 deletions JiYouMCC/0023/guestbook/guestbook/wsgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "guestbook.settings")

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
10 changes: 10 additions & 0 deletions JiYouMCC/0023/guestbook/manage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# -*- coding: utf-8 -*-
import os
import sys

if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "guestbook.settings")

from django.core.management import execute_from_command_line

execute_from_command_line(sys.argv)
8 changes: 8 additions & 0 deletions JiYouMCC/0024/0024.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
第 0024 题: 使用 Python 的 Web 框架,做一个 Web 版本 TodoList 应用。
---------------------------------------------------
![任务列表](https://raw.githubusercontent.com/JiYouMCC/python/master/JiYouMCC/0024/0024.png)

admin/admin
- 无限呆蠢的UI请忽略,这个实在是艺术活儿,原来还想把任务DragDrop到状态下和Jire的Kanban一样,没心思折腾html5了
- 其实还加了duedate和createdate,不高兴整template了,不然弄起来就像any.do似的
- 排序UI不高兴整了,就是Models.orderby的问题
Binary file added JiYouMCC/0024/0024.png
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/0024/todoList/db.sqlite3
Binary file not shown.
10 changes: 10 additions & 0 deletions JiYouMCC/0024/todoList/manage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env python
import os
import sys

if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "todoList.settings")

from django.core.management import execute_from_command_line

execute_from_command_line(sys.argv)
44 changes: 44 additions & 0 deletions JiYouMCC/0024/todoList/static/global.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
label {
width: 50%;
display:inline-block;
text-align: right;
}

h1 {
text-align: center;
}

.helptext {
display: block;
text-align: right;
}

.b {
text-align:center;
}

table {
width: 100%;
text-align: center;
}

tr {
vertical-align:top;
}

.list {
width: 300px;
border-style: solid;
border-width: 1px;
text-align: center;
}

.next,.pre {
display: inline-block;
width:70px;
}

.detail{
display: inline-block;
width:150px;
}
64 changes: 64 additions & 0 deletions JiYouMCC/0024/todoList/templates/process.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<html>
<head>
<title>{{ user_name }}的任务列表</title>
{% load staticfiles %}
<link rel="stylesheet" type="text/css" href="{% static "global.css" %}" />
</head>
<body>
<h1>{{ user_name }}的任务列表</h1>
<div class='helptext'>我不是{{ user_name }}, 我要<a href="logout">退出</a></div>
<form action="/" method="post">
{% csrf_token %}
<table>
<tr>
<th>添加新的任务</th>
</tr>
<tr>
<td>
<input type="text" name="detail" style="width:900px" />
</td>
</tr>
<tr>
<td><input type="submit" value="添加" /></td>
</tr>
</table>
</form>
<table>
<tr>
{% for item in status %}
<th width="300px">{{ item.status }}</th>
{% endfor %}
</tr>
<tr>
{% for item in lists %}
<td width="300px" align="center">
{% for i in item %}
<div class='list'>
{% if not i.status = firststatus %}
<div class='pre'>
<form action="/" method="post">
{% csrf_token %}
<input type="hidden" name="pre" value="{{ i.id }}" />
<input type="submit" value="上一步">
</form>
</div>
{% endif %}
<div class='detail' title='{{ i.createdate|date:"Y-n-j H:i:s" }}'>
{{ i.detail}}
</div>
{% if not i.status = laststatus %}
<div class='next' >
<form action="/" method="post">
{% csrf_token %}
<input type="hidden" name="next" value="{{ i.id }}" />
<input type="submit" value="下一步">
</form>
</div>
{% endif %}
</div>
{% endfor %}
</td>
{% endfor %}
</tr>
</table>
</body>
Loading