Skip to content

Instantly share code, notes, and snippets.

View samvv's full-sized avatar

Sam Vervaeck samvv

View GitHub Profile
@samvv
samvv / usage.py
Created February 14, 2025 20:33
Current working directory as a resource in Python
with WorkDir("/foo/bar/baz"):
# Do something while inside /foo/bar/baz ...
pass
@samvv
samvv / main.go
Last active December 23, 2024 23:41
Broken SSH server example
// Copyright 2011 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"fmt"
"log"
"net"
@samvv
samvv / truthseeker.py
Created September 20, 2024 14:47
Small program to detect tautologies
from collections.abc import Generator
from itertools import permutations
from dataclasses import dataclass
type Expr = Var | Not | And | Or | Implies | Equiv
Env = dict[str, bool]
class ExprBase:
pass
@samvv
samvv / tsq.h
Created August 31, 2024 13:55
Small thread-safe queue in C
#ifndef TSQ_H
#define TSQ_H
#include <stdlib.h>
#include <pthread.h>
#ifndef TSQ_MAX_SIZE
#define TSQ_MAX_SIZE 1024
#endif
@samvv
samvv / instructions.md
Created August 27, 2024 23:00
Install Wine dependencies

WineDev

In an ideal world, the following command would install all 32-bit dependencies necessary for building Wine on Debian/Ubuntu:

sudo apt install gcc-multilib:i386 gcc-mingw-w64:i386 libasound2-dev:i386 libpulse-dev:i386 libdbus-1-dev:i386 libfontconfig-dev:i386 libfreetype-dev:i386 libgnutls28-dev:i386 libgl-dev:i386 libunwind-dev:i386 libx11-dev:i386 libxcomposite-dev:i386 libxcursor-dev:i386 libxfixes-dev:i386 libxi-dev:i386 libxrandr-dev:i386 libxrender-dev:i386 libxext-dev:i386 libgstreamer1.0-dev:i386 gstreamer1-devel:i386 gstreamer:i386 libosmesa6-dev:i386 libsdl2-dev:i386 libudev-dev:i386 libvulkan-dev:i386 libcapi20-dev:i386 libcups2-dev:i386 libgphoto2-dev:i386 libsane-dev:i386 libkrb5-dev:i386 samba-dev:i386 ocl-icd-opencl-dev:i386 libpcap-dev:i386 libusb-1.0-0-dev:i386
@samvv
samvv / generate.py
Created August 5, 2024 10:16
Overloaded pipe() in Python
#!/usr/bin/env python3
out = ''
# Edit this variable
count = 25
for i in range(0, count):
out += f"_T{i} = TypeVar('_T{i}')\n"
@samvv
samvv / download.py
Last active February 10, 2025 18:39
Download a file in Python 3 with progress reporting
#!/usr/bin/env python3
from tarfile import TarFile
from typing import Callable, TypeVar, cast, Any
import math
import sys, os
import argparse
from urllib.parse import urlparse, urlunparse, ParseResult
import errno
@samvv
samvv / main.js
Created November 7, 2023 11:49
Configure Storybook to use Emotion
const path = require('path');
function toArray(value) {
return Array.isArray(value) ? value : [ value ];
}
const babelLoaderModulePath = require.resolve('babel-loader');
const emotionBabelPluginModulePath = require.resolve('@emotion/babel-plugin');
const babelPresetReactModulePath = require.resolve('@babel/preset-react');
@samvv
samvv / .Xmodmap
Last active April 4, 2023 17:13
Swap Ctrl and Caps Lock keys using Xmodmap
remove Lock = Caps_Lock
remove Control = Control_L
keysym Control_L = Caps_Lock
keysym Caps_Lock = Control_L
add Lock = Caps_Lock
add Control = Control_L
@samvv
samvv / CtrlEscape.ahk
Last active December 23, 2023 17:23
Make control a secondary escape-key on Windows using AutoHotKey
; New version based on author fwompner gmail com in the Vim wiki
; https://vim.fandom.com/wiki/Map_caps_lock_to_escape_in_Windows#AutoHotkey
#Requires AutoHotkey v2.0
#SingleInstance
SetCapsLockState "AlwaysOff"
*Capslock::
{