Skip to content

Instantly share code, notes, and snippets.

View i-e-b's full-sized avatar
🤔
Thinking

Iain Ballard i-e-b

🤔
Thinking
View GitHub Profile
@i-e-b
i-e-b / There are too many cars
Created April 21, 2023 10:20
There are too many cars
This file has been truncated, but you can view the full file.
The Holocaust lasted around 4 years, and killed about 6'000'000 Jews.
The Nazi regieme and its civilian and military collaborators industrialised murder, and managed around 1.5 million killed per year.
We rightfully hold those complicit in contempt.
Cars directly kill about 1.6 million a year. Every year, for decades.
@i-e-b
i-e-b / fastlog2.cpp
Created March 23, 2023 11:15
compute log2(x) by reducing x to [0.75, 1.5)
// From https://tech.ebayinc.com/engineering/fast-approximate-logarithms-part-i-the-basics/
float fastlog2(float x) // compute log2(x) by reducing x to [0.75, 1.5)
{
// a*(x-1)^2 + b*(x-1) approximates log2(x) when 0.75 <= x < 1.5
const float a = -.6296735;
const float b = 1.466967;
float signif, fexp;
int exp;
float lg2;
union { float f; unsigned int i; } ux1, ux2;
@i-e-b
i-e-b / sand clock.md
Created January 27, 2023 14:55
sand clock

dark and light sand. One magnetic, one not. Fill at top in pattern to write the time. Slowly drain out the bottom and separate with magnets.

@i-e-b
i-e-b / column paging.md
Last active January 27, 2023 10:43
Column paging

Idea

For cached queries, each column has a matching 'page-column', that gives the page is should be on if sorted by that column

That way, we can have a single 'paged' data table, but still correctly sort and page by any column.

e.g. (using sample data below)

To get page 3 when ordering by Type

@i-e-b
i-e-b / Fisher_Logemann_Test_of_Articulation.md
Last active January 27, 2023 09:22
Fisher-Logemann Test of Articulation

Once there was a young rat named Arthur, who could never make up his mind. Whenever his friends asked him if he would like to go out with them, he would only answer, "I don't know." He wouldn't say "yes" or "no" either. He would always shirk making a choice.

His aunt Helen said to him, "Now look here. No one is going to care for you if you carry on like this. You have no more mind than a blade of grass."

One rainy day, the rats heard a great noise in the loft. The pine rafters were all rotten, so that the barn was rather unsafe. At last the joists gave way and fell to the ground. The walls shook and all the rats' hair stood on end with fear and horror. "This won't do," said the captain. "I'll send out scouts to search for a new home."

Within five hours the ten scouts came back and said, "We found a stone house where there is room and board for us all. There is a kindly horse named Nelly, a cow, a calf, and a garden with an elm tree." The rats crawled out of their little houses and stood on the floor in a l

@i-e-b
i-e-b / test.js
Created December 21, 2022 15:11
basic RS encode / decode in Javascript
'strict';
function log(msg){document.getElementById('outp').innerText+= msg+"\r\n";}
log("Reed solomon octal coding for short messages\r\n");
const extraCodes = 2;
let orig = [46,219,120,55];
let int32Val = (orig[0] << 24) + (orig[1] << 16) + (orig[2] << 8) + orig[3];
log("tag value="+int32Val);
@i-e-b
i-e-b / MemoryMap.cs
Created December 1, 2022 09:43
Quick demo of mmap in dotnet
using System.IO.MemoryMappedFiles;
using System.Runtime.InteropServices;
namespace MemMapTests;
internal static class Program
{
private const long Megabyte = 1048576;
private const long Kilobyte = 1024;
@i-e-b
i-e-b / caller_id.md
Created October 21, 2022 10:44
Which process is calling out to a given IP

On Linux: lsof -PniTCP -r 1 | grep 1.2.3.4 On Windows: netstat -tabn 10 | find "1.2.3.4"

@i-e-b
i-e-b / BeltAndBraces.md
Created October 19, 2022 11:52
A forth-like language with weird semantics

Take a normal forth-like

25 4 * 100 =    // true

Add parenthesis as a re-write rule, and move one symbol from the left to the right

write(2 4 *) becomes 2 4 * write

@i-e-b
i-e-b / low_bias_hash.cs
Created October 6, 2022 09:36
Low bias 32 bit hash in C#
public static uint DataHash(byte[] data, uint len)
{
var hash = len;
for (uint i = 0; i < len; i++)
{
hash += data[i];
hash ^= hash >> 16;
hash *= 0x7feb352d;
hash ^= hash >> 15;
hash *= 0x846ca68b;