I googled it for a long time and I'm really suprised no one mentioned this.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 当两台电脑都有公网IP,却无法访问时,可能是被防火墙拦截了。inbound filter只允许内部往外部建立连接。 | |
# 想到普通家宽,建立连接后,双方是可以互发消息的,证明网络是通的。而UDP是无连接的,怎么做到收回复呢? | |
# 其实防火墙的原理是检测发出去的五元组,遇到对应的回复就放行传入。 | |
# 从实践上来说,只要双方互发消息,就可以了。这就是“打洞” | |
import socket, time, sys, threading | |
s = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM) | |
s.bind(('::', int(sys.argv[1]))) | |
target = (sys.argv[2], int(sys.argv[3])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://learn.microsoft.com/zh-cn/windows/win32/Http | |
// gcc server.c -Os -Wall -lhttpapi -o server | |
#define WIN32_LEAN_AND_MEAN | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <http.h> | |
#include <windows.h> | |
#include <signal.h> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# needs Admin privilege | |
# TODO: Add -confirm | |
$rules = Get-NetFirewallRule | |
foreach ($rule in $rules) { | |
if ($rule.Name.contains("Query User")) { | |
$filepath = $rule.Name.Substring($rule.Name.Indexof('}')+1) | |
if (-not (Test-Path $filepath)) { | |
echo "Removing $filepath" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This program helps pwsh to read from external program output from utf8 encoding. | |
// Compile: bflat build xargsu2a.cs -Ot --no-debug-info --no-globalization --no-reflection --no-stacktrace-data | |
// License: MIT | |
using System; | |
using System.Diagnostics; | |
using System.Text; | |
if (args.Length == 0) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://github.com/abejfehr/URLDecode | |
// Compile: gcc -Ofast -mtune=native -D__USE_MINGW_ANSI_STDIO -o urld.exe | |
// When decoding UTF8-encoded data, work with [xargsu2a](https://gist.github.com/imba-tjd/0a5a41df029babc6c814efe5d9296593) | |
#include <ctype.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <stdio.h> | |
char *urlDecode(const char *str) { | |
int d = 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Git for Windows or git-bash contains a realpath.exe which is required by git code.editor | |
// However I'm using Git distribution from VS, which doesn't have it. | |
// Copying from Git for Windows isn't a good choice because it needs msys-2.0.dll | |
// This program offers similar function, which is enough for me. | |
// It won't resolve '~'. It works when path contains whitespaces. | |
package main | |
import ( | |
"fmt" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// KP Backuper:帮助解决卡琳典狱长在非最低难度下强制覆盖自动保存的特性。 | |
// 放到与nw.exe同一目录下。运行后每隔一分钟会检测存档有没有发生变化,如果变了,就备份到www/save_bak目录下。 | |
// 并发安全性:读取时会加读锁,因此不会读到一半游戏自动保存导致读取内容错误,副作用是此次游戏的自动保存会不生效(静默失败);但本游戏保存很频繁,因此无影响。对于游戏保存到一半时本程序触发读,本程序会过一秒钟重试。 | |
// 编译:C:\tools\bflat-7.0.1-windows-x64\bflat.exe build KPBackuper.cs -Os --no-globalization --no-reflection --no-stacktrace-data && upx --lzma KPBackuper.exe | |
using System; | |
using System.IO; | |
using System.Threading; | |
using System.Runtime.InteropServices; | |
[DllImport("user32")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// LICENSE: MIT | |
using System; | |
using System.IO; | |
using System.Diagnostics; | |
using System.Reflection; | |
class Ngenize | |
{ | |
const string NgenX86Path = @"C:\Windows\Microsoft.NET\Framework\v4.0.30319\ngen.exe"; | |
const string NgenX64Path = @"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\ngen.exe"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* SQLite Device Characteristics Check | |
Goal: | |
Tell you whether -DSQLITE_ENABLE_ATOMIC_WRITE has benefits on your filesystem. | |
However I don't konw much about sqlite so the logic may not be right. | |
Usage: | |
Download sqlite3 source code. | |
gcc check.c sqlite3.c -DSQLITE_THREADSAFE=0 -DSQLITE_ENABLE_ATOMIC_WRITE -DSQLITE_OMIT_LOAD_EXTENSION |
NewerOlder