34. 簡易好用的樣板系統
<html>
<body>
{% for a in articles %}
<h1>{{a.title}}</h1>
{{a.body}}
<div>
<div style="text-align: right;">
</div>
</div>
Author: {{a.author}}
</body>
{% endfor %}
</html>
easy and good template system
42. mongo有什麼好吃的?
Schema free
No join
JSON compatible
Python friendly
Horizontal scalability with replica
Fast (& eat all your memory :-P)
Why mongoDB?
43. 用JSON來記錄Blog文章
{
"title": "這是blog title",
"body": "blog文章,很長很長...",
"create": "2012-6-10T10:00:00.000",
"author": "toki"
}
How to describe a blog article in JSON?
44. 用Python dict來記錄Blog文章
{
"title": "這是blog title",
"body": "blog文章,很長很長...",
"create": "2012-6-10T10:00:00.000",
"author": "toki"
}
How to describe it in Python dictionary?
45. 如何存進mongodb (in python)
from pymongo import Connection
a = {
"title": "這是blog title",
"article": "blog文章,很長很長...",
"body": "2012-6-10T10:00:00.000",
"author": "toki"
}
Connection('localhost')['blog']['article'].save(a)
connection database collection
How to save into mongodb via python?
46. 如何搜尋blog文章
from pymongo import Connection
all_article = Connection('localhost')['blog']['article'].
find()
all_article_title = Connection('localhost')['blog']
['article'].find(
{}, {title: 1})
article =
Connection('localhost')['blog']['article'].find_one(
{'author': 'toki'})
How to search?
47. 如果你突然想幫blog加上tag
from pymongo import Connection
Connection('localhost')['blog']['article'].update(
{
{'author': 'toki'},
{'$set': {'tags': ['a', 'b', 'c']}},
}
)
Wanna add tags fields to blog data?
48. 難道mongoDB沒有缺點嗎?
Schema free
Everyone needs to know how schema looks like
每個人都得知道資料長什麼樣子
No join
Waste of space
浪費空間
Fragment
Scheduled defragment maintenance required
需要定時重整資料庫
Cons of mongoDB?
49. 還有該死的BFGL!!!
Write will lock DB globally
寫入動作會鎖住整個資料庫
Solution
解法
Add more RAM
加RAM
Multi DB instance
開多個資料庫
Wait newer version(2.2)
等新版(2.2以後)
And DXXN BFGL(Big Fxxking Global Lock)!!!
52. LoL的通訊協定是....?
● Built by Flash (Adobe AIR)
● RTMPS ( Real Time Message Protocol)
● RTMPS = RTMP + SSL Encryption
● Wrote by Actionscript = Event Driven
What's the protocol of League of Legends?
54. Twisted寫echo server要多久
from twisted.internet import protocol, reactor
class Echo(protocol.Protocol):
def dataReceived(self, data):
self.transport.write(data)
class EchoFactory(protocol.Factory):
def buildProtocol(self, addr):
return Echo()
reactor.listenTCP(1234, EchoFactory())
reactor.run()
How long takes writing echo server in Twisted?
55. 要改成SSL加密版本又要多久?
from twisted.internet import protocol, reactor, ssl
class Echo(protocol.Protocol):
def dataReceived(self, data):
self.transport.write(data)
EchoFactory(protocol.Factory):
class
def buildProtocol(self, addr):
return Echo()
reactor.listenSSL(1234, EchoFactory(),
ssl.DefaultOpenSSLContextFactory('key', 'crt'))
reactor.run()
How long takes to rewrite it to SSL version?
56. Protocol提供了哪些事件?
● connectionMade
連上時要做什麼
● connectionLost
失去連線時要做什麼
● dataReceived
收到資料時要做什麼
What events does Protocol class provide?
57. 其它寫bot會用到的函數
● reactor.callLater()
讓你等下再call某個function
● reactor.callInThread()
讓你在另一個thread call某個function
● task.LoopingCall class
讓你每隔一定時間就去call某個function
Other functions for writing a lol bot
58. 一段簡單的client程式
from twisted.internet import protocol, reactor, task
class SimpleClient(protocol.Protocol):
def dataReceived(self, data):
print data
def connectionMade(self):
self.callLater(3.0, self.send_hello)
def send_nop(self):
self.transport.write('nop')
def send_hello(self):
self.transport.write('hello')
l = task.LoopingCall(self.send_nop)
l.start(1.0)
Simple client code
59. 一段簡單的client程式(續)
class SimpleClientFactory(protocol.ClientFactory):
def buildProtocol(self, addr):
return SimpleClient()
reactor.connectTCP('localhost', 7777,
SimpleClientFactory())
# for SSL support, call below line instead
# reactor.connectSSL('localhost', 7777,
SimpleClientFactory(), ssl.ClientContextFactory())
reactor.run()
Simple client code (continued)
67. 台達電子雲端研發中心徵人中
熱愛寫程式 Love coding
熱愛OSS Love OSS
Familiar with U*ix system is a plus
加分項目
熟U*ix系統 Familiar
Familiar
with
with
Python is a plus
C/C++ is a plus
Familiar with Virtualization is a plus
熟Python Familiar with Web Application is a plus
熟C/C++
熟Virtualization
熟Web Application
請寄履歷至: YVONNE.WJ.CHEN@delta.com.tw
We're hiring (Delta Electronic CTBU)