Skip to content

Instantly share code, notes, and snippets.

View yaoelvon's full-sized avatar

Alex Feng yaoelvon

  • China
View GitHub Profile
@href
href / dict_namedtuple.py
Created October 27, 2011 12:00
Convert any dictionary to a named tuple
from collections import namedtuple
def convert(dictionary):
return namedtuple('GenericDict', dictionary.keys())(**dictionary)
"""
>>> d = dictionary(a=1, b='b', c=[3])
>>> named = convert(d)
>>> named.a == d.a
True
>>> named.b == d.b
@dAnjou
dAnjou / flask-upload
Created June 5, 2012 12:35
Flask upload example
<VirtualHost *>
ServerName example.com
WSGIDaemonProcess www user=max group=max threads=5
WSGIScriptAlias / /home/max/Projekte/flask-upload/flask-upload.wsgi
<Directory /home/max/Projekte/flask-upload>
WSGIProcessGroup www
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
@alexanderjulo
alexanderjulo / celery.py
Created September 1, 2012 11:34
with request context decorator
class with_request_context(object):
def __init__(self, f, app=None, request=None):
self.f = f
if app:
self.app = app
else:
self.app = www
if request:
self.request = request
@catermelon
catermelon / config.py
Created October 4, 2013 15:49
Flask-SQLAlchemy - separating reads and writes
# This is not used unless SQLALCHEMY_BINDS is not present
SQLALCHEMY_DATABASE_URI = 'mysql+pymysql://{username}:{password}@{hostname}/{database}?charset=utf8'
SQLALCHEMY_BINDS = {
'master': 'mysql+pymysql://{username}:{password}@{hostname}/{database}?charset=utf8',
'slave': 'mysql+pymysql://{username}:{password}@{hostname}/{database}?charset=utf8'
}
@bstees
bstees / abbreviate_ipv6.js
Last active July 13, 2019 03:13
Abbreviates full IPv6 addresses by removing the leading "0" and collapsing longest consecutive run of 16-bit zeros down to "::".
/* Abbreviate full ipv6 address
* By Brent Stees (http://facebook.com/brent.stees), 2014
* MIT Licenced, see http://www.opensource.org/licenses/mit-license.php */
function abbreviate_ipv6(ip){
if(ip.indexOf("::") == -1) {
// needs to be abbreviated
// remove leading zeros
@jamespan
jamespan / dockerfile-hexo
Last active July 11, 2019 04:37
A Dockerfile for Hexo 3.0
FROM ubuntu:14.04
MAINTAINER Pan Jiabang, panjiabang@gmail.com
RUN \
# use aliyun's mirror for better download speed
sed -i 's/archive.ubuntu.com/mirrors.aliyun.com/g' /etc/apt/sources.list && \
apt-get update && \
apt-get install -y nodejs curl git-core && \
# use nodejs as node
@imwilsonxu
imwilsonxu / app.py
Last active May 13, 2019 03:41
[极验验证 + 云片短信 + Flask + WTForms] #flask
# -*- coding: utf-8 -*-
import re, requests, httplib, urllib, json
from flask import Flask, render_template, session, request, jsonify, current_app
from flask_wtf import Form
from wtforms import Field, StringField, SubmitField
from wtforms.validators import DataRequired, Regexp
from wtforms.widgets import TextInput, HTMLString