This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func (this *TestController) Show3() { | |
o := orm.NewOrm() | |
var arc []*models.Archives | |
o.QueryTable("go_archives").Filter("Id__gt", 1).RelatedSel().All(&arc)//使用RelatedSel将关联的arctype也查出来,也就是left join arctype as T1 on T1.id=go_archives.arctype_id | |
arc3 := arc[0] | |
fmt.Println(arc3.Arctype.Typename) | |
}// 이런식으로해서 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func (c *UserController) GetOne() { | |
o := orm.NewOrm() | |
var user models.User | |
idStr := c.Ctx.Input.Param(":id") | |
// 만일 파람으로 넘어온 키값으로 얻은 유저이름이 다르거나 | |
// 또는 관리자나 슈퍼유저가 아닌경우에 401에러를 날립니다 | |
// 현재 세션은 메모리로 하기때문에 60초 뒤에 날라감 | |
// mysql로 설정 변경 필요 | |
username := c.GetSession("Username") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
orm.RegisterDataBase("db1", "mysql", "root:root@/orm_db2?charset=utf8") | |
orm.RegisterDataBase("db2", "sqlite3", "data.db") | |
o1 := orm.NewOrm() | |
o1.Using("db1") | |
o2 := orm.NewOrm() | |
o2.Using("db2") | |
// After switching database |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" Tab navigation like Firefox. | |
nnoremap <C-S-tab> :tabprevious<CR> | |
nnoremap <C-tab> :tabnext<CR> | |
nnoremap <C-t> :tabnew<CR> | |
"""""""""""""""""""""""""""""" | |
" => CTRL-P | |
"""""""""""""""""""""""""""""" | |
let g:ctrlp_working_path_mode = 'ra' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//分页方法,根据传递过来的页数,每页数,总数,返回分页的内容 7个页数 前 1,2,3,4,5 后 的格式返回,小于5页返回具体页数 | |
func Paginator(page, prepage int, nums int64) map[string]interface{} { | |
var firstpage int //前一页地址 | |
var lastpage int //后一页地址 | |
//根据nums总数,和prepage每页数量 生成分页总数 | |
totalpages := int(math.Ceil(float64(nums) / float64(prepage))) //page总数 | |
if page > totalpages { | |
page = totalpages | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
import traceback | |
import colors | |
import sys, getopt | |
def main(argv): | |
flags , port = argv[1].split("=") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Extension of http://www.yilmazhuseyin.com/blog/dev/create-thumbnails-imagefield-django/ | |
# Note: image_folder and thumbnail_folder are both a callable (ie. a lambda that does a '/'.join()) | |
class Image(Media): | |
image = models.ImageField( | |
upload_to=image_folder | |
) | |
thumbnail = models.ImageField( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def info(self): | |
"Return a dictionary with all info on the last response." | |
m = {} | |
m['effective-url'] = self.handle.getinfo(pycurl.EFFECTIVE_URL) | |
m['http-code'] = self.handle.getinfo(pycurl.HTTP_CODE) | |
m['total-time'] = self.handle.getinfo(pycurl.TOTAL_TIME) | |
m['namelookup-time'] = self.handle.getinfo(pycurl.NAMELOOKUP_TIME) | |
m['connect-time'] = self.handle.getinfo(pycurl.CONNECT_TIME) | |
m['pretransfer-time'] = self.handle.getinfo(pycurl.PRETRANSFER_TIME) | |
m['redirect-time'] = self.handle.getinfo(pycurl.REDIRECT_TIME) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def _Read(self, url): | |
'''?????? ??? ? ?????????? ?????''' | |
attemptsCount = 2 | |
for _ in range(attemptsCount): | |
try: | |
buf = cStringIO.StringIO() | |
curl = pycurl.Curl() | |
curl.setopt(pycurl.HTTPHEADER, ["Accept:"]) | |
curl.setopt(pycurl.FOLLOWLOCATION, 1) | |
curl.setopt(pycurl.MAXREDIRS, 5) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" Important: | |
" This requries that you install https://github.com/amix/vimrc ! | |
" | |
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
"""""""""""""""""""""""""""""" | |
" => Load pathogen paths | |
"""""""""""""""""""""""""""""" |