This file contains 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
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)" |
This file contains 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
#!/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): |
This file contains 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
# 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) | |
) |
This file contains 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
git config --global http.proxy 'socks5://127.0.0.1:1080' | |
git config --global https.proxy 'socks5://127.0.0.1:1080' |
This file contains 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
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 |
This file contains 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
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) |
This file contains 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
class CustomAdmin(admin.ModelAdmin): | |
def get_readonly_fields(self, request, obj=None): | |
# ... | |
return [f.name for f in self.model._meta.fields] |
This file contains 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
# 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 ' |
This file contains 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
RAVEN_CONFIG = { | |
'dsn': '<your-dsn-here>', | |
} | |
LOGGING = { | |
'version': 1, | |
'disable_existing_loggers': True, | |
'root': { | |
'level': 'WARNING', | |
'handlers': ['sentry'], |
This file contains 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
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]) |
NewerOlder