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 / adler32.cs
Created September 18, 2017 14:30
Adler32 hash in C#
private static uint Adler32(string str)
{
const int mod = 65521;
uint a = 1, b = 0;
foreach (char c in str) {
a = (a + c) % mod;
b = (b + a) % mod;
}
return (b << 16) | a;
}
@i-e-b
i-e-b / A_Profile_BJSS.ps1
Last active October 28, 2023 13:27
My sample Powershell profile script
Set-PSReadlineOption -BellStyle None
# Clone `https://github.com/dahlbyk/posh-git.git` to C:\Gits
Import-Module 'C:\Gits\posh-git\src\posh-git.psd1'
set-executionpolicy Unrestricted process
$baseDir = Split-Path -parent $MyInvocation.MyCommand.Definition
#. "$baseDir\hand.ps1"
# General actions
function edit ($file) { & "${env:ProgramFiles(x86)}\Notepad++\notepad++.exe" $file }
@i-e-b
i-e-b / reset.txt
Created April 2, 2021 07:03
To reset "Dino World" Secret diary kid's toy
To reset dino world secret diary, hold 1, 3, and 0 together until it opens (about 3 seconds)
then enter new 4 digit code and press #
@i-e-b
i-e-b / Readme_NIX_OS.md
Last active July 4, 2023 16:53
/etc/nixos/configuration.nix

My experiments with an XMonad setup in NixOS. This is my work box now, so it pretty much works.

probably needs:

# useradd -m iain
# passwd iain ...
# passwd root ...
@i-e-b
i-e-b / FileLockInfo.cs
Last active June 7, 2023 10:15
Discover Win32 processes locking a file, and file locks by process. This is quite old now, and better methods are available. Additional research by Walkman100 at https://github.com/Walkman100/FileLocks (see comments section)
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Text;
using System.Threading;
namespace FileLockInfo
{
public class Win32Processes
@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