This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# vim: fileencoding=utf-8 | |
import sys, time | |
from multiprocessing.pool import ThreadPool | |
from tornado import web, gen, stack_context, httpserver, ioloop, util, options | |
_workers = ThreadPool() | |
def costly_task(n): # a costly task like processing images | |
time.sleep(n) | |
return n |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# vim: fileencoding=utf-8 | |
import time, signal | |
from tornado import web, ioloop, options, httpserver | |
_SHUTDOWN_TIMEOUT = 30 | |
def make_safely_shutdown(server): | |
io_loop = server.io_loop or ioloop.IOLoop.instance() | |
def stop_handler(*args, **keywords): | |
def shutdown(): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#vim: fileencoding=utf-8 | |
import mimetools | |
import itertools | |
class MultiPartForm(object): | |
def __init__(self): | |
self.form_fields = [] | |
self.files = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <string.h> | |
void *__memcpy_glibc_2_2_5(void *, const void *, size_t); | |
asm(".symver __memcpy_glibc_2_2_5, memcpy@GLIBC_2.2.5"); | |
void *__wrap_memcpy(void *dest, const void *src, size_t n) | |
{ | |
return __memcpy_glibc_2_2_5(dest, src, n); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var readline = require('readline'); | |
function main() { | |
readline.createInterface({ | |
input: process.stdin, | |
terminal: false, | |
}).on('line', function(line) { | |
console.log(line); | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; A Church-Numberal is a function, which takes a function f(x) | |
;; as its argument and returns a new function f'(x). | |
;; Church-Numerals N applies the function f(x) N times on x. | |
; predefined Church-Numerals 0 to 9 | |
(define zero (lambda (f) (lambda (x) x))) | |
(define one (lambda (f) (lambda (x) (f x)))) | |
(define two (lambda (f) (lambda (x) (f (f x))))) | |
(define three (lambda (f) (lambda (x) (f (f (f x)))))) | |
(define four (lambda (f) (lambda (x) (f (f (f (f x))))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
r"""Command-line tool to validate and pretty-print JSON | |
Usage:: | |
$ echo '{"json":"obj"}' | python -m json.tool | |
{ | |
"json": "obj" | |
} | |
$ echo '{ 1.2:3.4}' | python -m json.tool | |
Expecting property name: line 1 column 2 (char 2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python2.7 | |
import sys | |
import string | |
_usage = """ | |
Please redirect stdin to the input file, redirect stdout to the output file. | |
./subtitute.py ARG1=XXX ARG2=YYY < path_to_input > path_to_output\n | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# .ipa path: /tmp/packapp/com.xxx.${sub_domain}/build/com.xxx.${sub_domain}.app.ipa | |
# required progs: | |
# wget; | |
# python2.7 ./substitute.py; | |
# lockfile; | |
# imagemagick(convert, identify); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- lua-zlib is required | |
local MAX_BODY_SIZE = 16777216 | |
ngx.ctx.max_chunk_size = tonumber(ngx.var.max_chunk_size) or 262144 -- 256KB | |
ngx.ctx.max_body_size = tonumber(ngx.var.max_body_size) or MAX_BODY_SIZE -- 16MB | |
function bad_request_response(status, msg) | |
local message = string.format('{"status": %d, "msg": "%s"}', status, msg) | |
ngx.status = ngx.HTTP_BAD_REQUEST |
OlderNewer