Skip to content

Instantly share code, notes, and snippets.

View wention's full-sized avatar

WENTION wention

View GitHub Profile
@wention
wention / unpacking_paramater_pack.cpp
Last active July 22, 2024 08:27
c++ 可变模板参数解包
#include <iostream>
#if __cplusplus < 201700L
// c++11
template<typename... Args>
constexpr int f(Args&&... args) {
int sum = 0;
int arr[] = {(sum+=args, 0)...};
return sum;
@wention
wention / dnsmasq.conf
Created April 19, 2024 06:42
配置 dnsmasq 仅为指定主机分配 IP 地址 / dnsmasq config offer address for whitelist host
# 指定 dnsmasq 监听的接口
#interface=ens160
listen-address=10.1.1.22
# 禁用 DNS 功能
port=0
dhcp-range=10.1.1.0,static,255.255.255.0,1h
# 主机白名单
@wention
wention / has_qdebug_stream_operator.cpp
Last active July 21, 2024 13:41
CPP Check if Type has qdebug stream operator
#include <iostream>
#include <QDebug>
#include <QRectF>
template<typename T, typename = void>
struct has_qdebug_stream_operator : std::false_type {};
template<typename T>
struct has_qdebug_stream_operator<T, std::void_t<decltype(std::declval<QDebug>() << std::declval<T>())>> : std::true_type {};
@wention
wention / install_apps.ps1
Last active October 9, 2023 01:29
Install apps on windows using powershell
# https://aka.ms/vs/17/release/vs_community.exe
.\vs_Community.exe --layout d:\localVSlayout --add Microsoft.VisualStudio.Workload.NativeDesktop --add Microsoft.VisualStudio.Workload.ManagedDesktop --add Microsoft.VisualStudio.Component.VC.140 --add Microsoft.VisualStudio.Component.VC.v141.x86.x64 --add Microsoft.VisualStudio.ComponentGroup.VC.Tools.142.x86.x64 --add Microsoft.VisualStudio.Component.Windows10SDK.19041 --includeRecommended --lang en-US
# install
.\vs_Community.exe --noWeb --add Microsoft.VisualStudio.Workload.NativeDesktop --add Microsoft.VisualStudio.Workload.ManagedDesktop --add Microsoft.VisualStudio.Component.VC.140 --add Microsoft.VisualStudio.Component.VC.v141.x86.x64 --add Microsoft.VisualStudio.ComponentGroup.VC.Tools.142.x86.x64 --add Microsoft.VisualStudio.Component.Windows10SDK.19041 --includeRecommended --addProductLang en-US
@wention
wention / draw_rounded_rect.py
Last active August 24, 2023 01:34
Draw Half Rounded Rectangle Using PyQt5
def draw_rounded_rect(self, painter, rect, x_radius=10, y_radius=10, corners=(1, 1, 1, 1), mode = Qt.AbsoluteSize):
path = QPainterPath()
if mode == Qt.RelativeSize:
x_radius = x_radius / 100 * (rect.width()/2)
y_radius = y_radius / 100 * (rect.height()/2)
x_radius = max(0, min(x_radius, rect.width()/2))
y_radius = max(0, min(y_radius, rect.height()/2))
@wention
wention / multicast_echo.py
Created July 29, 2023 08:22
multicast echo example
import sys
import socket
import struct
def multicast_receive(multicast_group, port):
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.bind(('', port))
group = socket.inet_aton(multicast_group)
@wention
wention / get_myip.py
Created July 25, 2023 07:14
Get My IPAddress
import socket
def get_myip():
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.settimeout(0)
myip = None
try:
# doesn't even have to be reachable
s.connect(('10.254.254.254', 1))
@wention
wention / nginx.conf
Last active July 14, 2023 04:47
HTTP 反向代理与缓存
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
@wention
wention / ssh-copy-id.ps1
Created July 13, 2023 02:26 — forked from elonmallin/ssh-copy-id.ps1
One-liner ssh-keygen and ssh-copy-id for Windows powershell
ssh-keygen && cat $env:userprofile/.ssh/id_rsa.pub | ssh user@linuxserver 'cat >> .ssh/authorized_keys'
@wention
wention / utils.py
Last active July 12, 2023 08:49
Qt Utils
import sys
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
def rect_scale(source, target, aspect=Qt.IgnoreAspectRatio):
"""缩放
source 待缩放