Skip to content

Instantly share code, notes, and snippets.

@wongxinjie
wongxinjie / uber.yaml
Created May 12, 2017 00:52 — forked from earth2marsh/uber.yaml
A Swagger YAML specification for Uber's new API
swagger: 2
info:
title: The new Uber API
description: Move your app forward with the Uber API
version: "1.0.0"
host: api.uber.com
schemes:
- https
basePath: /v1
produces:
@wongxinjie
wongxinjie / simple_gridfs_server.py
Created April 17, 2017 02:26 — forked from artisonian/simple_gridfs_server.py
A simple GridFS server built with Flask
from flask import Flask, request, redirect, url_for, make_response, abort
from werkzeug import secure_filename
from pymongo import Connection
from pymongo.objectid import ObjectId
from gridfs import GridFS
from gridfs.errors import NoFile
ALLOWED_EXTENSIONS = set(['txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif'])
DB = Connection().gridfs_server_test
FS = GridFS(DB)
@wongxinjie
wongxinjie / Makefile
Created March 24, 2017 13:30 — forked from playpauseandstop/Makefile
Setup aiohttp web app with Session Middleware to use Redis Storage and run under Gunicorn.
.PHONY: clean distclean install run
ENV ?= env
VENV = $(shell python -c "import sys; print(int(hasattr(sys, 'real_prefix')));")
ifeq ($(VENV),1)
GUNICORN = gunicorn
else
GUNICORN = $(ENV)/bin/gunicorn
endif
import asyncio
import cgi
import re
from datetime import datetime
from asyncio import Queue
import aiohttp
from lxml import etree
from collections import OrderedDict
import csv
import time
@wongxinjie
wongxinjie / async_app.py
Created March 5, 2017 16:22 — forked from zbyte64/async_app.py
Asyncio Views With Django
import asyncio
from django import http
from django.core.urlresolvers import set_script_prefix
from django.utils.encoding import force_str
from django.core.handlers.wsgi import get_script_name
from django_wsgi.handler import DjangoApplication
import logging
import logging
import sys
@wongxinjie
wongxinjie / README.md
Created February 21, 2017 06:38 — forked from jmhobbs/README.md
Delayed queues for RQ.

Example Run

RQ Worker

✪ rqworker --db 10 default high
16:06:30 RQ worker started, version 0.3.7
16:06:30 
16:06:30 *** Listening on default, high...
16:06:49 high: jobs.multiply(5, 2) (2df52ba2-bd32-4849-a8e1-c5241c78b542)
16:06:49 Job OK, result = 10
@wongxinjie
wongxinjie / bobp-python.md
Created December 1, 2016 03:20 — forked from sloria/bobp-python.md
A "Best of the Best Practices" (BOBP) guide to developing in Python.

The Best of the Best Practices (BOBP) Guide for Python

A "Best of the Best Practices" (BOBP) guide to developing in Python.

In General

Values

  • "Build tools for others that you want to be built for you." - Kenneth Reitz
  • "Simplicity is alway better than functionality." - Pieter Hintjens
def ip2int(ip):
ip_parts = ip.split('.')
parts = ip_parts[::-1]
ipsum = 0
for index, part in enumerate(parts):
ipsum += int(part) * (256 ** (index))
return ipsum
def int2ip(integer):
# -*- coding: utf-8 -*-
from pymongo import MongoClient
from bson.objectid import ObjectId
class MClient(object):
def __init__(self, host='localhost', port=27017, db_name=None):
self.client = MongoClient(host=host, port=port)