Skip to content

Instantly share code, notes, and snippets.

View sir-pinecone's full-sized avatar
👁️

Michael Campagnaro sir-pinecone

👁️
View GitHub Profile
@shafik
shafik / WhatIsStrictAliasingAndWhyDoWeCare.md
Last active December 25, 2025 23:54
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

The goal is to be able to sketch directly on top of another foreground app with Milton.

To enter screen sketch mode, you launch Milton with a special command line switch. This would also be provided with a shortcut in the Windows Start Menu: In addition to the current "Milton" icon, there'd also be a "Milton Screen Sketch" icon.

When screen sketch mode is entered:

  1. Maximize window, set WS_EX_TOPMOST, and hide system title bar, frame and Milton's own menu.
  2. Implement this SO answer for DWM-accelerated OpenGL window transparency: https://stackoverflow.com/a/4055059
  3. Install a global keyboard hook to toggle whether Milton should be the foreground window. When it's in the foreground it can receive keyboard and tablet events as it usually would. SetForegroundWindow is restricted for security reasons, so this is only possible if a keyboard hook callback counts as the process "receiving the last input event". If this doesn't work, we can just use built-in Windows task switching via the task bar or alt-tabbi
@uucidl
uucidl / 00_the-problem-with-UI.org
Last active May 22, 2025 00:59
The Problem Of UI (User Interfaces)

Links

Note: a lot of programmers talk about UI without mentionning the user even once, as if it was entirely a programming problem. I wonder what we’re leaving off the table when we do that.

@pervognsen
pervognsen / gob.h
Last active March 31, 2024 22:42
gob.h
// My investigations on the C standard compliance of Gob and related techniques:
// https://gist.github.com/pervognsen/5249a405fe7d76ded1cf08ed50fa9176
#pragma once
#include <stdint.h>
#pragma pack(push, 8)
#if __cplusplus >= 201103L || (__cplusplus && _MSC_VER >= 1900)
@pervognsen
pervognsen / btree.inl
Last active June 15, 2019 17:23
Experiments in lightweight C templates
// Here is btree.inl, which is the thing you would write yourself.
// Unlike C++ templates, the granularity of these lightweight templates is at the
// module level rather than the function or class level. You can think of it like
// ML functors (parameterized modules) except that there isn't any static checking
// of signatures (in that respect, it's like C++ templates). In my view, this style
// of parameterized generative modules is generally the better conceptual framework.
// This is a completely valid C file even prior to preprocessing, so during library
// development you can just include this file directly. That is a big win for testing
enum { BMAX = 32, BCUT = BMAX / 2, BHEIGHT = 6 };
typedef uint8_t BIndex;
struct BNode {
BIndex length;
Key keys[BMAX];
union {
BNode *children[BMAX];
Value values[BMAX];
@pervognsen
pervognsen / BTree.cpp
Created April 24, 2016 20:40
A B+-tree implementation with find, insert and delete in 176 lines of code.
enum { BMAX = 32, BMIN = BMAX / 2, BHEIGHT = 6 };
struct BNode {
uint32_t length;
Key keys[BMAX];
union {
BNode *children[BMAX];
Value values[BMAX];
};
};

Programming Language Evaluation

A list of simple tasks to perform when learning or evaluating a new language. Each of these should be able to be completed in a few hours, and will help to get the feel of the language and its standard libraries. A well-rounded set of evaluation tasks will help ensure all parts of the language are exercised. You might also write some tests to demonstrate implementation correctness.

Basics

  1. Hello world
  2. Read lines from a text file and output them in sorted order
  3. Read numbers from a text file and output the mean and standard deviation
  4. Given an amount of money and a list of coin denominations provided on the command line, output all the possible ways to make change
@jebberjeb
jebberjeb / access-logic.clj
Last active August 29, 2015 14:10
[TAKE 3] Rough cut at using core.logic to figure out user->roles->privileges access concerns.
(ns access.core
(:refer-clojure :exclude [==])
(:require [clojure.core.logic :refer :all]))
(def all-priv [:smart-controls :view-all-reports :admin :foo :bar])
(def all-roles [{:name :admin :privs priv}
{:name :reporting :privs [:view-all-reports]}
{:name :store :privs [:smart-controls :view-all-reports]}
{:name :foo-role :privs [:foo :bar]}])
@macton
macton / cpuid_features.c
Last active November 5, 2023 02:04
Print cpuid features
// This file: https://gist.github.com/macton/4dd5fec2113be284796e
// See: Intel Intrinsics Guide https://software.intel.com/sites/landingpage/IntrinsicsGuide/
// See: CPUID Explorer http://www.flounder.com/cpuid_explorer1.htm
// See: Playing with cpuid http://newbiz.github.io/cpp/2010/12/20/Playing-with-cpuid.html
// See: MSDN __cpuid, __cpuidex http://msdn.microsoft.com/en-us/library/hskdteyh.aspx
// See: Notes on MMX/SSE and a searchable table of intrinsics. http://www.taffysoft.com/pages/20120418-01.html
// See: AMD CPUID Specification http://amd-dev.wpengine.netdna-cdn.com/wordpress/media/2012/10/25481.pdf
#if defined(__GNUC__)
#include <stdint.h>