Skip to content

Instantly share code, notes, and snippets.

View haoch's full-sized avatar
🎯
Focusing

Hao Chen haoch

🎯
Focusing
View GitHub Profile
@haoch
haoch / load_env_conf_settings.py
Created October 19, 2012 11:04
django settings : automatically load settings arguments from certain package and set as locals variables
""" Automatically load settings arguments from environment settings and set as locals variables
* os.environ.get('DJANGO_CONF', 'default')
Author : Hao Chen (cn.haochen@gmail.com) """
DJANGO_CONF = os.environ.get('DJANGO_CONF', 'default')
if DJANGO_CONF != 'default':
module = __import__(DJANGO_CONF, globals(), locals(), ['*'])
for k in dir(module):
locals()[k] = getattr(module, k)
@haoch
haoch / webapp.wsgi
Created October 25, 2012 06:17
common wsgi configure file for django application
""" WSGI configure file for django application
Default configure file path: /etc/httpd/conf.d/wsgi.conf """
import os
import sys
## setup path for mod_wsgi
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
# add more path here
@haoch
haoch / qunit_test_bootstrap.html
Created October 29, 2012 10:27
qunit test on bootstrap
<!DOCTYPE HTML>
<html>
<head>
<title>Bootstrap Plugin Test Suite</title>
<!-- jquery -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<!-- qunit -->
<link rel="stylesheet" href="vendor/qunit.css" type="text/css" media="screen" />
@haoch
haoch / ModelFieldResource.py
Created November 1, 2012 11:14
django tastypie : model field resource for django tastypie
#!/usr/bin/env python
# −*− coding: UTF−8 −*−
""" ModelField resources
Author : Hao Chen (hchen9@ebay.com) """
from tastypie.resources import Resource
from tastypie.constants import ALL, ALL_WITH_RELATIONS
from tastypie import fields
@haoch
haoch / CustomJSONSerializer.py
Created November 1, 2012 11:18
django tasypie : custom serializer for fixing some bugs while serializing response on some platform like windows
from tastypie.serializers import Serializer
import json
class CustomJSONSerializer(Serializer):
""" Custom JSON Serializer
Replace the default simplejson.DjangoJSONEncoder in tastypie with json.JSONEncoder
USAGE: avoid json encoding error in django 1.5+
Author: cn.haochen@gmail.com """
@haoch
haoch / socket.py
Created November 1, 2012 16:24
python socket
import socket
import sys
from thread import *
HOST = '' # Symbolic name meaning all available interfaces
PORT = 8888 # Arbitrary non-privileged port
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
print 'Socket created'
@haoch
haoch / CSSStyle.css
Last active October 12, 2015 07:57
code comment style (python,javascript,css,java,...)
/* Name
*
* Description
*
* Created by Hao Chen on 11/04/2012.
* Version 1.0 (c) 2012 __MyCompanyName__.All rights reserved.
* Released under Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0.html.
*/
/* style name
@haoch
haoch / django_orm_sequence_id.py
Created November 2, 2012 10:31
django pull id from oracle sequence id
''' Django ORM don't support to pull id from sequence by default.'''
def update_id(func):
'''A decorator for pulling a data object's ID value out of a
user-defined sequence. This gets around a limitation in
django whereby we cannot supply our own sequence names.'''
def decorated_function(*args):
# Grab a reference to the data object we want to update.
data_object = args[0]
@haoch
haoch / decorator_template.py
Created November 2, 2012 17:35
a general python decorator implementation template
def decorator(function):
''' A general decorator implementation
author : cn.haochen@gmail.com '''
def wraper(*arg,**kargs):
''' actual function logic here '''
# more codes here
# ...
# if calling original function here then the code defined in original function will run
@haoch
haoch / AUTHORS
Created November 2, 2012 18:34
python release template(AUTHORS,CONTRIBUTING.rst,INSTALL,LICENSE,MANIFEST.in,README.rst,setup.cfg,setup.py)
{APP_NAME}was originally created in late 2003 at World Online, the Web division
of the Lawrence Journal-World newspaper in Lawrence, Kansas.
The PRIMARY AUTHORS are (and/or have been):
* Hao Chen <cn.haochen@gmail.com>
More information on the main contributors to Django can be found in
docs/internals/committers.txt.