Skip to content

Instantly share code, notes, and snippets.

View leopard627's full-sized avatar

Leopard627 leopard627

  • South Korea
  • 06:44 (UTC +09:00)
View GitHub Profile
@leopard627
leopard627 / switch.go
Created July 11, 2017 07:40
Switch to another database:
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
@leopard627
leopard627 / tips.go
Created July 8, 2017 06:04
BeeGo Tips
func (c *UserController) GetOne() {
o := orm.NewOrm()
var user models.User
idStr := c.Ctx.Input.Param(":id")
// 만일 파람으로 넘어온 키값으로 얻은 유저이름이 다르거나
// 또는 관리자나 슈퍼유저가 아닌경우에 401에러를 날립니다
// 현재 세션은 메모리로 하기때문에 60초 뒤에 날라감
// mysql로 설정 변경 필요
username := c.GetSession("Username")
@leopard627
leopard627 / getColumn.go
Created July 8, 2017 05:52
Beego Practice..
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)
}// 이런식으로해서
@leopard627
leopard627 / session.go
Created July 5, 2017 14:02
beego session
import (
"github.com/astaxie/beego"
)
func (c *AdminController) Logindo() {
username := c.GetString("username")
c.SetSession("Adminname", username) //设置Session
adminName := c.GetSession("Adminname") //读取Session
c.DelSession("Adminname") //删除Session
c.TplNames = "admin/login.html"
}
@leopard627
leopard627 / main.go
Created June 21, 2017 04:46
go orm expl
package main
import (
"beegoorm/models"
"fmt"
"github.com/astaxie/beego"
"github.com/astaxie/beego/orm"
_ "beegoorm/routers"
_ "github.com/go-sql-driver/mysql"
@leopard627
leopard627 / mock_example2.py
Last active May 25, 2017 08:53
Mocking Functions Using Context Managers
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import unittest
import mock
import pytest
from fots import abc_urandom, my_random
@leopard627
leopard627 / main.py
Last active May 24, 2017 16:02
mocking_master_part1 // python2.7.x 에서 mock.patch를 사용해서 테스트를 유연하게 진행시키는 부분입니다.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
from os import urandom
import mock
import unittest
import pytest
from fots import abc_urandom
@leopard627
leopard627 / mock_example1.py
Created May 24, 2017 13:41
mock_example_python2.7.xx
import unittest
from os import urandom
import mock
def simple_urandom(length):
return 'f' * length
class TestRandom(unittest.TestCase):
@leopard627
leopard627 / stupid_write.py
Last active May 22, 2017 14:33
마지막 테일값에 쓰레기값이 붙습니다만 . . .
a = ['Hello', 'Sydney', 'I', 'Am']
b = [1, 2, 3, -1212.022, 5523, 232441, 1000]
# way 1 방법1
with open("foo.txt", "w") as f:
map(lambda var: f.write(str(var)) if var == b[-1:][0] else f.write(str(var) + " "), b)
# way 2 방법2
with open("foo.txt", "w") as f:
# 보면 이런식으로 여러줄의 라인을 한 줄로 만들 수 있습니다.
# style 1
current_id = return_response.data["id"]
current_banking = LOLOBanking.objects.get(id=current_id)
current_banking.related_id = withdraw_account_id
current_banking.withdraw_type = withdraw_type
current_banking.bank_type = wa.bank_type
current_banking.save