This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def login_required(meth): | |
def deal(self): | |
if not self.get_secure_cookie("user"): | |
self.redirect("/user_login/") | |
return | |
return meth(self) | |
return deal | |
class MainHandler(tornado.web.RequestHandler): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding:utf-8 | |
# opt parse | |
from optparse import OptionParser | |
class Test(): | |
def sum(self,*args): | |
print "sum method" | |
print "result is",sum(args) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import unittest | |
class Test(): | |
def sub(self,*args): | |
return sum(args) | |
def bigThan5(self,x): | |
if x>5: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def static_url_patch(): | |
from tornado.template import Template | |
old_generate = Template.generate | |
def hack_generate(self,**kwargs): | |
t = old_generate(self,**kwargs) | |
import re | |
print "hack generate" | |
t = re.sub(r'(?<=[\'|"])/static/',r'http://example.com/static/',t) | |
return t |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::io; | |
use std::rand; | |
use std::cmp::Ordering; | |
fn cmp(a: u32, b: u32) -> Ordering { | |
if a < b { Ordering::Less } | |
else if a > b { Ordering::Greater } | |
else { Ordering::Equal } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#coding: utf-8 | |
import os | |
## block cc攻击 的ip | |
CMD = "netstat -ntup | grep -v SYN |awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -nr" | |
MAX_CONN = 50 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/bin/lua | |
local socket = require "socket" | |
function receive(c) | |
c:settimeout(0) --> 不阻塞 | |
local s,status,partial = c:receive(2^10) | |
if status == "timeout" then | |
coroutine.yield(c) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/bin/lua | |
function producer() | |
return coroutine.create(function() | |
while true do | |
local line = io.read() | |
coroutine.yield(line) | |
end | |
end) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
def producer(): | |
while True: | |
line = sys.stdin.readline() | |
yield line | |
def consumer(p): | |
line = p.next() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#coding:utf-8 | |
# http://stackoverflow.com/questions/2719017/how-to-set-timeout-on-pythons-socket-recv-method | |
# http://stackoverflow.com/questions/16745409/what-does-pythons-socket-recv-return-for-non-blocking-sockets-if-no-data-is-r | |
import select | |
import socket | |
def receive(s): |
OlderNewer