Skip to content

Instantly share code, notes, and snippets.

View bluethon's full-sized avatar
🤣
free

Haibo Jia bluethon

🤣
free
  • Beijing, China
View GitHub Profile
@bluethon
bluethon / install-oh-my-zsh.sh
Created September 7, 2018 08:09 — forked from hewerthomn/install-oh-my-zsh.sh
Offline install of oh-my-zsh on Ubuntu
main() {
# Use colors, but only if connected to a terminal, and that terminal
# supports them.
if which tput >/dev/null 2>&1; then
ncolors=$(tput colors)
fi
if [ -t 1 ] && [ -n "$ncolors" ] && [ "$ncolors" -ge 8 ]; then
RED="$(tput setaf 1)"
GREEN="$(tput setaf 2)"
YELLOW="$(tput setaf 3)"
@bluethon
bluethon / ttc2ttf.py
Created July 17, 2018 09:21 — forked from johnko/ttc2ttf.py
ttc2ttf
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#First released as C++ program by Hiroyuki Tsutsumi as part of the free software suite “Beer”
#I thought porting it to Python could be both a challenge and useful
from sys import argv, exit, getsizeof
from struct import pack_into, unpack_from
def ceil4(n):
# in env.py
from sqlalchemy.ext.compiler import compiles
from alembic.ddl.base import AddColumn, alter_table, add_column
@compiles(AddColumn)
def visit_add_column(element, compiler, **kw):
sql = "%s %s" % (
alter_table(compiler, element.table_name, element.schema),
add_column(compiler, element.column, **kw)
)
@bluethon
bluethon / git_proxy_socks5.sh
Created January 18, 2017 08:25
设置git使用socks5代理
git config --global http.proxy 'socks5://127.0.0.1:1080'
git config --global https.proxy 'socks5://127.0.0.1:1080'
git config --global https.proxy http://127.0.0.1:1080
git config --global https.proxy https://127.0.0.1:1080
git config --global --unset http.proxy
git config --global --unset https.proxy
npm config delete proxy
class MyModelAdmin(admin.ModelAdmin):
def formfield_for_foreignkey(self, db_field, request, **kwargs):
if db_field.name == "school":
kwargs["queryset"] = School.objects.order_by('name')
return super(MyModelAdmin, self).formfield_for_foreignkey(db_field, request, **kwargs)
class CustomAdmin(admin.ModelAdmin):
def get_readonly_fields(self, request, obj=None):
# ...
return [f.name for f in self.model._meta.fields]
# Changing field 'MyTable.associated'
# db.alter_column(u'data_mytable', 'associated',
# self.gf('django.db.models.fields.IntegerField')()
# )
db.execute(
'ALTER TABLE "data_mytable" '
'ALTER COLUMN "associated" DROP DEFAULT, '
'ALTER COLUMN "associated" DROP NOT NULL, '
'ALTER COLUMN "associated" TYPE INTEGER '
'USING '
RAVEN_CONFIG = {
'dsn': '<your-dsn-here>',
}
LOGGING = {
'version': 1,
'disable_existing_loggers': True,
'root': {
'level': 'WARNING',
'handlers': ['sentry'],
@bluethon
bluethon / django_execute_sql.py
Created October 16, 2016 04:58
django执行SQL语句
from django.db import connection, transaction
cursor = connection.cursor() # 获得一个游标(cursor)对象
cursor.execute('update order_invoiceinfo set type = 1')
transaction.commit() # 提交到数据库
# # 更新操作
# cursor.execute('update other_other2 set name ="李四" where id=%s', [3]) # 执行sql语句
# transaction.commit_unless_managed() # 提交到数据库
# # 查询操作
# cursor.execute('select * from other_other2 where id>%s', [1])