1
Fork 0
mirror of https://github.com/RGBCube/Site synced 2025-07-30 20:47:46 +00:00

Add blog post Cosmic Drift

This commit is contained in:
RGBCube 2024-04-02 09:20:14 +03:00
parent 0507f81c21
commit 1c5f607302
No known key found for this signature in database

58
site/blog/cosmic-drift.md Normal file
View file

@ -0,0 +1,58 @@
---
title: Cosmic Drift
description: Or how I missed the school bus because of a cosmic ray.
date: 2024-04-02
tags:
- time
- unix-timestamps
---
So, every day I wake up at 6:55, get dressed by 7, walk to the bus stop
by 7:13 and board the bus around 7:17. Today was different.
My alarm that I have set for 6:55 rang at 7:12 and as a result, I missed the bus.
> No, I didn't sleep in. There was no note in the UI saying this was a repeat alarm,
> which there is if you snooze it or let it expire.
Surely something was happening. Machines don't break whenever they want, they're
mostly deterministic. And I doubt Samsung engineers wrote code to delay the alarm
by 12 minutes on the date after April 1st.
So, _what_ was happening? I entered the Python repl to test out a theory:
```py
>>> alarm_time = 6*60*60 + 55*60
>>> alarm_time_real = 7*60*60 + 12*60
>>> alarm_time_real - alarm_time
1020
```
The total time was off by about 1020 seconds. Give or take 60, as my phone
doesn't display the seconds of the time.
> Since I'm using a Samsung SM-B310E, I assumed it uses seconds to store
> the time. You can't even see seconds noted anywhere so I feel this is a normal
> assumption. Even if it is false, the math still adds up for milliseconds.
Wow, I thought. That's really close to 1024 (which is 2 to the power of 10).
Maybe the 11th bit got flipped, making it increment 1024?
```py
>>> bin(alarm_time)
'0b110000101000100'
>>> alarm_time |= 1 << 10
>>> bin(alarm_time)
'0b110010101000100'
>>> alarm_time - alarm_time_real
-4
```
Aha! So the 11th bit got flipped by something. And that something was probably
a cosmic ray.
My main takeaway from this event is to create more than one alarm, for extra redundancy.
Who knew being prone to sleeping in could save you from your alarm getting
shifted 12 minutes into the future :^).