Skip to content

Instantly share code, notes, and snippets.

View mmozeiko's full-sized avatar

Mārtiņš Možeiko mmozeiko

View GitHub Profile
@XVilka
XVilka / TrueColour.md
Last active May 26, 2024 22:50
True Colour (16 million colours) support in various terminal applications and terminals

THIS GIST WAS MOVED TO TERMSTANDARD/COLORS REPOSITORY.

PLEASE ASK YOUR QUESTIONS OR ADD ANY SUGGESTIONS AS A REPOSITORY ISSUES OR PULL REQUESTS INSTEAD!

@lelandbatey
lelandbatey / whiteboardCleaner.md
Last active April 25, 2024 02:01
Whiteboard Picture Cleaner - Shell one-liner/script to clean up and beautify photos of whiteboards!

Description

This simple script will take a picture of a whiteboard and use parts of the ImageMagick library with sane defaults to clean it up tremendously.

The script is here:

#!/bin/bash
convert "$1" -morphology Convolve DoG:15,100,0 -negate -normalize -blur 0x1 -channel RBG -level 60%,91%,0.1 "$2"

Results

#pragma comment(lib, "Xinput.lib")
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <Xinput.h>
@rygorous
rygorous / u32_f32.c
Last active July 22, 2023 03:41
U32->F32 using SSE2 intrinsics.
// ---- Straightforward:
__m128i lo_int = _mm_and_si128(_mm_set1_epi32(0xffff), in); // low 16 bits of all vals
__m128i hi_int = _mm_srli_epi32(in, 16); // high 16 bits of all vals
__m128 lo_flt = _mm_cvtepi32_ps(lo_int); // exact (all 16 bit ints = machine numbers)
__m128 hi_flt = _mm_cvtepi32_ps(hi_int); // exact
__m128 hi_scl = _mm_mul_ps(hi_flt, _mm_set1_ps(65536.0f)); // exact (just exponent change)
__m128 result = _mm_add_ps(hi_scl, lo_flt); // this is the only step that rounds.
// same approach also works with FMA where available.
@paniq
paniq / minmaxabssign.txt
Last active January 30, 2023 14:31
useful min/max/abs/sign identities
max(-x,-y) = -min(x,y)
min(-x,-y) = -max(x,y)
abs(x) = abs(-x)
abs(x) = max(x,-x) = -min(x,-x)
abs(x*a) = if (a >= 0) abs(x)*a
(a < 0) -abs(x)*a
// basically any commutative operation
min(x,y) + max(x,y) = x + y
@ocornut
ocornut / (Archived) imgui_memory_editor.h
Last active January 1, 2024 04:27
Mini memory editor for dear imgui (to embed in your game/tools)
// Mini memory editor for Dear ImGui (to embed in your game/tools)
// Animated GIF: https://twitter.com/ocornut/status/894242704317530112
// THE MEMORY EDITOR CODE HAS MOVED TO GIT:
// https://github.com/ocornut/imgui_club/tree/master/imgui_memory_editor
// Click "Revisions" on the Gist to see old version.
@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
@pervognsen
pervognsen / zzz.cpp
Last active January 22, 2019 17:08
/// zzz - very sleepy replacement, based on etw
#define INITGUID
#include <windows.h>
#include <psapi.h>
#include <tdh.h>
#include <evntrace.h>
#include <guiddef.h>
#pragma warning(disable: 4091)
#include <dbghelp.h>
@rygorous
rygorous / gist:e0f055bfb74e3d5f0af20690759de5a7
Created May 8, 2016 06:54
A bit of background on compilers exploiting signed overflow
Why do compilers even bother with exploiting undefinedness signed overflow? And what are those
mysterious cases where it helps?
A lot of people (myself included) are against transforms that aggressively exploit undefined behavior, but
I think it's useful to know what compiler writers are accomplishing by this.
TL;DR: C doesn't work very well if int!=register width, but (for backwards compat) int is 32-bit on all
major 64-bit targets, and this causes quite hairy problems for code generation and optimization in some
fairly common cases. The signed overflow UB exploitation is an attempt to work around this.