Skip to content

Instantly share code, notes, and snippets.

View reorx's full-sized avatar
YOLO

Xiao Meng reorx

YOLO
View GitHub Profile
@reorx
reorx / sshgfw
Created October 25, 2010 12:42 — forked from fuckgfw/sshgfw
#!/usr/bin/expect
set timeout 60
spawn /usr/bin/ssh -D 7070 -g username@yourserver.com
#这里的 username 为你自己的用户名,yourserver.com 为你自己的服务器域名或ip
expect {
"password:" {
send "password\r"
#将第二个 password 改为你自己的密码
}
@reorx
reorx / xiami_checkin.py
Created June 15, 2011 05:47
xiami auto checkin script
#!/usr/bin/python2.7
#coding=utf-8
import sys
import time
import gzip
import logging
import urllib, httplib
from Cookie import BaseCookie
from StringIO import StringIO
@reorx
reorx / logging_sample.py
Created June 25, 2011 03:25
logging usage
def init_logger():
logger = logging.getLogger()
hdr = logging.FileHandler('xiami.log.txt')
formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
hdr.setFormatter(formatter)
logger.addHandler(hdr)
logger.setLevel(logging.NOTSET)
return logger
# useage #
@reorx
reorx / v2ex_reply.py
Created July 18, 2011 15:13
demo of cross-site request to v2ex (reply to a topic)
#coding=utf-8
import sys
import time
import gzip
import logging
import urllib
from urllib import urlencode
import httplib
from Cookie import BaseCookie
from StringIO import StringIO
@reorx
reorx / mail_threading.py
Created September 19, 2011 17:00
mail_threading
from django.core.mail import send_mail as core_send_mail
from django.core.mail import EmailMultiAlternatives
import threading
class EmailThread(threading.Thread):
def __init__(self, subject, body, from_email, recipient_list, fail_silently, html):
self.subject = subject
self.body = body
self.recipient_list = recipient_list
self.from_email = from_email
@reorx
reorx / demo.py
Created October 5, 2011 07:18
mongodb usage deom
from models import Contact
# 根据条件进行查询
cs = Contact.query(user_id=1) # 返回列表,列表中元素是过core.database.MongoDoc封装的对象
# 添加文档至数据库,返回_id
_id = Contact.create({'user_id':1})
# 根据_id获取MongoDoc对象
_id = ''
@reorx
reorx / prepare_in_handler.py
Created October 10, 2011 08:23
prepare demo
def prepare(self):
"""
watch out _prepare* functions' sequence
NOTE: WITHOUT JUDGING self._finished THERE WILL BE BIG PROBLEMS
"""
self._prepare_debug()
if self._finished: return
self._prepare_mobile()
if self._finished: return
@reorx
reorx / account.py
Created October 21, 2011 06:58
django account signup
import re
from django.http import HttpResponse, HttpResponseRedirect
from django.contrib.auth.models import User
from django.contrib.auth import login as auth_login
from django.contrib.auth import authenticate as auth_authenticate
from utils.viewsbase import render_tpl, ApiBaseError, get_rsrc
def validate(val, p, unique=None):
res = re.search(p, val)
#!/usr/bin/python
#coding=utf8
import sys
from utils import directSelectSort
class Process(object):
def __init__(self, id, priority, schema):
"""
@reorx
reorx / pysimulation_2.py
Created October 28, 2011 04:17
os_memory
#!/usr/bin/python
#coding=utf8
import sys
from utils import directSelectSort, col_decorate, BaseError
class MEMStoreError(BaseError):
pass
class InputError(BaseError):