Skip to content

Instantly share code, notes, and snippets.

@georgefs
georgefs / aesfield.py
Last active December 23, 2015 03:39
simple django 16 byte aes field
from django.db import models
from django.utils.encoding import smart_str
from Crypto.Cipher import AES
import base64
class AESField(models.TextField):
__metaclass__ = models.SubfieldBase
@georgefs
georgefs / copy.vim
Created September 14, 2013 16:12
ubuntu vim copy
python import gtk
python import vim
vmap <silent> <C-C> y:let @0=substitute(@0,"\\","\\\\\\","gi")<CR>:let @0=substitute(@0,"\'","\\\\'","gi")<CR>:python gtk.clipboard_get().set_text('''<C-R>0''')<CR>:python gtk.clipboard_get().store()<CR>
@georgefs
georgefs / gist:6361529
Last active December 21, 2015 20:29
django booleanfield issue

不知道有沒有人會直接用django form fields來做輸入驗證, 不過我是做了..

像是這樣

from django import forms
forms.DateTimeField().clean('2013-02-01')

datetime.datetime(2013, 2, 1, 0, 0)

可以直接幫你把字串解成時間..

@georgefs
georgefs / myip.sh
Last active December 20, 2015 17:49
linux 查對外ip
function myip {
result=`wget -qO- http://myip.is/|grep "The IP used to connect to this webserver is "|sed 's/The IP used to connect to this webserver is//'`
echo $result
}
@georgefs
georgefs / mongo.py
Last active December 19, 2015 17:48
mongodb /etc/init.d script
#! /usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright © 2013 george
#
# Distributed under terms of the MIT license.
__all__ = []
import os
import sys
@georgefs
georgefs / uwsgi.py
Last active December 19, 2015 17:48
管裡開啟uwsgi.ini 的/etc/init.d
#! /usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright © 2013 george
#
# Distributed under terms of the MIT license.
__all__=[]
import os
import sys
import re
@georgefs
georgefs / bash_rc
Created May 14, 2013 01:05
som of my bash rc
pp='ps -aux|grep '
function pk(){
echo kill -9 `ps -aux|grep $1|awk '{print \$2}'`
}
@georgefs
georgefs / advance_search_form_admin.py
Created May 11, 2013 20:54
django advance search form
class FormForAdvancedSearch(forms.Form):
#you can put any field here this is an example so only 1 simple CharField
form_field1 = forms.CharField()
class MyModelAdmin(admin.ModelAdmin):
# the auxiliary search form
advanced_search_form = FormForAdvancedSearch()
# a dictionary of key that will be removed from the GET QueryDict
# this is necessary otherwise ChangeList will complain for malformed
# query string
@georgefs
georgefs / window_fog.vim
Created May 9, 2013 14:29
除了主要編輯視窗都上迷霧0..0 額外付送十字游標喔 lol XD window 開太多 常會找不到現在的編輯區~攤手 找了一下.. vim原生不支援單一window 修改background color.. 只能用這種蠢方法XDDD ColorColumn 的highlight 來模擬了- -+ 雖然不完美但是夠用了~
"height ligth cusor
set t_Co=256
set cursorline
set cursorcolumn
highlight CursorColumn cterm=none ctermbg=236
highlight CursorLine cterm=none ctermbg=236
highlight ColorColumn ctermbg=none ctermbg=240
" Dim inactive windows using 'colorcolumn' setting
" This tends to slow down redrawing, but is very useful.
@georgefs
georgefs / utils.py
Created April 19, 2013 23:39
django view json decoder auto warp status & errormsg
def json_api(func):
def deco(*args, **kwargs):
result = {}
try:
result['status'] = 0
result['msg'] = "success"
result['data'] = func(*args, **kwargs)
except Exception,e:
result['status'] = e.errorno if hasattr(e, 'errorno') else 1