Skip to content

Instantly share code, notes, and snippets.

View WanpengQian's full-sized avatar
👳‍♀️

Wanpeng Qian WanpengQian

👳‍♀️
  • Fukuoka, Japan
View GitHub Profile
@WanpengQian
WanpengQian / nginx_remove_double_slashes.md
Created July 19, 2022 02:03 — forked from JustThomas/nginx_remove_double_slashes.md
nginx: Remove double slashes from URLs

Put the following directives in your server block. nginx will then redirect URLs with double (or triple or multiple) slashes to the corresponding URL with a single slash.

merge_slashes off;
rewrite ^(.*?)//+(.*?)$ $1/$2 permanent;
@WanpengQian
WanpengQian / New-GPUPDriverPackage.ps1
Created March 18, 2022 05:02 — forked from neggles/New-GPUPDriverPackage.ps1
Hyper-V GPU Virtualization
<#
.SYNOPSIS
Create a GPU-P Guest driver package.
.DESCRIPTION
Gathers the necessary files for a GPU-P enabled Windows guest to run.
.EXAMPLE
New-GPUPDriverPackage -DestinationPath '.'
.EXAMPLE
New-GPUPDriverPackage -Filter 'nvidia' -DestinationPath '.'
.INPUTS
@WanpengQian
WanpengQian / UniqueIDGenerator.cpp
Created March 19, 2021 06:49 — forked from wdanxna/UniqueIDGenerator.cpp
Thread safe Unique ID Generator in c++ using std::atomic
template <typename T>
struct UniqueIDGenerator {
std::atomic<T> _id;
std::function<const T(const T&)> _nexter;
template <typename NEXT>
UniqueIDGenerator(const T& init, const NEXT& nexter) {
_id.store(init, std::memory_order::memory_order_release);
_nexter = nexter;
}
#include <memory>
#include <cassert>
#include <Windows.h>
struct FileHandle
{
::HANDLE fileHandle;
//implicit
FileHandle(::HANDLE h) noexcept
@WanpengQian
WanpengQian / stringformat_constexpr_if.cpp
Created November 27, 2020 06:12 — forked from Zitrax/stringformat_constexpr_if.cpp
stringformat with constexpr if
#include <string>
#include <iostream>
#include <memory>
/**
* Convert all std::strings to const char* using constexpr if (C++17)
*/
template<typename T>
auto convert(T&& t) {
@WanpengQian
WanpengQian / stash_dropped.md
Created March 31, 2020 00:22 — forked from joseluisq/stash_dropped.md
How to recover a dropped stash in Git?

How to recover a dropped stash in Git?

1. Find the stash commits

git log --graph --oneline --decorate ( git fsck --no-reflog | awk '/dangling commit/ {print $3}' )

This will show you all the commits at the tips of your commit graph which are no longer referenced from any branch or tag – every lost commit, including every stash commit you’ve ever created, will be somewhere in that graph.

@WanpengQian
WanpengQian / PPPoE on FreeBSD
Created May 31, 2019 01:16 — forked from ysarro/PPPoE on FreeBSD
PPPoE on FreeBSD
/etc/ppp/ppp.conf
default:
set device PPPoE:<interface connected to modem>:<profile name>:
<profile name>:
set authname <pppoe username>
set authkey <pppoe password>
add default HISADDR
@WanpengQian
WanpengQian / tun2socks_proxy_foo.bash
Created January 7, 2018 01:22 — forked from rsanden/tun2socks_proxy_foo.bash
tun2socks TCP+UDP user-wide proxy through shadowsocks and udpgw
#--- Build tun2socks and udpgw (as the user who will use the proxy) ---
mkdir -p $HOME/src
cd $HOME/src
git clone "https://github.com/ambrop72/badvpn"
cd badvpn
mkdir -p build
cd build
export OUTDIR=$PWD
export SRCDIR=$(dirname $PWD)
@WanpengQian
WanpengQian / patch-source3_modules_vfs__shadow__copy2.c
Created May 16, 2017 13:31 — forked from moisseev/patch-source3_modules_vfs__shadow__copy2.c
[partial fix] CVE-2015-5299 denies access to ZFS snapshots due to overly strict condition checking (the patch is against Samba 4.4.13)
--- source3/modules/vfs_shadow_copy2.c.orig 2017-04-02 08:19:24 UTC
+++ source3/modules/vfs_shadow_copy2.c
@@ -1533,7 +1533,7 @@ static bool check_access_snapdir(struct
&smb_fname,
false,
SEC_DIR_LIST);
- if (!NT_STATUS_IS_OK(status)) {
+ if (NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) {
DEBUG(0,("user does not have list permission "
"on snapdir %s\n",
@WanpengQian
WanpengQian / SambaOnFreeBsd.md
Created February 5, 2016 05:33 — forked from TravisTroyer/SambaOnFreeBsd.md
Samba 4.1 on FreeBSD 10.1

Samba 4.1 Active Directory Domain Controller on FreeBSD 10.1

To simplify home network management, I recently decommissioned my beefy domain controller/file server/Hyper-V host, moving mass file storage to the cloud. I thought I could live without Active Directory, but with 5 PCs and a couple of Windows tablets, I want it back, so my plan is to host a tiny VM instance in hyper-V on 4 of my desktop PCs, creating something like peer-to-peer AD (hopefully with little overhead).

Resources

The following references were incredibly helpful, but neither were perfect for getting up and running quickly, hence this gist.