Skip to content

Instantly share code, notes, and snippets.

// gcc server.c -O2 -lhttpapi -o server
#define WIN32_LEAN_AND_MEAN
#include <stdio.h>
#include <stdlib.h>
#include <http.h>
#include <windows.h>
#include <signal.h>
@imba-tjd
imba-tjd / AutoRemove-NetFirewallRule.ps1
Created March 3, 2023 04:22
Auto remove invalid Windows Firewall rules
# 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"
@imba-tjd
imba-tjd / Readme.md
Last active February 14, 2023 01:50
Call UWP / WinRT API from Win32 without installing Windows SDK
@imba-tjd
imba-tjd / xargsu2a.cs
Last active July 8, 2023 13:54
A program helps pwsh to read from utf8 output.
// 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)
{
// 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;
@imba-tjd
imba-tjd / realpath.go
Last active February 2, 2023 03:21
realpath.exe for windows
// 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"
// 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")]
@imba-tjd
imba-tjd / ngenize.cs
Last active February 22, 2023 12:31
A wrapper for ngen.exe
// 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";
@imba-tjd
imba-tjd / check.c
Created January 11, 2023 10:45
SQLite Device Characteristics Check
/* 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
@imba-tjd
imba-tjd / mi-ftp-open.cs
Last active March 6, 2023 13:10
快速打开我的小米的FTP
// csc mi-ftp-open.cs /o /t:winexe
using System.Net.Sockets;
using System.Threading.Tasks;
using System.Diagnostics;
using System.Runtime.InteropServices;
class Program
{
static readonly string[] IPList = {
"192.168.0.100", "192.168.0.101", "192.168.0.102", "192.168.0.103", "192.168.0.104",