Skip to content

Instantly share code, notes, and snippets.

View mpoullet's full-sized avatar

Matthieu Poullet mpoullet

View GitHub Profile
@richardweinberger
richardweinberger / vm.sh
Last active August 26, 2024 18:34
Fastest QEMU VM setup
$ wget https://cloud.debian.org/images/cloud/bookworm/latest/debian-12-nocloud-amd64.raw
$ qemu-system-x86_64 -M pc,accel=kvm -m 1G \
-drive file=./debian-12-nocloud-amd64.raw,if=virtio \
-netdev type=user,hostfwd=tcp::5573-:22,id=net0 \
-device virtio-net,netdev=net0 -rtc base=localtime -smp 4 \
-nographic
# login with user 'root'
VM$ apt update && apt install openssh-server
VM$ echo "PermitRootLogin yes" > /etc/ssh/sshd_config.d/root_login.conf
VM$ systemctl restart sshd
@hosct
hosct / ctBiosKey.cpp
Last active October 12, 2024 15:55
ctBiosKey
#include <iostream>
#include <Windows.h>
int main()
{
DWORD firmwareTableProviderSignature = 0x41435049; // "ACPI"
DWORD firmwareTableMSDMID = 0x4d44534d; // "MSDM"
UINT structSize = EnumSystemFirmwareTables(firmwareTableProviderSignature, NULL, 0);
if (structSize == 0) {
@dimo414
dimo414 / _README.md
Last active February 25, 2025 23:44
Bash array expansion patterns for use with -u

Expanding Bash arrays safely with set -u

Prior to Bash 4.4 set -u treated empty arrays as "unset", and terminates the process. There are a number of possible workarounds using array parameter expansion, however almost all of them fail in certain Bash versions.

This gist is a supplement to this StackOverflow post.

@mblondel
mblondel / check_convex.py
Last active January 3, 2025 12:42
A small script to get numerical evidence that a function is convex
# Authors: Mathieu Blondel, Vlad Niculae
# License: BSD 3 clause
import numpy as np
def _gen_pairs(gen, max_iter, max_inner, random_state, verbose):
rng = np.random.RandomState(random_state)
# if tuple, interpret as randn
@fosterbrereton
fosterbrereton / better_macros_better_flags.cpp
Last active January 31, 2025 21:29
Companion source code for the article "Better Macros, Better Flags."
/*
MIT License
Copyright 2019 Foster T. Brereton
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
associated documentation files (the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute,
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
createStrippedAndDebugInfo() {
cd ${REPO_PATH} # assuming we're in your repository's directory
ANDROID_NDK=<PATH_TO_NDK>
TMP_DIR_NAME=tmp_strip_symbols
AAR=`find -name '*.aar'` # find the path to the AAR containing the binaries
mkdir -p ${TMP_DIR_NAME}
try cd ${TMP_DIR_NAME}

Discovering the Fourier Transform: A Tutorial on Circulant Matrices, Circular Convolution, and the DFT

Summary

  • Discrete Fourier Transform (DFT) arises naturally out of analysis of circulant matrices
  • DFT can be derived as the change of basis that simultaneously diagonalizes all circulant matrices
@puffybsd
puffybsd / launch.json
Last active July 7, 2022 11:56
VSCode launcher for rust using lldb
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Debug-LLDB",
"type": "lldb",
"request": "launch",
@shafik
shafik / WhatIsStrictAliasingAndWhyDoWeCare.md
Last active April 19, 2025 10:45
What is Strict Aliasing and Why do we Care?

What is the Strict Aliasing Rule and Why do we care?

(OR Type Punning, Undefined Behavior and Alignment, Oh My!)

What is strict aliasing? First we will describe what is aliasing and then we can learn what being strict about it means.

In C and C++ aliasing has to do with what expression types we are allowed to access stored values through. In both C and C++ the standard specifies which expression types are allowed to alias which types. The compiler and optimizer are allowed to assume we follow the aliasing rules strictly, hence the term strict aliasing rule. If we attempt to access a value using a type not allowed it is classified as undefined behavior(UB). Once we have undefined behavior all bets are off, the results of our program are no longer reliable.

Unfortunately with strict aliasing violations, we will often obtain the results we expect, leaving the possibility the a future version of a compiler with a new optimization will break code we th