Skip to content

Instantly share code, notes, and snippets.

Avatar

ipid ipid

  • Beijing University of Posts and Communications
  • Beijing, China
  • Twitter @ipid__
View GitHub Profile
@ipid
ipid / swas.wg0.server.conf
Created Aug 19, 2022
Wireguard DMZ 示例,一条命令让你轻松拥有公网地址。An example of Wireguard DMZ configuration that provides you a public IPv4 address.
View swas.wg0.server.conf
[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
@ipid
ipid / B站视频显示点赞率.user.js
Created Jan 23, 2022
用于在 B 站视频播放页显示点赞率、收藏率、P 名的用户脚本。
View B站视频显示点赞率.user.js
// ==UserScript==
// @name B站视频显示点赞率
// @namespace https://ipid.me
// @version 0.1
// @description 在视频播放页面显示点赞率(点赞数 / 总播放数)
// @author ipid
// @match *://www.bilibili.com/video/*
// ==/UserScript==
(function () {
@ipid
ipid / image_converter.py
Created Dec 17, 2021
Convert between PIL Image and Numpy while using torchvision
View image_converter.py
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 / PythonQuine.py
Last active May 10, 2021
Python Quine 中文版
View PythonQuine.py
# Python 自打印程序示例
# 直接运行本程序,控制台就会输出这个程序本身的代码!
打印内容 = '''# Python 自打印程序示例
# 直接运行本程序,控制台就会输出这个程序本身的代码!
print_content = {引号}{引号}{引号}{替换内容}{引号}{引号}{引号}
print(打印内容.format(引号="'", 替换内容=打印内容))'''
@ipid
ipid / PrintClassInfo.java
Last active Apr 3, 2020
Print class methods and fields info through reflection, as if you were reading source code.
View PrintClassInfo.java
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 / warn-light.cc
Last active Jan 15, 2020
Simple warning light flashing in your terminal. Written in C++17 with ncurses.
View warn-light.cc
/*
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 / heap_var.hpp
Last active May 30, 2019
Define variables on the heap but use them like stack variables. Heap variables have never been so simple to use.
View heap_var.hpp
#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 / print_type_name.hpp
Last active Apr 8, 2019
Functions to print name of a type, with std::cout. Work under C++14.
View print_type_name.hpp
#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 / defer.hpp
Created Mar 25, 2019
Simple Scope-guard(defer) implementation under C++17.
View defer.hpp
#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