Skip to content

Instantly share code, notes, and snippets.

@pnck
pnck / consteval_forwarding.cpp
Created April 23, 2024 06:03
if(a==1) return 1 DO MAKE SENSE in C++
// fun thing that `if a==1 f(1);if a==2 f(2)` do make sense in c++
#include <cstdint>
#include <format>
#include <iostream>
#include <string_view>
#include <tuple>
using namespace std;
@pnck
pnck / Klotski.py
Created February 13, 2024 08:31
HGAME2024 WEEK2 华容道 solver
import requests
import numpy as np
import json
port = 31541
class NotMoveable(RuntimeWarning): ...
@pnck
pnck / init.lua
Created January 12, 2024 09:15
GP2015 NodeMCU Codes
gserverip = "192.168.1.253"
gnetwork = "GP2015 Remastered" -- originally "hukouliufang"
gnetkey = "12345678" -- originally "hbLVcyMyrs"
gdebugmode = 1 -- originally 0
function p(m)
print(m)
end
function lmsg(msg)
if (gdebugmode ~= 0) then
p(tmr.now() .. ": " .. msg .. "\n")
@pnck
pnck / vpspanel.go
Last active June 28, 2023 20:39
control warp service through web interface
// Codes in this file is almost written by copilot, which brings lot of fun (it wants to fill "lots of bugs" here :)")
// I only give it prompts, as you can see in the comments
// ---- ACTUAL CODES STARTS HERE ----
// a typical http server program's main file
// use html template to return a interactive page
package main
import (
@pnck
pnck / 01nginx-tls-sni.md
Created June 23, 2023 21:00 — forked from kekru/01nginx-tls-sni.md
nginx TLS SNI routing, based on subdomain pattern

Nginx TLS SNI routing, based on subdomain pattern

Nginx can be configured to route to a backend, based on the server's domain name, which is included in the SSL/TLS handshake (Server Name Indication, SNI).
This works for http upstream servers, but also for other protocols, that can be secured with TLS.

prerequisites

  • at least nginx 1.15.9 to use variables in ssl_certificate and ssl_certificate_key.
  • check nginx -V for the following:
    ...
    TLS SNI support enabled
@pnck
pnck / LspWslFix.ps1
Last active April 15, 2023 08:07 — forked from mariotaku/LspWslFix.ps1
Fix WSL Connection Issue Caused by Winsock
#Requires -RunAsAdministrator
# Fix for https://github.com/microsoft/WSL/issues/4177
$MethodDefinition = @'
[DllImport("ws2_32.dll", CharSet = CharSet.Unicode)]
public static extern int WSCSetApplicationCategory([MarshalAs(UnmanagedType.LPWStr)] string Path, uint PathLength, [MarshalAs(UnmanagedType.LPWStr)] string Extra, uint ExtraLength, uint PermittedLspCategories, out uint pPrevPermLspCat, out int lpErrno);
'@
$Ws2Spi = Add-Type -MemberDefinition $MethodDefinition -Name 'Ws2Spi' -PassThru
@pnck
pnck / webdav1shot.go
Created February 22, 2023 00:43
simplest webdav server
//go run main.go -p 8080
package main
import (
"errors"
"flag"
"fmt"
"log"
"net"
"net/http"
@pnck
pnck / mess_queue.js
Created February 21, 2023 21:22
This gitst shows how complicated writing correct concurrency in go
const maxAlive = 7;
let idAcc = 0;
const idGenerator = () => {
return idAcc++;
}; // can be hashed, accumulator idGenerator is for convenience
let alives = [];
let nonemptyResolver = { resolve: () => {} };
let nonemptyWaiter;
const results = [];
#include <iostream>
#include <type_traits>
#include <vector>
template <typename T>
using get_value_type = typename T::value_type;
std::vector<int> V;
from typing import Tuple, Callable, Dict, Set, List
from functools import reduce, wraps
SIZE = 5
# Triangle shape, central symmetry
# 2 arbitrary axes determin a point
# but we need 3 axes to make it easier to detect boundary conditions
Point = Tuple[int, int, int] # type