Skip to content

Instantly share code, notes, and snippets.

@tiancheng91
tiancheng91 / start-celery-for-dev.py
Created July 15, 2017 09:52 — forked from chenjianjx/start-celery-for-dev.py
A python script which starts celery worker and auto reload it when any code change happens.
'''
A python script which starts celery worker and auto reload it when any code change happens.
I did this because Celery worker's "--autoreload" option seems not working for a lot of people.
'''
import time
from watchdog.observers import Observer ##pip install watchdog
from watchdog.events import PatternMatchingEventHandler
import psutil ##pip install psutil
import os
@tiancheng91
tiancheng91 / redis_asyncio.py
Created July 5, 2017 03:21 — forked from yihuang/redis_asyncio.py
benchmark gevent vs asyncio on python3.4
import asyncio
import hiredis
d = {}
def process(req):
cmd = req[0].lower()
if cmd==b'set':
d[req[1]] = req[2]
return b"+OK\r\n"
@tiancheng91
tiancheng91 / gspider.py
Created June 5, 2017 06:01 — forked from wolf0403/gspider.py
Gevent Spider
import gevent
import logging
import requests
try:
import simplejson as json
except:
import json
from gevent.pool import Group, Pool
@tiancheng91
tiancheng91 / factory-shared.es5.js
Created June 2, 2017 02:41 — forked from PatrickJS/factory-shared.es5.js
Different examples of OOP "class" with "inheritance" done using JavaScript including languages that transpile into js. Take notice to the amount of boilerplate that's needed in ES5 compared to ES6. These examples all have the same interface with pros/cons for each pattern. If they seem similar that's whole point especially the difference between…
var EventEmitter = require('events').EventEmitter;
var _ = require('lodash');
// Factory shared
var makePerson = function() {
var person = {};
EventEmitter.call(person);
person.wallet = 0;
_.extend(person, personMethods)
return person;
@tiancheng91
tiancheng91 / redsocks.conf
Created November 19, 2016 18:47 — forked from afriza/redsocks.conf
Setup iptables for RedSocks in OpenWRT
base {
// debug: connection progress & client list on SIGUSR1
log_debug = on;
// info: start and end of client session
log_info = on;
/* possible `log' values are:
* stderr
* file:/path/to/file
@tiancheng91
tiancheng91 / promise.js
Created November 4, 2016 01:43 — forked from wavded/promise.js
Promise A+ Implementation
"use strict"
var Promise = function () {
this.state = 'pending'
this.thenables = []
}
Promise.prototype.resolve = function (value) {
if (this.state != 'pending') return
this.state = 'fulfilled'
@tiancheng91
tiancheng91 / shell_bind_tcp.asm
Created November 2, 2016 11:21 — forked from geyslan/shell_bind_tcp.asm
Shell Bind TCP in Assembly (Linux/x86)
; This is a snippet of the original file in https://github.com/geyslan/SLAE/blob/master/1st.assignment/shell_bind_tcp.asm
global _start
section .text
_start:
; syscalls (/usr/include/asm/unistd_32.h)
; socketcall numbers (/usr/include/linux/net.h)
@tiancheng91
tiancheng91 / crawler.py
Created April 21, 2016 08:14 — forked from jmoiron/crawler.py
Simple gevent/httplib2 web crawler.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Simple async crawler/callback queue based on gevent."""
import traceback
import logging
import httplib2
import gevent
@tiancheng91
tiancheng91 / 01_Laravel 5 Simple ACL manager_Readme.md
Created November 13, 2015 01:31 — forked from amochohan/01_Laravel 5 Simple ACL manager_Readme.md
Laravel 5 Simple ACL - Protect routes by an account / role type

#Laravel 5 Simple ACL manager

Protect your routes with user roles. Simply add a 'role_id' to the User model, install the roles table and seed if you need some example roles to get going.

If the user has a 'Root' role, then they can perform any actions.

Installation

Simply copy the files across into the appropriate directories, and register the middleware in App\Http\Kernel.php

@tiancheng91
tiancheng91 / jsonhandler.py
Last active August 29, 2015 14:26 — forked from mminer/jsonhandler.py
A JSON request handler for Tornado.
import json
import tornado.web
class JsonHandler(BaseHandler):
"""Request handler where requests and responses speak JSON."""
def prepare(self):
# Incorporate request JSON into arguments dictionary.
if self.request.body:
try: