Skip to content

Instantly share code, notes, and snippets.

@daimon99
daimon99 / serializers.py
Created August 3, 2021 04:19
#django #rest #serializer
class OuSerializer(serializers.ModelSerializer):
class Meta:
model = m.Ou
fields = ['code', 'name', 'full_name', 'p_ou__code', 'memo']
p_ou__code = serializers.SlugRelatedField('code', source='p_ou', read_only=True)
@daimon99
daimon99 / admin.py
Created August 3, 2021 04:12
#django #admin #filter
list_filter = [
('id', RangeNumericFilter),
AutocompleteFilterFactory('摄像头', 'cam_algo__cam'),
AutocompleteFilterFactory('算法', 'cam_algo__algo'),
AutocompleteFilterFactory('通道加载算法', 'cam_algo'),
'source_type',
('created', DateRangeFilter),
]
@daimon99
daimon99 / autolearn.js
Created July 23, 2020 07:32
北京市职业技能提升平台,自动学习脚本
// 功能
// 1. 自动点确定
// 2. 自动点人脸验证的确定
// 3. 播完一集自动播放下一集
// 4. 如果视频中间有锁,会自动从最后一个不是100%的视频开始播放
// 5. 可以重复执行。如果忘了自己执行过没有,就放心的多粘几次吧。
var clickindex = null
if (typeof (run1) == 'undefined') {
var run1 = setInterval(() => {
// 自动确认播放弹窗
@daimon99
daimon99 / killvirus-centos.sh
Last active May 7, 2020 07:06
salt 攻击病毒服务器修复脚本
# centos 修复脚本
ps -elf|grep salt|awk '{print $4}' | xargs kill -9
for i in /var/spool/cron/*;do sed -i "/wget/d" $i;sed -i "/salt/d" $i;done
systemctl stop salt-minion
systemctl disable salt-minion
systemctl stop salt-master
systemctl disable salt-master
@daimon99
daimon99 / move_center
Last active May 24, 2020 02:19
mac sizeup 的替代品,自动按需调节 app 位置 / Mac sizeup alternative
on run {input, parameters}
tell application "Finder"
set screenResolution to bounds of window of desktop
end tell
set screenWidth to item 3 of screenResolution
set screenHeight to item 4 of screenResolution
set theApp to (path to frontmost application as Unicode text)
@daimon99
daimon99 / live_build.py
Created April 21, 2020 07:01
用 watchdog 监听文件变化自动构建 / Auto build monitoring file change with watchdog
import time
import watchdog.events
import watchdog.observers
class Handler(watchdog.events.PatternMatchingEventHandler):
def __init__(self):
# Set the patterns for PatternMatchingEventHandler
watchdog.events.PatternMatchingEventHandler.__init__(self, patterns=['*.rst'],
@daimon99
daimon99 / any.py
Created April 21, 2020 06:40
进入 ipython 调试控制台 / Debug using ipython embed
from IPython import embed;embed()
@daimon99
daimon99 / index.html
Created April 18, 2020 04:25
javascript获取url中的get参数 / javascript get the get param in the url.
function findGetParameter(parameterName) {
var result = null,
tmp = [];
location.search
.substr(1)
.split("&")
.forEach(function (item) {
tmp = item.split("=");
if (tmp[0] === parameterName) result = decodeURIComponent(tmp[1]);
});
@daimon99
daimon99 / admin.py
Created April 15, 2020 04:16
Django admin 的新增和修改页面使用不同的字段 / Different fields for add and change pages in django admin
def get_fields(self, request, obj=None):
if not obj:
# 新增页面的字段
fields = ['name', 'company', 'project']
else:
# 修改页面的字段
fields = super().get_fields(request, obj)
return fields
@daimon99
daimon99 / admin.py
Created April 15, 2020 03:53
Django admin 新建记录页面表单初始值 / Django admin add form initial value
def get_changeform_initial_data(self, request):
init = super().get_changeform_initial_data(request)
init['company'] = get_user_last_company(request.user)
return init