Skip to content

Instantly share code, notes, and snippets.

View leafsummer's full-sized avatar
🎯
Focusing

LeafSummer leafsummer

🎯
Focusing
View GitHub Profile
@leafsummer
leafsummer / rest_client.py
Last active September 19, 2021 21:48
My share snippets
from restclient import GET, POST
import simplejson as json
import logging
import socket
logger = logging.getLogger('rs.utils.restclient')
class ConnectAPI(object):
'''
all the way of connection web and api server
@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 / daemonize_class.py
Last active May 8, 2021 09:31
daemonize a process class of python script
import os
import sys
import time
import atexit
class Daemon(object):
def __init__(self, pidfile="/dev/null", stdin="/dev/null", stdout="/dev/null", stderr="/dev/null"):
@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 / simple_proxy.py
Last active September 19, 2021 21:48
a proxy class example
def _default_cls_attr(name, type_, cls_value):
# Proxy uses properties to forward the standard
# class attributes __module__, __name__ and __doc__ to the real
# object, but these needs to be a string when accessed from
# the Proxy class directly. This is a hack to make that work.
# -- See Issue #1087.
def __new__(cls, getter):
instance = type_.__new__(cls, cls_value)
instance.__getter = getter