Skip to content

Instantly share code, notes, and snippets.

@m-ou-se
m-ou-se / font
Created February 18, 2015 18:07
Font for my whiteboard clock
0
0 1.5
0 0.5
0.2 0.1
0.5 0
0.8 0.1
1 0.5
1 1.5
0.8 1.9
0.5 2
@m-ou-se
m-ou-se / ieee754.cpp
Created September 12, 2015 14:27
constexpr functions to encode and decode IEEE754 binary64 doubles.
#include <iostream>
#include <vector>
#include <cstdint>
constexpr double decode_double(std::uint64_t encoded) {
bool s = encoded >> 63;
std::int16_t e = encoded >> 52 & 0x7FF;
std::int64_t m = encoded & (1ULL << 52) - 1;
if (e == 2047) return m ? s ? 0/0.0 : -(0/0.0) : s ? -1/0.0 : 1/0.0;
double x = m | (e ? 1ULL << 52 : 0);
@m-ou-se
m-ou-se / replace-debian-with-arch.txt
Last active October 22, 2023 12:16
Instructions to replace a live Debian installation with Arch
# Download latest archlinux bootstrap package, see https://www.archlinux.org/download/
wget 'ftp://ftp.nluug.nl/pub/os/Linux/distr/archlinux/iso/latest/archlinux-bootstrap-*-x86_64.tar.gz'
# Make sure you'll have enough entropy for pacman-key later.
apt-get install haveged
# Install the arch bootstrap image in a tmpfs.
mount -t tmpfs none /mnt
cd /mnt
tar xvf ~/archlinux-bootstrap-*-x86_64.tar.gz --strip-components=1
@m-ou-se
m-ou-se / compositor.sh
Last active August 9, 2019 13:59
Translucent terminals. Works with any terminal emulator, as long as the background is black.
#!/bin/sh
# Runs compton with a shader that only applies the opacity property to black
# backgrounds, with small soft shadows around non-black parts to inprove
# readability.
exec compton --backend glx --vsync --glx-fshader-win '
uniform float opacity;
uniform sampler2D tex;
void main() {
@m-ou-se
m-ou-se / instructions.txt
Created September 11, 2017 13:11
Compiling a cross compiler for armv7l-unknown-linux-gnueabihf (RPi3)
wget http://ftp.snt.utwente.nl/pub/software/gnu/binutils/binutils-2.29.tar.xz
wget ftp://ftp.nluug.nl/mirror/languages/gcc/releases/gcc-7.2.0/gcc-7.2.0.tar.xz
wget http://ftp.gnu.org/gnu/glibc/glibc-2.26.tar.xz
tar xvf binutils-2.29.tar.xz
tar xvf gcc-7.2.0.tar.xz
cd binutils-2.29
./configure --target=armv7l-unknown-linux-gnueabihf --disable-multilib
make -j9
sudo make install
cd ..
@m-ou-se
m-ou-se / Makefile
Last active September 18, 2017 08:20
Automatically include git version in software.
ifeq (${VERBOSE},)
MAKEFLAGS += -s
endif
ifeq ($(OS),Windows_NT)
PY = py
else
PY =
endif
@m-ou-se
m-ou-se / CMakeLists.txt
Last active August 20, 2018 13:29
Automatically include git version in software.
include_directories(${CMAKE_CURRENT_BINARY_DIR}/generated)
#...
add_custom_target(version
COMMAND ${CMAKE_COMMAND}
ARGS
-DOUTPUT=${CMAKE_CURRENT_BINARY_DIR}/generated/version.h
-P ${CMAKE_CURRENT_SOURCE_DIR}/gen-version.cmake
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
@m-ou-se
m-ou-se / Makefile
Created August 20, 2018 09:26
Makefile for CMake+Ninja
.PHONY: .always
all:
Makefile:
#
build/build.ninja:
mkdir -p build
cd build && CXX='clang++ -fdiagnostics-color' CC='clang -fdiagnostics-color' cmake .. -DCMAKE_BUILD_TYPE=RelWithDebInfo -G Ninja
@m-ou-se
m-ou-se / floats.txt
Last active September 19, 2022 19:35
6-bit Floating point values
The overview below shows all 6-bit floating point values using a sign bit, a 3-bit exponent and a 2-bit mantissa.
This should give you an idea of how floating point values work. The standard 32 bit and 64 bit floats
we all know are exactly the same, but just with more bits for both the exponent and mantissa.
S EEE MM
0 111 11 NaN
0 111 10 NaN
0 111 01 NaN
0 111 00 +Infinity
@m-ou-se
m-ou-se / lib.rs
Created October 25, 2022 09:50
FVec
//! Not tested!
extern crate alloc;
use alloc::{
alloc::{realloc, Layout},
collections::TryReserveError,
ffi::CString,
vec::{self, Drain},
};