Skip to content

Instantly share code, notes, and snippets.

View KaiserKatze's full-sized avatar
🎯
Focusing

KaiserKatze KaiserKatze

🎯
Focusing
  • MiGo Future Tech Group
  • Chongqing, China
View GitHub Profile
@KaiserKatze
KaiserKatze / json-error-middleware.py
Last active May 13, 2018 14:55
Django middleware, replace builtin error views with customized JsonResponse
# -*- coding: utf-8 -*-
from http import HTTPStatus
from django.http import JsonResponse
class JsonErrorMiddleware:
def __init__(self, get_response):
self.get_response = get_response
@KaiserKatze
KaiserKatze / django_logging_middleware.py
Created May 13, 2018 14:53
Django logging middleware
def _log(request, response):
print('''
General
Request URL: {}
Request Method: {}
Status Code: {}
Remote Address: {}
------------------------------------
Request Headers
Accept: {}
@KaiserKatze
KaiserKatze / futures.py
Last active July 10, 2019 15:07
上海期货交易所历史期货价格数据
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# `pip install requests`
from datetime import datetime, date
from dateutil.rrule import rrule, DAILY
from enum import Enum
import json
@KaiserKatze
KaiserKatze / ipc.c
Last active August 31, 2018 11:42
Linux Inter-process Communication Demo
/***************************************************
*
* Linux Inter-process Communication Demo
*
***************************************************/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @see https://stackoverflow.com/questions/36932/how-can-i-represent-an-enum-in-python
from enum import Enum # for enum34, or the stdlib version
# from aenum import Enum # for the aenum version
Animal = Enum('Animal', 'ant bee cat dog')
# Mapping from enum's value to itself
// Question 35
// Attempt 001
public class Solution {
/*
static class ListNode {
int val;
ListNode next;
ListNode(int x) {
@KaiserKatze
KaiserKatze / AutoTrunc.cpp
Last active December 6, 2020 03:51
C++ Meta Programming Examples
#include <iostream>
#include <type_traits>
#include <atomic>
// Truncate larger integers into smaller ones
template <typename TargetType, typename Integer,
std::enable_if_t<std::conjunction_v<std::is_integral<Integer>, std::is_integral<TargetType>>, int> = 0>
constexpr inline TargetType AutoTrunc(Integer value)
{
@KaiserKatze
KaiserKatze / bows_and_cows.py
Created September 22, 2018 09:14
猜数字
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
Bulls and Cows
'''
import random
class Game:
@KaiserKatze
KaiserKatze / bilispider.py
Last active October 3, 2018 09:23
Spider for Bilibili.com
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
Reference:
- https://github.com/uupers/BiliSpider/wiki/
- https://github.com/Hansimov/bili-comment-analysis
'''
@KaiserKatze
KaiserKatze / checkcaller.py
Last active October 9, 2018 06:39
Python decorator examples
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import functools
import inspect
import os.path
def checkcaller(caller: str = 'package'):
# 限制函数作用域