Skip to content

Instantly share code, notes, and snippets.

View ipid's full-sized avatar
😩
Busily Occupied

ipid ipid

😩
Busily Occupied
View GitHub Profile
@ipid
ipid / defer.hpp
Created March 25, 2019 08:40
Simple Scope-guard(defer) implementation under C++17.
#pragma once
#ifndef DEFER_HPP_DEFINED
#define DEFER_HPP_DEFINED
/*
defer.hpp v20190325
Simple Scope-guard(defer) implementation under C++17.
Released under MIT License.
Support: C++17
@ipid
ipid / print_type_name.hpp
Last active April 8, 2019 14:08
Functions to print name of a type, with std::cout. Work under C++14.
#pragma once
#ifndef PRINT_TYPE_NAME_HPP_DEFINED
#define PRINT_TYPE_NAME_HPP_DEFINED
/*
Usage:
void print_type_name<T>() {...}
Print type name of T, exactly the same as declaration.
@ipid
ipid / heap_var.hpp
Last active May 30, 2019 10:58
Define variables on the heap but use them like stack variables. Heap variables have never been so simple to use.
#pragma once
#ifndef HEAP_VAR_HPP
#define HEAP_VAR_HPP
/*
Introduction:
In order not to cause a stack overflow, sometimes you must define
large objects on the heap. But heap variables are somewhat hard to use.
@ipid
ipid / warn-light.cc
Last active January 15, 2020 15:24
Simple warning light flashing in your terminal. Written in C++17 with ncurses.
/*
Simple warning light flashing in your terminal.
Compile with the following arguments:
<YOUR COMPILER> --std=c++17 -O2 -lcurses -o warn-light warn-light.cc
*/
#include <ncurses.h>
#include <stdint.h>
#include <unistd.h>
@ipid
ipid / PrintClassInfo.java
Last active April 3, 2020 10:47
Print class methods and fields info through reflection, as if you were reading source code.
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.*;
import java.util.stream.Collectors;
/**
* Usage:
* <code>
* System.out.print(printInfo(java.time.format.DateTimeFormatter.class));
@ipid
ipid / PythonQuine.py
Last active May 10, 2021 16:20
Python Quine 中文版
# Python 自打印程序示例
# 直接运行本程序,控制台就会输出这个程序本身的代码!
打印内容 = '''# Python 自打印程序示例
# 直接运行本程序,控制台就会输出这个程序本身的代码!
print_content = {引号}{引号}{引号}{替换内容}{引号}{引号}{引号}
print(打印内容.format(引号="'", 替换内容=打印内容))'''
@ipid
ipid / image_converter.py
Created December 17, 2021 12:38
Convert between PIL Image and Numpy while using torchvision
import numpy as np
from PIL import Image
__all__ = (
'image_to_numpy',
'numpy_to_image',
)
IMAGE_MEAN = np.array([0.485, 0.456, 0.406], dtype=np.float32).reshape((3, 1, 1))
IMAGE_STD = np.array([0.229, 0.224, 0.225], dtype=np.float32).reshape((3, 1, 1))
@ipid
ipid / B站视频显示点赞率.user.js
Created January 23, 2022 12:44
用于在 B 站视频播放页显示点赞率、收藏率、P 名的用户脚本。
// ==UserScript==
// @name B站视频显示点赞率
// @namespace https://ipid.me
// @version 0.1
// @description 在视频播放页面显示点赞率(点赞数 / 总播放数)
// @author ipid
// @match *://www.bilibili.com/video/*
// ==/UserScript==
(function () {
@ipid
ipid / dblp 按条件隐藏论文.user.js
Last active October 17, 2022 04:42
隐藏只命中作者的论文,隐藏非 CCF A、CCF B 的论文
// ==UserScript==
// @name dblp 按条件隐藏论文
// @namespace https://ipidkun.com
// @version 0.1
// @description 隐藏只命中作者的论文,隐藏非 CCF A、CCF B 的论文
// @author ipid
// @match *://dblp.org/*
// @match *://*.dblp.org/*
// @match *://dblp.uni-trier.de/*
// @match *://*.dblp.uni-trier.de/*
@ipid
ipid / swas.wg0.server.conf
Created August 19, 2022 11:15
Wireguard DMZ 示例,一条命令让你轻松拥有公网地址。An example of Wireguard DMZ configuration that provides you a public IPv4 address.
[Interface]
Address = 10.0.0.1/24
PrivateKey = ******************************************
ListenPort = 51000
DNS = 223.5.5.5
PostUp = iptables -t nat -F; iptables -t nat -A PREROUTING -p tcp -m multiport --dports 1024:50999,51001:65534 -i eth0 -j DNAT --to-destination 10.0.0.2; iptables -t nat -A PREROUTING -p udp -m multiport --dports 1024:50999,51001:65534 -i eth0 -j DNAT --to-destination 10.0.0.2; iptables -t nat -A POSTROUTING -s 10.0.0.0/24 -o eth0 -j MASQUERADE
PostDown = iptables -t nat -F
[Peer]
AllowedIPs = 10.0.0.2/32