Skip to content

Instantly share code, notes, and snippets.

View Ivlyth's full-sized avatar
🎯
Focusing

Ivlyth Ivlyth

🎯
Focusing
View GitHub Profile
@Ivlyth
Ivlyth / import_object
Created January 21, 2015 06:04
import_object [ from tornado ]
def import_object(name):
"""Imports an object by name.
import_object('x') is equivalent to 'import x'.
import_object('x.y.z') is equivalent to 'from x.y import z'.
>>> import tornado.escape
>>> import_object('tornado.escape') is tornado.escape
True
>>> import_object('tornado.escape.utf8') is tornado.escape.utf8
@Ivlyth
Ivlyth / jsdict
Last active August 29, 2015 14:14
Python Js styled dict
# copy from `https://github.com/damonchen/onion/blob/master/onion/utils/_dict.py`
# and `https://github.com/damonchen/onion/blob/master/onion/utils/tools.py`
class JsDict(dict):
def __getattr__(self, key):
try:
v = self[key]
except:
v = None
@Ivlyth
Ivlyth / file_lock_with_nonblocking
Created January 27, 2015 03:10
acquire an exclusive lock on an given fd with non-blocking
import errno
import fcntl
'''
just run this script twice to see different output
'''
'''
`doc string in fcntl.lockf`
When operation is LOCK_SH or LOCK_EX, it can also be bitwise ORed with
@Ivlyth
Ivlyth / pyinstall
Created January 27, 2015 10:00
ubuntu 环境下一些python模块的安装
# ubuntu
# sqlalchemy for python
sudo pip install sqlalchemy
# redis for python
sudo pip install redis
# tornado for python
sudo pip install tornado
# supervisor for python
sudo pip install supervisor
@Ivlyth
Ivlyth / README.md
Last active February 18, 2016 03:53
用tornado+nginx + supervisord 搭建一个简单的文件上传下载, 方便在多服务器间以及与本地间文件拷贝

##上传文件

Web

使用浏览器访问 YOUR.DOMAIN.COM/up , 然后选择文件, 点击上传

Curl

使用命令 curl YOUR.DOMAIN.COM -T *FILE*


@Ivlyth
Ivlyth / cfkj.py
Created January 31, 2015 04:06
在四个方向上打印乘法口诀表
for i in range(1, 10):
for j in range(1, i + 1):
print '%d*%d=%2d' % (i, j, i * j),
print ''
print ''
@Ivlyth
Ivlyth / autossh.py
Created January 31, 2015 04:15
利用 pexpect 模块来实现自动通过堡垒机登陆服务器
#!/usr/bin/env python
# -*- coding:utf8 -*-
'''
Author : myth
Date : 14-12-11
Email : belongmyth at 163.com
'''
import pexpect
import json
@Ivlyth
Ivlyth / install-step
Created February 8, 2015 17:04
install nginx rtmp module and ffmpeg etc
# configure nginx with rtmp module
# about more set headers module - http://wiki.nginx.org/HttpHeadersMoreModule
# get download uri from : https://github.com/openresty/headers-more-nginx-module/tags
wget https://github.com/openresty/headers-more-nginx-module/archive/v0.25.tar.gz
# about rtmp module - https://github.com/arut/nginx-rtmp-module
# fork and clone the repo to localhost
# get nginx
wget http://nginx.org/download/nginx-1.7.9.tar.gz
# remember add module when configure nginx
./configure --with-http_ssl_module --with-http_spdy_module --with-http_realip_module --with-http_addition_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_auth_request_module --with-mail --with-pcre --add-module=/home/myth/workspace/github/nginx-rtmp-module --add-module=/home/myth/software/more_set_headers
@Ivlyth
Ivlyth / kill_processes
Created February 10, 2015 18:00
kill multi processes use ps/awk/kill
ps -ef | grep curl | grep -v grep | awk -F ' ' '{print $2}' | xargs kill -9
@Ivlyth
Ivlyth / template_vars
Created March 3, 2015 08:09
Predefined template variables in pycharm
Predefined template variables
PyCharm comes with a set of predefined template variables.
The available predefined file template variables are:
${PROJECT_NAME} - the name of the current project.
${NAME} - the name of the new file which you specify in the New File dialog box during the file creation.
${USER} - the login name of the current user.
${DATE} - the current system date.