Skip to content

Instantly share code, notes, and snippets.

View leafsummer's full-sized avatar
🎯
Focusing

LeafSummer leafsummer

🎯
Focusing
View GitHub Profile
@leafsummer
leafsummer / simpleftp.py
Last active August 29, 2015 14:05
简单的ftp文件上传和下载
#!/usr/bin/python
# -*- coding:utf-8 -*-
#this script is used to do some operations more convenient via ftp
#1.[p]upload many files in the same time,show md5s
#2.[g]download many files in the same time,show md5s
#3.[l]list all the files on ftp site
#4.[f]search a file on ftp site,return True or Flase
#5.[h]show help info
#add upload and download operations 20111210 version0.1
@leafsummer
leafsummer / thread_timeout.py
Last active August 29, 2015 14:19
设置一个python进程的超时,可以通过父子线程或者进程的方式实现
#!/usr/bin/env python
# -*- coding: utf-8 -*-
__all__ = ['timeout']
import ctypes
import functools
import threading
@leafsummer
leafsummer / simple_httpserver.js
Created July 7, 2015 10:04
nodejs, create a simple http server
var http = require('http');
http.createServer(function(req, res){
res.wirteHead(200, {'Content-Type': 'text/html'});
res.wirte('<h1>Node.js</h1>');
res.end('<p>Hello World</p>');
}).listen(3000);
console.log("HTTP Server is lisetening at port 3000.");
@leafsummer
leafsummer / parse_postrequest.js
Last active August 29, 2015 14:24
nodejs, parse post request (simple example)
var http = require('http');
var querystring = require('querystring');
var server = http.createServer(function(req, res){
var post = '';
req.on('data', function(chunk){
post += chunk;
});
@leafsummer
leafsummer / service.conf
Created July 15, 2015 04:55
a simple nginx conf file
server {
listen 8001;
server_name localhost;
charset utf-8;
root /opt/celery_web;
location / {
root /opt/celery_web;
}
location ^~ /choi_wan_api/ {
#add_header 'Access-Control-Allow-Origin' '*';
@leafsummer
leafsummer / nginx_server_conf.conf
Created July 15, 2015 05:52
nginx server conf
server {
listen 443;
charset utf-8;
ssl on;
ssl_certificate /opt/disk2/var/serverconfig/server.cert;
ssl_certificate_key /opt/disk2/var/serverconfig/server.key;
location / {
root /opt/disk2/var/www;
uwsgi_pass 127.0.0.1:9001;
@leafsummer
leafsummer / celeryweb_deploy.sh
Last active August 29, 2015 14:24
static web deploy shell
#!/bin/bash
#celery web deploy
NGINX_CONF=/opt/disk2/var/serverconfig/www-nginx.conf
SVN_USERNAME=""
SVN_PASSWORD=""
CELERY_WEB_SVN=""
WEB_PROJECT_DIR=/opt/disk2/var/www
@leafsummer
leafsummer / modelcachlock.py
Created July 24, 2015 09:29
used cache lock in django
def get_user_events(user_id, appname, new_flag=False):
"""
get the last 7 days events from reportevent table by user_id
param: user_id: the user id, appname: the app name
"""
if new_flag:
starttime = datetime.datetime.combine(datetime.date.today(), datetime.time.min)
else:
starttime = datetime.datetime.combine(datetime.date.today() - datetime.timedelta(days=6),
datetime.time.min)
@leafsummer
leafsummer / downloader_pic.py
Created August 10, 2015 06:59
a downloader of pic with python
# -*- coding: utf-8 -*-
import urllib2
import sys
import time
import os
import random
from multiprocessing.dummy import Pool as ThreadPool
type_ = sys.getfilesystemencoding()
def rename():
@leafsummer
leafsummer / ajax.csrf.js
Created August 11, 2015 11:26
a csrf token with ajax js
$(document).ajaxSend(function(event, xhr, settings) {
function getCookie(name) {
var cookieValue = null;
if (document.cookie && document.cookie != '') {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = jQuery.trim(cookies[i]);
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) == (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));