Skip to content

Instantly share code, notes, and snippets.

@dengshuan
dengshuan / __init__.py
Created September 1, 2014 23:27
celery with django 1.3
from __future__ import absolute_import
from .mycelery import app as celery_app
@dengshuan
dengshuan / gbk_utf8_transformation.py
Created May 15, 2014 10:21
Windows/Linux文本文件中文编码乱码问题解决方案
#!/usr/bin/env python
import sys, codecs
def transform(enc1, enc2, f1, f2):
infile = codecs.open(f1, 'rU', enc1)
outfile = codecs.open(f2, 'w', enc2, errors='ignore')
if enc1 == 'utf-8' and enc2 == 'gbk':
for line in infile.readlines():
outfile.write(line[:-1] + '\r\n')
elif enc1 == 'gbk' and enc2 == 'utf-8':
@dengshuan
dengshuan / app.py
Created May 13, 2014 11:18
Upload pictures to qiniu within a flask app
from flask import Flask, jsonify, request, redirect, url_for, render_template
from flask.ext.sqlalchemy import SQLAlchemy
from datetime import datetime
import qiniu.conf, qiniu.rs
import os
app = Flask(__name__)
app.config['DATABASE_FILE'] = 'app.db'
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + app.config['DATABASE_FILE']
app.config['AK'] = 'YOUR QINIU ACCESS KEY'
@dengshuan
dengshuan / app.py
Last active August 29, 2015 14:00
flask-security encrypt_password varies on every load
from flask import Flask, render_template
from flask.ext.sqlalchemy import SQLAlchemy
from flask.ext.security import Security, SQLAlchemyUserDatastore, \
UserMixin, RoleMixin, login_required
from flask.ext.security.utils import encrypt_password, verify_password
# Create app
app = Flask(__name__)
app.config['DEBUG'] = True
app.config['SECRET_KEY'] = 'super-secret'
@dengshuan
dengshuan / ckedit.py
Last active January 29, 2020 20:31 — forked from mrjoes/ckedit.py
Apply ckeditor(WYSIWYG rich text editor) to flask-admin textarea
from flask import Flask
from flask.ext.sqlalchemy import SQLAlchemy
from flask.ext import admin
from wtforms import TextAreaField
from wtforms.widgets import TextArea
from flask.ext.admin.contrib.sqla import ModelView
app = Flask(__name__)
app.config['SECRET_KEY'] = '123456790'
@dengshuan
dengshuan / integrate.c
Last active December 29, 2015 15:29
Speed test for C and pypy and python to calculate integration using Simpson and Trapezoidal method
#include<stdio.h>
#include <math.h>
#include <time.h>
#define rval (-4.0/9)
float f(float x){
return sqrt(x)*log(x);
}
int main(){