Skip to content

Instantly share code, notes, and snippets.

@alex8224
alex8224 / download.kt
Last active September 7, 2017 11:27
resume download use kotlin
import java.io.*
import java.net.URL
import java.net.HttpURLConnection as http
data class Response(val status: Int=200, var header: Map<String, List<String>>, var stream: InputStream)
object Request {
private fun method(method:String, url: String, header: Map<String, String>, followRedirect:Boolean=true): Pair<Response, http> {
set -g prefix C-f
unbind C-b
set -g mouse on
bind h select-pane -L
bind l select-pane -R
bind k select-pane -U
bind j select-pane -D
bind v copy-mode
bind C-v run -b "tmux set-buffer \"$(xclip -o -sel clip)\" && tmux paste-buffer"
bind y run -b "tmux show-buffer | xclip -sel clip -i"\; display-message "copy to system"
# -*- coding:utf-8 -*-
from tornado.ioloop import IOLoop
from tornado.web import RequestHandler, Application
class MiddleWare(object):
def process_request(self, handler):
pass
def process_response(self, handler):
pass
@alex8224
alex8224 / green.py
Created December 29, 2015 12:33
greenlet in tornado
# -*- coding:utf-8 -*-
from __future__ import absolute_import
import sys
import greenlet
import socket
import time
from tornado.iostream import IOStream
from tornado.gen import coroutine, Return
from tornado.concurrent import Future
@alex8224
alex8224 / call_in_coroutine.py
Last active December 23, 2015 03:24
call async io function in coroutine
# -*- coding:utf-8 -*-
from tornado.gen import coroutine
from tornado.concurrent import Future
from tornado.ioloop import IOLoop
from tornado.httpclient import AsyncHTTPClient
from functools import wraps, partial
ioloop = IOLoop.instance()
AsyncHTTPClient.configure("tornado.curl_httpclient.CurlAsyncHTTPClient")
httpclient = AsyncHTTPClient()
@alex8224
alex8224 / streamuploader.py
Last active May 5, 2019 06:48
A multipart form parse for tornado
#!/usr/bin/env python
#-*-coding:utf-8 -*-
#
#Author: alex alex8224 at gmail.com
#Create by:2015-08-11 15:50:21
#Last modified:2015-10-10 09:19:05
#Filename:server.py
#Description:
from __future__ import absolute_import
import re
@alex8224
alex8224 / Properties.py
Created November 11, 2015 16:10
禁止PropertyPublisherMeta记录所有子类的字段信息
class PropertyPublisherMeta(type):
"""A metaclass that associates subclasses with Storm L{PropertyRegistry}s.
"""
def __init__(self, name, bases, dict):
if not hasattr(self, "_storm_property_registry"):
self._storm_property_registry = PropertyRegistry()
elif hasattr(self, "__storm_table__") and hasattr(self, "__refbyname__"):
refbyname = getattr(self, "__refbyname__")
@alex8224
alex8224 / Basemode.py
Created November 11, 2015 16:09
根据 storm model 生成 dict
def __iter__(self):
valid_fields = (name for name in dir(self ) if name not in self.exclude_field and (not name.startswith("_")))
for name in valid_fields:
prop = getattr(self, name)
if isinstance(prop, (unicode, int)):
yield name, getattr(self, name)
elif isinstance(prop, datetime):
yield name, str(getattr(self, name))
elif isinstance(prop, Reference):
try:
@alex8224
alex8224 / gist:e77e6bce6cf10884475d
Created May 21, 2015 07:41
inject bytecode into python
import sys
import dis
import inspect
from byteplay import *
def wearedcode(fcode):
c = Code.from_code(fcode)
if c.code[1] == (LOAD_CONST, 'alex'):
return fcode