Skip to content

Instantly share code, notes, and snippets.

ls0f

Block or report user

Report or block ls0f

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@ls0f
ls0f / gist:9222088
Created Feb 26, 2014
login_required for tornado
View gist:9222088
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):
View gist:b80e3f3dbb5d9ad61797
import unittest
class Test():
def sub(self,*args):
return sum(args)
def bigThan5(self,x):
if x>5:
View gist:8a5cf72d881199852ce5
# coding:utf-8
# opt parse
from optparse import OptionParser
class Test():
def sum(self,*args):
print "sum method"
print "result is",sum(args)
@ls0f
ls0f / gist:8be68a3266601f872832
Last active Aug 29, 2015
tornado hack static url in template html
View gist:8be68a3266601f872832
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
View rust guess game
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 }
}
View block-ip.py
#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
View gist:85817aaedbabea7e6cf6
#!/usr/local/bin/lua
function producer()
return coroutine.create(function()
while true do
local line = io.read()
coroutine.yield(line)
end
end)
end
@ls0f
ls0f / python-producer-consumer.py
Last active Aug 29, 2015
python-producer-consumer
View python-producer-consumer.py
import sys
def producer():
while True:
line = sys.stdin.readline()
yield line
def consumer(p):
line = p.next()
@ls0f
ls0f / lua
Created Aug 6, 2015
lua-yeild-http
View lua
#!/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
@ls0f
ls0f / python-yield-socket.py
Last active Aug 29, 2015
python-yield-http.py
View python-yield-socket.py
#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):
You can’t perform that action at this time.