Skip to content

Instantly share code, notes, and snippets.

@Trass3r
Trass3r / WSLxserver.sh
Created December 25, 2021 20:59
WSL xserver
echo 'export DISPLAY=${HOSTNAME}.local:0.0' >> ~/.bashrc
echo 'export LIBGL_ALWAYS_SOFTWARE=1' >> ~/.bashrc
https://sourceforge.net/projects/vcxsrv/files/latest/download
start X with "C:\Program Files\VcXsrv\vcxsrv.exe" -ac -multiwindow -nowgl
@Trass3r
Trass3r / Dockerfile
Last active September 1, 2021 07:53
Alpine Test Container
FROM mcr.microsoft.com/vscode/devcontainers/base:dev-alpine-3.14
RUN apk add --no-cache gdb file g++ clang coreutils
#RUN rm /etc/alpine-release \
#&& wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub \
#&& wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.33-r0/glibc-2.33-r0.apk \
#&& apk add glibc-2.33-r0.apk
#&& apk add --no-cache -X http://dl-cdn.alpinelinux.org/alpine/edge/testing mono gdb
FROM ubuntu:focal
RUN apt update && apt install -y ca-certificates wget gnupg \
&& wget -O - https://download.grammatech.com/gtirb/files/apt-repo/conf/apt.gpg.key | apt-key add - \
&& echo "deb https://download.grammatech.com/gtirb/files/apt-repo focal unstable" >> /etc/apt/sources.list \
&& apt update && apt install -y ddisasm
# RUN ddisasm --generate-import-libs --asm=a.exe.asm a.exe
@Trass3r
Trass3r / buildQemu.sh
Created June 19, 2021 13:22
build QEMU with LTO
sed -Ei 's/^# deb-src /deb-src /' /etc/apt/sources.list
apt update && apt build-dep -y qemu
apt install -y git clang lld
mkdir build && cd build
CC=clang CXX=clang++ CFLAGS="-O3 -march=skylake -flto=thin" CXXFLAGS="-O3 -march=skylake -flto=thin" LDFLAGS="-fuse-ld=lld -O3 -march=skylake -flto=thin" \
../configure --prefix=$(pwd)/install --target-list=aarch64-linux-user --static --disable-system --enable-linux-user --enable-lto --disable-stack-protector --disable-pie
-gsplit-dwarf
--disable-strip
#include <https://raw.githubusercontent.com/swansontec/map-macro/master/map.h>
#define CONST_MAP_CASE2(a, b) case a: return b;
#define CONST_MAP_CASE(pair) CONST_MAP_CASE2 pair
#define HEAD(h, ...) h
#define CONST_MAP_RET2(a, b) return decltype(b){};
#define CONST_MAP_RET(pair) CONST_MAP_RET2 pair
#define CONST_MAP(name, ...) \
#version 460
#extension GL_KHR_shader_subgroup_vote: require
layout (location = 0) in float lightDistanceSqared;
layout (location = 0) out vec4 fragColor;
void main()
{
const int radius = 5;
#if 0
@Trass3r
Trass3r / containers-are-expensive.cpp
Last active November 27, 2020 15:53
comparing implementations of 'is x in a set of numbers' - https://godbolt.org/z/9en4qv
int baseline(int x)
{
switch (x)
{
case 0:
case 2:
case 8:
case 15:
case 16:
return 5;
@Trass3r
Trass3r / CompressWSLdisks.ps1
Last active August 3, 2023 12:47
Reduces disk space taken by the WSL and Docker vhdx files
$ErrorActionPreference = "Stop"
$files = Get-ChildItem -Path C:\Users -Recurse -Include "ext4.vhdx" -Force -ErrorAction SilentlyContinue | Select-Object FullName, Length
wsl -u root fstrim /
foreach ($file in $files) {
echo "Compacting $file"
wsl --shutdown
Mount-VHD -Path $file.FullName -ReadOnly
@Trass3r
Trass3r / buildWSL2kernel.sh
Last active October 8, 2022 17:00
build WSL2 Linux 'next' kernel with clang LTO
sudo apt install -y llvm clang ccache
git clone https://github.com/nathanchance/WSL2-Linux-Kernel
cd WSL2-Linux-Kernel
cp arch/x86/configs/wsl2_defconfig .config
./scripts/config -d XFS_FS -d NFS_FS -d NFSD -d BTRFS_FS -d F2FS_FS -d SUNRPC -d X86_X32 -d X86_16BIT -e CPU_FREQ -e CPU_FREQ_STAT -e CPU_FREQ_GOV_USERSPACE -e CPU_FREQ_GOV_ONDEMAND -e X86_INTEL_PSTATE -e SCHED_MC_PRIO -e PROFILING -e PERF_EVENTS_INTEL_UNCORE -e PERF_EVENTS_INTEL_RAPL -e PERF_EVENTS_INTEL_CSTATE -e ENERGY_MODEL -e INTEL_IDLE -e MODULE_COMPRESS_LZ4 -e KERNEL_LZ4 -e CC_OPTIMIZE_FOR_PERFORMANCE_O3 -e LD_DEAD_CODE_DATA_ELIMINATION -e BPF_JIT -e LTO_CLANG_THIN -d CFI_CLANG -d STACKPROTECTOR -e OPROFILE -e OPROFILE_EVENT_MULTIPLEX
./scripts/config -d SPECULATION_MITIGATIONS -d NETFILTER
# /sys/kernel/debug/tracing not available without this
./scripts/config -d SECURITY_LOCKDOWN_LSM
@Trass3r
Trass3r / static_foreach.cpp
Last active November 13, 2020 17:15
C++17 foreach over tuple implementation
// https://godbolt.org/z/9vWYd8
#include <utility> // forward, integer_sequence
#include <tuple> // get
namespace detail {
template <typename F, typename Tuple, std::size_t... I>
constexpr void static_foreach_impl(Tuple&& t, F&& f, std::index_sequence<I...>)
{
// assume f is a simple FunctionObject, so just call instead of std::invoke