A useful usecase for nano banana. It is nice to iterate on my style like iterting on source code. This could be great for the next haircut, suit purchase, etc.
Wednesday, 25 February 2026
Allgäu real estate vs s&p the last 30 years
We start with 100k 30 years ago. s&p returns 2mio, 22x return, real estate 876k, so 8.8x return (assuming you re-invest rental income. If not 375k or 3.7x).
Lets hope the s&p keeps going.
Year,SP500_EUR_Wealth,House_Wealth_TCO,House_Price_Only 1995,100000.0,90090.09009009009,90090.09009009009 1996,120259.99999999999,90348.64864864864,89189.18918918919 1997,157552.626,90135.48648648648,87851.35135135135 1998,199571.91135419998,90821.16628378378,87412.09459459459 1999,238548.30564167525,91957.52351351352,87412.09459459459 2000,214359.50744960937,93559.35014695946,87849.15506756755 2001,186407.0276781803,94227.88221702365,87409.90929222971 2002,142843.70530978957,94410.56892744442,86535.81019930741 2003,180525.87477051208,93624.8237708347,84805.09399532127 2004,196755.15091238113,93306.38064288226,83533.01758539144 2005,202657.80543975256,93448.38677277742,82697.68740953752 2006,230259.79854064688,94523.4567091014,82697.68740953752 2007,238387.96942913168,96554.51191187964,83524.6642836329 2008,146632.4399958589,99593.13919851821,85195.15756930556 2009,181017.7471748878,101204.17962815377,85621.13335715208 2010,204151.81526383845,105386.77199265065,88189.76735786664 2011,204151.81526383845,111859.90091671808,92599.25572575998 2012,231528.5736907192,120412.83117182789,98618.20734793438 2013,300061.0315031721,130821.98295740236,106014.57289902946 2014,334237.98299138347,142776.18619749692,114495.73873095182 2015,331798.04571554635,156527.12441908423,124227.87652308273 2016,363451.57927680947,172374.8746271339,135408.38541016018 2017,434033.87597236584,190678.0260830252,148272.1820241254 2018,406950.1621116902,211866.12089427272,163099.40022653795 2019,524477.3689295463,233245.19027596732,177778.34624692638 2020,609757.3891174906,255578.59502323743,192889.50567791512 2021,773721.1510511838,286475.63604272594,214107.3513024858 2022,623309.7592868337,300829.3928740446,222671.64535458523 2023,774337.7139620335,279426.1943225619,204857.91372621842 2024,954835.8350865834,276447.5602569827,200760.75545169404 2025,1111333.4284572743,295800.897082526,212806.4007787957
Saturday, 21 February 2026
How whey is made
Source: https://www.youtube.com/watch?v=LeUZmojH7p8
- Start with Milk, homogenize, pasteurize. It is 87% water, 5% lactose, 3.5% fat, 3.5% protein of which 80% is casine and 20% whey. So there is 0.7% whey in milk. Use around 10l milk for 1kg cheese.
- Whey is a byproduct from making cheese which is made from the casine protein. You need to sperate that caseine from the rest of the milk. Add acid or bacteria that eat lactose and secret acid. Curdling happens and the milk gets firm as the casine separates from the rest, including the whey protein which stays in the water.
- Now it is one big curd with all the other milk components trapped inside. Cut it in small pieces an press it. What comes out are the curds for the cheese and whey liquid.
- The whey liquid contains protein, lactose and fat.
- Filter out the fat, lactose and minerals. Then dry it. You get whey
Thursday, 19 February 2026
Factor 1.75: I assume 430 ckal/h on long distance cycling. 760 ckal/h on long distance running.
So I need to cycle 1.75 times long than running. I want to have the equivalent of 100km running. I would plan 12h for this. So I need to cycle 21h or about 500km. Nice, 12 to 21 is easy to remember. I need to consume 9000 ckal.
Tuesday, 17 February 2026
Maing capslock useful
tap to esc, hold with hjkl for arrows
git clone https://github.com/rvaiya/keyd cd keyd make && sudo make install
sudo systemctl enable --now keyd
cat /etc/keyd/default.conf [ids] * [main] # Create a dedicated navigation layer called 'vim_nav' # Tap = Esc, Hold = Activate 'vim_nav' layer capslock = overload(vim_nav, esc) [vim_nav] # Map hjkl to arrow keys h = left j = down k = up l = right # --- Optional but recommended --- # Map other useful navigation keys to this layer for convenience # Example: Caps + u/i = PageUp/PageDown u = pageup i = pagedown # Example: Caps + n/m = Home/End n = home m = end
sudo keyd reload
Monday, 16 February 2026
Dont be the strongest ant
Move into another category. The strongest ant is not as strong as a human. Humans moved in another category when they formed groups and again when they formed societies. Terrorists are groups, nations are societies. The first can not cause real damage - compared to an army. Here is a funny example of category change: Epic final moments of Kung-Fu Panda 3
Sunday, 15 February 2026
democratizing sharing of insights
It would be nice if all insights travel into the right brains at the right time. Existing solutions are not there yet. On youtube, you have to do your videos about one area only. This is the same problem with other follower-based platform as well. It would be strange to get a video in your feed about 3blue1brown on insights about cheesecake backing in his specific oven type. Blogs are ok, but when you have RSS, it is the same problem. Tiktok goes in the right direction. Content is king, nothing else, followers dont count. But due to insentive problems tiktok is aweful. Google might be good, but where to publish. In a dream world of a decentralized web with a search engine on your side it could work. LLMs, maybe with sources, are a very promising candidate for such a database. But there are currently no insentives to share your insights.
Motivating EVERYONE to share EVERYTHING slightly useful for SOMEONE and then bringing that to the right person at the right time is an important unsolved problem.
Is everything exclusively relational / defined by its context?
I had a conversaion about where taste comes from. We concluded from associations. I constructed an example where you had to choose between 2 things that were clearly distinct, but had NO existing associations. We could not come up with a preference.
But if positive preferences diffuse through the association-web in our mind, where is the source? Maybe a more fundamental algorithm like evloution and the drive to survive are the sources, diffusing through associations to other objects building our preferences
For example I like a nice shirt, because I associate it with wealth, associating it with resource abundance, which evolution programmed into me since I was a single cell is a good thing
Anyway, just speculations, I did 0 seconds of research.
which problems to work on?
Dimensions: Interesting, Hard, I can find joy. We assume valuable is given. Wook for not interesting, hard and where I am able to find joy in it.
- not interesting, not hard, no joy: obviously bad
- not interesting, not hard, joy: hobby
- not interesting, hard, no joy: why bother?
- not interesting, hard, joy: great! A good problem
- interesting, not hard, no joy: just use others work
- interesting, not hard, joy: why is i not solved already?
- interesting, hard, no joy: use others work and be happy about it
- interesting, hard, joy: would be nice, but the space is crowded
Saturday, 14 February 2026
paste to stdin of a program
I am using wayland, thus I do
sudo apt install wl-clipboard wl-paste wl-paste | xargs echo wl-paste | my-program echo hi | wl-copyand put in
.zshrc
alias paste="wl-paste" alias copy="wl-copy"
Linux is great.
Wednesday, 4 February 2026
Make learning addictive
While not being a live-goal, a good milestone.
Equally addictive as hyperoptimized social media apps and features.
Only good content. Good is defined as personal goal oriented. It is about you.
Datatransfer from your AI-twin into your brain.
Like that scene in the Matrix.
Monday, 2 February 2026
Why do we listen to Tech CEOs for predictions?
They have clearly a conflict of interest. We assume that they have insight that we don't have. This may be the case - or it is not. But even if they did, why should they tell the truth? They are telling you things that benefit them. If they would not, they would leave the pool of tech CEOs. If the CEO of Anthropic really would believe that Claude Code would replace ALL programmers in 1 year, he would only hand out employment contracts for one year max.
Vibe Coding watching is like 3d printer watching
Hypnotizing into uselessness, but hard to stop. Useful enough to be dangerous but there are better things to do. For now discipline is key, but discipline depletes
base36 in rust
base36 are a-z and 0-9. This is great when computers and humans are working together as it is easy to spell out. It is also short. I can just do an integer auto-increment and get quite small ids. Here is a reusable rust implementation
const BASE36_CHARS: &[u8; 36] = b"0123456789abcdefghijklmnopqrstuvwxyz";
// Lookup table for fast base36 to digit conversion
const BASE36_DECODE: [u8; 256] = {
let mut table = [255u8; 256];
let mut i = 0;
while i < 10 {
table[(b'0' + i) as usize] = i;
i += 1;
}
let mut i = 0;
while i < 26 {
table[(b'a' + i) as usize] = i + 10;
i += 1;
}
table
};
#[inline(always)]
pub fn u64_to_base36(value: u64) -> String {
// Specialized implementations for different ranges for maximum performance
match value {
0 => "0".to_string(),
1..=35 => unsafe { String::from_utf8_unchecked(vec![BASE36_CHARS[value as usize]]) },
36..=1295 => {
let d1 = (value % 36) as usize;
let d0 = (value / 36) as usize;
unsafe { String::from_utf8_unchecked(vec![BASE36_CHARS[d0], BASE36_CHARS[d1]]) }
}
1296..=46655 => {
let mut v = value;
let d2 = (v % 36) as usize;
v /= 36;
let d1 = (v % 36) as usize;
let d0 = (v / 36) as usize;
unsafe {
String::from_utf8_unchecked(vec![
BASE36_CHARS[d0],
BASE36_CHARS[d1],
BASE36_CHARS[d2],
])
}
}
_ => {
// General case for larger numbers
let mut val = value;
let mut buffer: [u8; 13] = [0; 13]; // Maximum length of u64 in base36 is 13
let mut pos = 13;
// Optimized division loop - compiler can optimize division by constant
while val > 0 {
pos -= 1;
buffer[pos] = BASE36_CHARS[(val % 36) as usize];
val /= 36;
}
// SAFETY: We only write valid ASCII characters
unsafe { String::from_utf8_unchecked(buffer[pos..].to_vec()) }
}
}
}
#[inline(always)]
pub fn base36_to_u64(s: &str) -> Result {
if s.is_empty() {
return Err("Empty string".to_string());
}
let bytes = s.as_bytes();
// Fast path for common single digit case
if bytes.len() == 1 {
let digit = BASE36_DECODE[bytes[0] as usize];
if digit == 255 {
return Err(format!(
"Invalid character '{}' in base36 string",
bytes[0] as char
));
}
return Ok(digit as u64);
}
let mut result: u64 = 0;
let mut i = 0;
// Process 2 digits at a time when possible for better performance
while i + 1 < bytes.len() {
let d0 = BASE36_DECODE[bytes[i] as usize];
let d1 = BASE36_DECODE[bytes[i + 1] as usize];
if d0 == 255 || d1 == 255 {
return Err("Invalid character in base36 string".to_string());
}
// result = result * 36^2 + d0 * 36 + d1
result = match result
.checked_mul(1296)
.and_then(|r| r.checked_add((d0 as u64) * 36 + d1 as u64))
{
Some(val) => val,
None => return Err("Overflow while parsing base36 string".to_string()),
};
i += 2;
}
// Handle remaining single digit
if i < bytes.len() {
let digit = BASE36_DECODE[bytes[i] as usize];
if digit == 255 {
return Err("Invalid character in base36 string".to_string());
}
result = match result
.checked_mul(36)
.and_then(|r| r.checked_add(digit as u64))
{
Some(val) => val,
None => return Err("Overflow while parsing base36 string".to_string()),
};
}
Ok(result)
}
/// Encode a u128 value to base36 string (useful for UUIDs which are 128 bits)
#[inline]
pub fn u128_to_base36(value: u128) -> String {
if value == 0 {
return "0".to_string();
}
// Maximum length of u128 in base36 is 25 characters
let mut buffer: [u8; 25] = [0; 25];
let mut pos = 25;
let mut val = value;
while val > 0 {
pos -= 1;
buffer[pos] = BASE36_CHARS[(val % 36) as usize];
val /= 36;
}
// SAFETY: We only write valid ASCII characters
unsafe { String::from_utf8_unchecked(buffer[pos..].to_vec()) }
}
/// Decode a base36 string to u128 (useful for UUIDs which are 128 bits)
#[inline]
pub fn base36_to_u128(s: &str) -> Result {
if s.is_empty() {
return Err("Empty string".to_string());
}
let bytes = s.as_bytes();
let mut result: u128 = 0;
for &byte in bytes {
let digit = BASE36_DECODE[byte as usize];
if digit == 255 {
return Err(format!(
"Invalid character '{}' in base36 string",
byte as char
));
}
result = match result
.checked_mul(36)
.and_then(|r| r.checked_add(digit as u128))
{
Some(val) => val,
None => return Err("Overflow while parsing base36 string".to_string()),
};
}
Ok(result)
}
/// Encode arbitrary binary data to base36 string
/// Treats the byte slice as a big-endian unsigned integer
#[inline]
pub fn bytes_to_base36(bytes: &[u8]) -> String {
if bytes.is_empty() || bytes.iter().all(|&b| b == 0) {
return "0".to_string();
}
// Skip leading zeros
let start = bytes.iter().position(|&b| b != 0).unwrap_or(0);
let bytes = &bytes[start..];
if bytes.is_empty() {
return "0".to_string();
}
// For small byte arrays, use u128 fast path
if bytes.len() <= 16 {
let mut value: u128 = 0;
for &byte in bytes {
value = (value << 8) | (byte as u128);
}
return u128_to_base36(value);
}
// For larger byte arrays, use arbitrary precision arithmetic
// We'll work with the bytes directly using schoolbook division
let mut digits = bytes.to_vec();
let mut result = Vec::new();
while !digits.is_empty() && !(digits.len() == 1 && digits[0] == 0) {
let mut remainder: u16 = 0;
let mut new_digits = Vec::with_capacity(digits.len());
for &digit in &digits {
let current = (remainder << 8) | (digit as u16);
let quotient = current / 36;
remainder = current % 36;
if !new_digits.is_empty() || quotient > 0 {
new_digits.push(quotient as u8);
}
}
result.push(BASE36_CHARS[remainder as usize]);
digits = new_digits;
}
if result.is_empty() {
return "0".to_string();
}
result.reverse();
// SAFETY: We only use valid ASCII characters from BASE36_CHARS
unsafe { String::from_utf8_unchecked(result) }
}
/// Decode a base36 string to binary data
/// Returns the minimal byte representation (no leading zeros)
#[inline]
pub fn base36_to_bytes(s: &str) -> Result, String> {
if s.is_empty() {
return Err("Empty string".to_string());
}
// For short strings that fit in u128, use fast path
if s.len() <= 25 {
let value = base36_to_u128(s)?;
if value == 0 {
return Ok(vec![0]);
}
// Convert u128 to bytes, removing leading zeros
let all_bytes = value.to_be_bytes();
let start = all_bytes.iter().position(|&b| b != 0).unwrap_or(15);
return Ok(all_bytes[start..].to_vec());
}
// For longer strings, use arbitrary precision arithmetic
let input_bytes = s.as_bytes();
// Validate all characters first
for &byte in input_bytes {
if BASE36_DECODE[byte as usize] == 255 {
return Err(format!(
"Invalid character '{}' in base36 string",
byte as char
));
}
}
// Convert base36 digits to a vector
let mut digits: Vec = input_bytes
.iter()
.map(|&b| BASE36_DECODE[b as usize])
.collect();
let mut result = Vec::new();
while !digits.is_empty() && !(digits.len() == 1 && digits[0] == 0) {
let mut remainder: u16 = 0;
let mut new_digits = Vec::with_capacity(digits.len());
for &digit in &digits {
let current = remainder * 36 + (digit as u16);
let quotient = current / 256;
remainder = current % 256;
if !new_digits.is_empty() || quotient > 0 {
new_digits.push(quotient as u8);
}
}
result.push(remainder as u8);
digits = new_digits;
}
if result.is_empty() {
return Ok(vec![0]);
}
result.reverse();
Ok(result)
}
/// Decode a base36 string to a fixed-size byte array
/// Pads with leading zeros if necessary, returns error if result is too large
#[inline]
pub fn base36_to_bytes_fixed(s: &str) -> Result<[u8; N], String> {
let bytes = base36_to_bytes(s)?;
if bytes.len() > N {
return Err(format!(
"Value too large: {} bytes, expected at most {}",
bytes.len(),
N
));
}
let mut result = [0u8; N];
let offset = N - bytes.len();
result[offset..].copy_from_slice(&bytes);
Ok(result)
}
// Ultra-fast versions without bounds checking for internal use
#[inline(always)]
pub fn u64_to_base36_unchecked(value: u64) -> String {
// Use the same optimized approach but without error checking
u64_to_base36(value) // Safe to call since we know input is valid
}
#[inline(always)]
pub fn base36_to_u64_unchecked(s: &str) -> u64 {
let bytes = s.as_bytes();
// Unroll for common short cases
match bytes.len() {
1 => BASE36_DECODE[bytes[0] as usize] as u64,
2 => {
let d0 = BASE36_DECODE[bytes[0] as usize] as u64;
let d1 = BASE36_DECODE[bytes[1] as usize] as u64;
d0 * 36 + d1
}
3 => {
let d0 = BASE36_DECODE[bytes[0] as usize] as u64;
let d1 = BASE36_DECODE[bytes[1] as usize] as u64;
let d2 = BASE36_DECODE[bytes[2] as usize] as u64;
(d0 * 36 + d1) * 36 + d2
}
_ => {
let mut result: u64 = 0;
for &byte in bytes {
result = result * 36 + (BASE36_DECODE[byte as usize] as u64);
}
result
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_u64_to_base36() {
assert_eq!(u64_to_base36(0), "0");
assert_eq!(u64_to_base36(1), "1");
assert_eq!(u64_to_base36(35), "z");
assert_eq!(u64_to_base36(36), "10");
assert_eq!(u64_to_base36(1296), "100");
assert_eq!(u64_to_base36(46656), "1000");
}
#[test]
fn test_base36_to_u64() {
assert_eq!(base36_to_u64("0").unwrap(), 0);
assert_eq!(base36_to_u64("1").unwrap(), 1);
assert_eq!(base36_to_u64("z").unwrap(), 35);
assert_eq!(base36_to_u64("10").unwrap(), 36);
assert_eq!(base36_to_u64("100").unwrap(), 1296);
assert_eq!(base36_to_u64("1000").unwrap(), 46656);
}
#[test]
fn test_base36_to_u64_errors() {
assert!(base36_to_u64("").is_err());
assert!(base36_to_u64("Z").is_err());
assert!(base36_to_u64("!").is_err());
assert!(base36_to_u64("abc123xyz!").is_err());
}
#[test]
fn test_roundtrip_small_values() {
for i in 0..1000 {
let base36 = u64_to_base36(i);
let back = base36_to_u64(&base36).unwrap();
assert_eq!(i, back, "Roundtrip failed for {i}");
}
}
#[test]
fn test_roundtrip_edge_cases() {
let test_values = vec![
0,
1,
35,
36,
1295,
1296,
46655,
46656,
u64::MAX / 2,
u64::MAX - 1,
u64::MAX,
];
for value in test_values {
let base36 = u64_to_base36(value);
let back = base36_to_u64(&base36).unwrap();
assert_eq!(value, back, "Roundtrip failed for {value}");
}
}
#[test]
fn test_roundtrip_random_samples() {
let test_values = vec![
123456789,
987654321,
1_000_000_000,
10_000_000_000,
100_000_000_000,
1_000_000_000_000,
];
for value in test_values {
let base36 = u64_to_base36(value);
let back = base36_to_u64(&base36).unwrap();
assert_eq!(value, back, "Roundtrip failed for {value}");
}
}
#[test]
fn test_max_u64_base36() {
let max_base36 = u64_to_base36(u64::MAX);
assert_eq!(max_base36, "3w5e11264sgsf");
assert_eq!(base36_to_u64(&max_base36).unwrap(), u64::MAX);
}
#[test]
fn test_overflow_detection() {
assert!(base36_to_u64("3w5e11264sgsg").is_err());
assert!(base36_to_u64("zzzzzzzzzzzzzz").is_err());
}
#[test]
fn test_unchecked_versions() {
// Test unchecked versions match checked versions for valid inputs
for i in 0..10000 {
assert_eq!(u64_to_base36(i), u64_to_base36_unchecked(i));
let s = u64_to_base36(i);
assert_eq!(base36_to_u64(&s).unwrap(), base36_to_u64_unchecked(&s));
}
}
#[test]
fn test_u64_to_base36_specific_ranges() {
// Test value 0 (line 23)
assert_eq!(u64_to_base36(0), "0");
// Test single digit range 1..=35 (lines 24)
assert_eq!(u64_to_base36(1), "1");
assert_eq!(u64_to_base36(35), "z");
// Test two digit range 36..=1295 (lines 25-29)
assert_eq!(u64_to_base36(36), "10");
assert_eq!(u64_to_base36(1295), "zz");
assert_eq!(u64_to_base36(100), "2s");
// Test three digit range 1296..=46655 (lines 30-42)
assert_eq!(u64_to_base36(1296), "100");
assert_eq!(u64_to_base36(46655), "zzz");
assert_eq!(u64_to_base36(5000), "3uw");
// Test general case _ (lines 44-59)
assert_eq!(u64_to_base36(46656), "1000");
assert_eq!(u64_to_base36(1000000), "lfls");
assert_eq!(u64_to_base36(u64::MAX), "3w5e11264sgsf");
}
#[test]
fn test_base36_to_u64_specific_cases() {
// Test empty string error (lines 65-67)
match base36_to_u64("") {
Err(msg) => assert_eq!(msg, "Empty string"),
Ok(_) => panic!("Should have failed"),
}
// Test single digit path (lines 72-80)
assert_eq!(base36_to_u64("0").unwrap(), 0);
assert_eq!(base36_to_u64("9").unwrap(), 9);
assert_eq!(base36_to_u64("a").unwrap(), 10);
assert_eq!(base36_to_u64("z").unwrap(), 35);
// Test invalid single character (lines 74-78)
match base36_to_u64("@") {
Err(msg) => assert!(msg.contains("Invalid character")),
Ok(_) => panic!("Should have failed"),
}
// Test two digit processing (lines 87-104)
assert_eq!(base36_to_u64("10").unwrap(), 36);
assert_eq!(base36_to_u64("zz").unwrap(), 1295);
// Test invalid character in two digit (lines 91-93)
match base36_to_u64("a@") {
Err(msg) => assert_eq!(msg, "Invalid character in base36 string"),
Ok(_) => panic!("Should have failed"),
}
// Test overflow in multiplication (lines 96-102)
let overflow_str = "zzzzzzzzzzzzzzzzzzzz"; // Very long string
match base36_to_u64(overflow_str) {
Err(msg) => assert_eq!(msg, "Overflow while parsing base36 string"),
Ok(_) => panic!("Should have failed"),
}
// Test single remaining digit (lines 108-123)
assert_eq!(base36_to_u64("abc").unwrap(), 13368); // 10*36*36 + 11*36 + 12
// Test invalid remaining digit (lines 110-112)
match base36_to_u64("ab@") {
Err(msg) => assert_eq!(msg, "Invalid character in base36 string"),
Ok(_) => panic!("Should have failed"),
}
}
#[test]
fn test_base36_to_u64_unchecked_specific_cases() {
// Test 1 character case (line 139)
assert_eq!(base36_to_u64_unchecked("0"), 0);
assert_eq!(base36_to_u64_unchecked("z"), 35);
// Test 2 character case (lines 140-143)
assert_eq!(base36_to_u64_unchecked("10"), 36);
assert_eq!(base36_to_u64_unchecked("zz"), 1295);
// Test 3 character case (lines 145-149)
assert_eq!(base36_to_u64_unchecked("100"), 1296);
assert_eq!(base36_to_u64_unchecked("zzz"), 46655);
// Test general case (lines 151-156)
assert_eq!(base36_to_u64_unchecked("1000"), 46656);
assert_eq!(base36_to_u64_unchecked("abc123"), 623698779);
}
#[test]
fn test_u64_to_base36_unchecked_coverage() {
// Test that unchecked version calls the regular version (line 130)
assert_eq!(u64_to_base36_unchecked(12345), u64_to_base36(12345));
assert_eq!(u64_to_base36_unchecked(0), "0");
assert_eq!(u64_to_base36_unchecked(u64::MAX), "3w5e11264sgsf");
}
#[test]
fn test_lookup_table_bounds() {
// Test that our lookup table handles all possible byte values
for i in 0..=255 {
let val = BASE36_DECODE[i];
if i >= b'0' as usize && i <= b'9' as usize {
assert_eq!(val, (i - b'0' as usize) as u8);
} else if i >= b'a' as usize && i <= b'z' as usize {
assert_eq!(val, (i - b'a' as usize + 10) as u8);
} else {
assert_eq!(val, 255);
}
}
}
#[test]
fn test_base36_chars_array() {
// Test that BASE36_CHARS contains expected characters
assert_eq!(BASE36_CHARS[0], b'0');
assert_eq!(BASE36_CHARS[9], b'9');
assert_eq!(BASE36_CHARS[10], b'a');
assert_eq!(BASE36_CHARS[35], b'z');
assert_eq!(BASE36_CHARS.len(), 36);
}
#[test]
fn test_base36_decode_lookup_table_comprehensive() {
// Test that BASE36_DECODE lookup table is correctly initialized
// Test digits 0-9
for i in 0..10 {
let char_byte = b'0' + i;
assert_eq!(BASE36_DECODE[char_byte as usize], i);
}
// Test letters a-z
for i in 0..26 {
let char_byte = b'a' + i;
assert_eq!(BASE36_DECODE[char_byte as usize], i + 10);
}
// Test that uppercase letters are invalid (should be 255)
for i in 0..26 {
let char_byte = b'A' + i;
assert_eq!(BASE36_DECODE[char_byte as usize], 255);
}
// Test that other characters are invalid (should be 255)
assert_eq!(BASE36_DECODE[b'@' as usize], 255);
assert_eq!(BASE36_DECODE[b'[' as usize], 255);
assert_eq!(BASE36_DECODE[b'`' as usize], 255);
assert_eq!(BASE36_DECODE[b'{' as usize], 255);
assert_eq!(BASE36_DECODE[255], 255);
}
#[test]
fn test_u64_to_base36_boundary_values() {
// Test exact boundary values for the optimized ranges
assert_eq!(u64_to_base36(0), "0");
assert_eq!(u64_to_base36(1), "1");
assert_eq!(u64_to_base36(35), "z");
assert_eq!(u64_to_base36(36), "10");
assert_eq!(u64_to_base36(1295), "zz");
assert_eq!(u64_to_base36(1296), "100");
assert_eq!(u64_to_base36(46655), "zzz");
assert_eq!(u64_to_base36(46656), "1000");
}
#[test]
fn test_base36_to_u64_single_digit_edge_cases() {
// Test all valid single digits
for i in 0..36 {
let base36_char = BASE36_CHARS[i] as char;
let base36_string = base36_char.to_string();
let result = base36_to_u64(&base36_string).unwrap();
assert_eq!(result, i as u64);
}
}
#[test]
fn test_base36_to_u64_two_digit_processing() {
// Test the two-digit processing path (lines 87-104)
assert_eq!(base36_to_u64("10").unwrap(), 36);
assert_eq!(base36_to_u64("11").unwrap(), 37);
assert_eq!(base36_to_u64("zz").unwrap(), 1295);
assert_eq!(base36_to_u64("az").unwrap(), 10 * 36 + 35);
assert_eq!(base36_to_u64("za").unwrap(), 35 * 36 + 10);
}
#[test]
fn test_base36_to_u64_overflow_boundary() {
// Test values near the overflow boundary
let max_valid = u64_to_base36(u64::MAX);
assert_eq!(base36_to_u64(&max_valid).unwrap(), u64::MAX);
// Test a string that should cause overflow
let overflow_str = "zzzzzzzzzzzzzzzz"; // 16 z's - much larger than u64::MAX
match base36_to_u64(overflow_str) {
Err(msg) => assert_eq!(msg, "Overflow while parsing base36 string"),
Ok(_) => panic!("Should have overflowed"),
}
}
#[test]
fn test_base36_to_u64_invalid_characters() {
// Test various invalid characters
let invalid_cases = vec![
("A", "Invalid character 'A' in base36 string"),
("Z", "Invalid character 'Z' in base36 string"),
("@", "Invalid character '@' in base36 string"),
("[", "Invalid character '[' in base36 string"),
("`", "Invalid character '`' in base36 string"),
("{", "Invalid character '{' in base36 string"),
("!", "Invalid character '!' in base36 string"),
("a!", "Invalid character in base36 string"),
("!a", "Invalid character in base36 string"),
("a@b", "Invalid character in base36 string"),
];
for (input, expected_error) in invalid_cases {
match base36_to_u64(input) {
Err(msg) => {
if expected_error.contains("Invalid character '") {
assert!(msg.starts_with("Invalid character"));
} else {
assert_eq!(msg, expected_error);
}
}
Ok(_) => panic!("Should have failed for input: {input}"),
}
}
}
#[test]
fn test_base36_to_u64_odd_length_strings() {
// Test strings with odd lengths to ensure the remaining digit handling works
assert_eq!(base36_to_u64("1").unwrap(), 1);
assert_eq!(base36_to_u64("123").unwrap(), 36 * 36 + 2 * 36 + 3);
assert_eq!(
base36_to_u64("12345").unwrap(),
36 * 36 * 36 * 36 + 2 * 36 * 36 * 36 + 3 * 36 * 36 + 4 * 36 + 5
);
}
#[test]
fn test_base36_to_u64_unchecked_specific_lengths() {
// Test all the specific length cases in base36_to_u64_unchecked
// 1 character (line 139)
assert_eq!(base36_to_u64_unchecked("5"), 5);
assert_eq!(base36_to_u64_unchecked("z"), 35);
// 2 characters (lines 140-143)
assert_eq!(base36_to_u64_unchecked("10"), 36);
assert_eq!(base36_to_u64_unchecked("zz"), 1295);
// 3 characters (lines 145-149)
assert_eq!(base36_to_u64_unchecked("100"), 1296);
assert_eq!(base36_to_u64_unchecked("zzz"), 46655);
// 4+ characters (lines 151-156)
assert_eq!(base36_to_u64_unchecked("1000"), 46656);
assert_eq!(
base36_to_u64_unchecked("abcd"),
10 * 36 * 36 * 36 + 11 * 36 * 36 + 12 * 36 + 13
);
}
#[test]
fn test_performance_comparison() {
// Test that checked and unchecked versions produce the same results
let test_values = vec![0, 1, 35, 36, 1000, 46656, 1000000];
for value in test_values {
let base36_str = u64_to_base36(value);
assert_eq!(u64_to_base36_unchecked(value), base36_str);
assert_eq!(
base36_to_u64(&base36_str).unwrap(),
base36_to_u64_unchecked(&base36_str)
);
}
}
#[test]
fn test_edge_case_error_messages() {
// Test specific error message formatting
match base36_to_u64("@") {
Err(msg) => assert!(msg.contains("Invalid character '@' in base36 string")),
Ok(_) => panic!("Should have failed"),
}
// Test empty string error message
match base36_to_u64("") {
Err(msg) => assert_eq!(msg, "Empty string"),
Ok(_) => panic!("Should have failed"),
}
}
#[test]
fn test_large_string_handling() {
// Test handling of strings that would definitely overflow
let very_large_string = "z".repeat(20);
match base36_to_u64(&very_large_string) {
Err(msg) => assert_eq!(msg, "Overflow while parsing base36 string"),
Ok(_) => panic!("Should have overflowed"),
}
}
#[test]
fn test_buffer_usage_in_general_case() {
// Test values that use the general case buffer (> 46655)
let large_values = vec![100000, 1000000, 10000000, 100000000, 1000000000];
for value in large_values {
let base36_str = u64_to_base36(value);
let decoded = base36_to_u64(&base36_str).unwrap();
assert_eq!(decoded, value);
// Verify the string is reasonable length (should be <= 13 for u64::MAX)
assert!(base36_str.len() <= 13);
}
}
#[test]
fn test_u128_to_base36() {
assert_eq!(u128_to_base36(0), "0");
assert_eq!(u128_to_base36(1), "1");
assert_eq!(u128_to_base36(35), "z");
assert_eq!(u128_to_base36(36), "10");
assert_eq!(u128_to_base36(u64::MAX as u128), "3w5e11264sgsf");
// Test value larger than u64::MAX
let large_value: u128 = (u64::MAX as u128) * 2;
let encoded = u128_to_base36(large_value);
let decoded = base36_to_u128(&encoded).unwrap();
assert_eq!(decoded, large_value);
}
#[test]
fn test_base36_to_u128() {
assert_eq!(base36_to_u128("0").unwrap(), 0);
assert_eq!(base36_to_u128("1").unwrap(), 1);
assert_eq!(base36_to_u128("z").unwrap(), 35);
assert_eq!(base36_to_u128("10").unwrap(), 36);
assert_eq!(base36_to_u128("3w5e11264sgsf").unwrap(), u64::MAX as u128);
}
#[test]
fn test_u128_roundtrip() {
let test_values: Vec = vec![
0,
1,
35,
36,
u64::MAX as u128,
u64::MAX as u128 + 1,
u128::MAX / 2,
u128::MAX - 1,
u128::MAX,
];
for value in test_values {
let encoded = u128_to_base36(value);
let decoded = base36_to_u128(&encoded).unwrap();
assert_eq!(decoded, value, "Roundtrip failed for {value}");
}
}
#[test]
fn test_bytes_to_base36() {
// Empty and zero cases
assert_eq!(bytes_to_base36(&[]), "0");
assert_eq!(bytes_to_base36(&[0]), "0");
assert_eq!(bytes_to_base36(&[0, 0, 0]), "0");
// Single byte values
assert_eq!(bytes_to_base36(&[1]), "1");
assert_eq!(bytes_to_base36(&[35]), "z");
assert_eq!(bytes_to_base36(&[36]), "10");
assert_eq!(bytes_to_base36(&[255]), "73"); // 255 in base36
// Multi-byte values
assert_eq!(bytes_to_base36(&[1, 0]), "74"); // 256 in base36
assert_eq!(bytes_to_base36(&[0, 1, 0]), "74"); // Leading zeros ignored
// Known value: 0xDEADBEEF
assert_eq!(bytes_to_base36(&[0xDE, 0xAD, 0xBE, 0xEF]), "1ps9wxb");
}
#[test]
fn test_base36_to_bytes() {
assert_eq!(base36_to_bytes("0").unwrap(), vec![0]);
assert_eq!(base36_to_bytes("1").unwrap(), vec![1]);
assert_eq!(base36_to_bytes("z").unwrap(), vec![35]);
assert_eq!(base36_to_bytes("10").unwrap(), vec![36]);
assert_eq!(base36_to_bytes("73").unwrap(), vec![255]);
assert_eq!(base36_to_bytes("74").unwrap(), vec![1, 0]); // 256
// Known value: 0xDEADBEEF
assert_eq!(
base36_to_bytes("1ps9wxb").unwrap(),
vec![0xDE, 0xAD, 0xBE, 0xEF]
);
}
#[test]
fn test_bytes_roundtrip() {
let test_cases: Vec> = vec![
vec![0],
vec![1],
vec![255],
vec![1, 0],
vec![255, 255],
vec![0xDE, 0xAD, 0xBE, 0xEF],
vec![1, 2, 3, 4, 5, 6, 7, 8],
vec![255; 16], // 16 bytes of 0xFF
];
for bytes in test_cases {
let encoded = bytes_to_base36(&bytes);
let decoded = base36_to_bytes(&encoded).unwrap();
// Skip leading zeros in original for comparison
let start = bytes.iter().position(|&b| b != 0).unwrap_or(bytes.len() - 1);
let expected = if start == bytes.len() {
vec![0]
} else {
bytes[start..].to_vec()
};
assert_eq!(decoded, expected, "Roundtrip failed for {bytes:?}");
}
}
#[test]
fn test_base36_to_bytes_fixed() {
// Test fixed-size decoding with padding
let result: [u8; 4] = base36_to_bytes_fixed("1").unwrap();
assert_eq!(result, [0, 0, 0, 1]);
let result: [u8; 4] = base36_to_bytes_fixed("1ps9wxb").unwrap();
assert_eq!(result, [0xDE, 0xAD, 0xBE, 0xEF]);
// Test error when value is too large
let result: Result<[u8; 2], String> = base36_to_bytes_fixed("1ps9wxb");
assert!(result.is_err());
}
#[test]
fn test_uuid_v4_encode_decode() {
// UUID v4 example: 550e8400-e29b-41d4-a716-446655440000
// As bytes (big-endian): [0x55, 0x0e, 0x84, 0x00, 0xe2, 0x9b, 0x41, 0xd4,
// 0xa7, 0x16, 0x44, 0x66, 0x55, 0x44, 0x00, 0x00]
let uuid_bytes: [u8; 16] = [
0x55, 0x0e, 0x84, 0x00, 0xe2, 0x9b, 0x41, 0xd4, 0xa7, 0x16, 0x44, 0x66, 0x55, 0x44,
0x00, 0x00,
];
// Encode to base36
let encoded = bytes_to_base36(&uuid_bytes);
// Decode back to bytes
let decoded: [u8; 16] = base36_to_bytes_fixed(&encoded).unwrap();
assert_eq!(decoded, uuid_bytes);
// Also test via u128 path
let uuid_as_u128 = u128::from_be_bytes(uuid_bytes);
let encoded_u128 = u128_to_base36(uuid_as_u128);
let decoded_u128 = base36_to_u128(&encoded_u128).unwrap();
assert_eq!(decoded_u128, uuid_as_u128);
assert_eq!(decoded_u128.to_be_bytes(), uuid_bytes);
// Verify both methods produce the same encoding
assert_eq!(encoded, encoded_u128);
}
#[test]
fn test_uuid_v4_random_samples() {
// Test several UUID v4 patterns
// UUID v4 has version 4 in bits 12-15 of time_hi_and_version (byte 6)
// and variant bits 10xx in byte 8
let uuid_samples: Vec<[u8; 16]> = vec![
// Standard UUID v4 format
[
0x6b, 0xa7, 0xb8, 0x10, 0x9d, 0xad, 0x41, 0xd2, 0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4,
0x30, 0xc8,
],
// All zeros except version/variant bits
[
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00,
],
// Near max values
[
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x4f, 0xff, 0xbf, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff,
],
];
for uuid_bytes in uuid_samples {
// Test bytes_to_base36 / base36_to_bytes_fixed roundtrip
let encoded = bytes_to_base36(&uuid_bytes);
let decoded: [u8; 16] = base36_to_bytes_fixed(&encoded).unwrap();
assert_eq!(decoded, uuid_bytes);
// Test u128_to_base36 / base36_to_u128 roundtrip
let uuid_u128 = u128::from_be_bytes(uuid_bytes);
let encoded_u128 = u128_to_base36(uuid_u128);
let decoded_u128 = base36_to_u128(&encoded_u128).unwrap();
assert_eq!(decoded_u128.to_be_bytes(), uuid_bytes);
// Verify encoding is compact (UUID should be ~25 chars max in base36)
assert!(encoded.len() <= 25);
}
}
#[test]
fn test_uuid_v4_max_value() {
// Maximum possible UUID value (all 0xFF)
let max_uuid: [u8; 16] = [0xff; 16];
let encoded = bytes_to_base36(&max_uuid);
let decoded: [u8; 16] = base36_to_bytes_fixed(&encoded).unwrap();
assert_eq!(decoded, max_uuid);
// Verify via u128
let max_u128 = u128::MAX;
assert_eq!(u128::from_be_bytes(max_uuid), max_u128);
let encoded_u128 = u128_to_base36(max_u128);
assert_eq!(encoded, encoded_u128);
}
#[test]
fn test_uuid_v4_min_nonzero() {
// Minimum non-zero UUID (just 1 in the last byte)
let min_uuid: [u8; 16] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1];
let encoded = bytes_to_base36(&min_uuid);
assert_eq!(encoded, "1");
let decoded: [u8; 16] = base36_to_bytes_fixed(&encoded).unwrap();
assert_eq!(decoded, min_uuid);
}
}
Iterative Mona Lisa E2E development
Iterative as at the beginning I know least Mona Lisa, as I always want to be able to stop E2E, go wide before going deep Notes: Agents are i...
-
""" This module processes Wikipedia dump files by extracting individual articles and parsing them into a structured format, ...
-
2 Million renderings took 0.875s import java.io.IOException; import java.io.StringWriter; import java.io.Writer; import java.util.HashMap;...
-
docker pull quay.io/unstructured-io/unstructured-api 20gb image. After docker-pull: docker image inspect --format '{{json .}}' ...

.png)


.png)


.png)
