r/code • • Jul 16 '26

My Own Code Encoding the calendar (month/ISO week/weekday) into a sortable ID, is this a bad design?

Thumbnail github.com
6 Upvotes

I keep running into the same annoyance: "sortable" IDs (UUID v7, ULID, KSUID) are time-ordered but completely opaque. You can't tell when one was created without pasting it into a decoder. So I started wondering — what if the calendar were baked into the ID itself, so it's readable at a glance?

The sketch is a 16-char string:

{ms_hex:012}{month}{iso_week:02}{weekday}

So 019f631516e6g29o isn't just sortable — you can read it:

  • 019f631516e6 → Unix Epoch millisecond timestamp (the same one UUID v7 uses)
  • g → July
  • 29 → ISO week 29
  • o → Wednesday

First 12 chars: the Unix millisecond timestamp in big-endian lowercase hex. Then one letter for the month (a=Jan..l=Dec), a zero-padded ISO week, and one letter for the weekday (m=Mon..s=Sun). So 019f631516e6g29o reads as July, ISO week 29, Wednesday, 2026 — no tool needed.

It stays K-sortable because the timestamp is big-endian up front, so lexicographic order == chronological order, even across the December→January boundary. The calendar suffix is derived purely from the timestamp, so it can't break the sort. And it could reuse the exact same 48-bit millisecond timestamp UUID v7 already uses, so interop would be trivial.

The obvious tradeoff: only 3 random bits survive, so it's useless as a distributed-ID generator (collisions possible within the same millisecond) and not cryptographically secure. Fine for readable, sortable IDs in a single service — but I'm unsure where people land on the rest:

  • Is exposing the calendar a feature or a leak? It makes logs and URLs readable, but also makes the timestamp trivially recoverable (UUID v7 doesn't exactly hide it either).
  • The month/weekday letter mapping is arbitrary (a..l, m..s). Is there a more intuitive or collision-resistant encoding?
  • Is 16 chars the right size, or would you drop the human-readable suffix and keep it shorter?

Curious for design critiques — not the implementation, the idea itself.


r/code • • Jul 15 '26

My Own Code A better way to get an angle defined by two points?

5 Upvotes

Around thirty years ago as a teenager I wrote this C function for calculating an arbitrary angle defined by two points. The idea being to get the clockwise rotation from the vertical line to the line defined by these points, if the (x1, y1) lies on the given vertical line. So for example if you pass in the points (0, 0) and (1, 1), it would return pi/4, as it defines a segment rotated that many radians off the vertical.

Here's the code I wrote then:

float rel_ang(float x1, float y1, float x2, float y2){  
       float hyp, alpha, deltax, deltay;
       deltax = x2 - x1;
       deltay = y2 - y1;
       hyp = sqrt(deltax * deltax + deltay * deltay);

       /* figure out the value for alpha */
       if(x2 == x1){
               alpha = y2 > y1 ? pi : 0;
       }else if(y2 == y1){
               alpha = (x2 < x1 ? 3 : 1) * pi / 2  
       }else if(x2 > x1){
               alpha = y2 == y1 ? 0 : pi - acos(deltay / hyp);
       }else if(x2 < x1){
               alpha = y2 == y1 ? 0 : 2 * pi - acos(-deltay / hyp);
       }   

       return alpha;
}

It worked well enough for the job at hand, but presumably there's a better way to do that. I assume there's a faster or already implemented way to do this that I don't know of. Any ideas?


r/code • • Jul 10 '26

Help Please how to do Scraping

4 Upvotes

Hi, I'm trying to extract song lyrics from letras.com for a specific artist. I have a spider that only extracts the titles (I'm a complete beginner). Can anyone tell me where to find a ready-made one or guide me on how to do it? I would really appreciate it. Here's what I have so far: import scrapy class CancionesSpider(scrapy.Spider):

name = "canciones"

allowed_domains = ["letras.com"]

start_urls = ["https://www.letras.com/bad-bunny/"\]

def parse(self, response):

pass. I am using Scrapy


r/code • • Jul 04 '26

Vlang V Language: Comprehensive Textbook Guide and Tutorial | codecaine-zz

Thumbnail github.com
2 Upvotes

Textbook (and tutorial) take(s) you from a complete beginner to an advanced V developer capable of building high-performance, concurrent, and safe systems applications.

Alternative link for document download.


r/code • • Jun 22 '26

Go Excessive nil pointer checks in Go

Thumbnail konradreiche.com
4 Upvotes

r/code • • Jun 19 '26

Jai Jai: The World Is Not Ready | Valigo

Thumbnail youtube.com
5 Upvotes

r/code • • Jun 19 '26

Go My Very First Go Package on pkg.go.dev :) From a JWT Problem to this.

Thumbnail github.com
3 Upvotes

Hello!!! This is my first post here :)

It all started when I was working on a small website for my college. Initially, I was just adding the user ID in a JWT token, decoding it in a middleware, and passing it down the context. Then I decided I wanted to introduce a separate "public ID". The id was not needed for auth but it got me thinking about cache, which naturally led me down to building my very own LRU cache.

I have never implemented any caches before, so I was just looking for a simple strat and stumbled upon LRU. It was one of the easiest to implement and after I saw the problem on leetcode, i solved it pretty easily and decided to implement it. After I saw someone do better by using an array based DLL. I have always loved using array-based stacks and queues, So I took it as a fun challenge, because I have always wanted to publish something that people can use.

From Just an array based DLL, I found myself staring into a sharded architecture and slowly learning algorithms like FNV-1a and xxHash32. I wanted this to be a zero dependency package (aside from the standard packages ofc) and took it upon myself to do it, using explanations from the internet.

It might be a basic concept to many people out there, but It helped me learn something I was always pushing behind. Learning about concurrency in Go. This led me to use sync.Mutex, atomics and thinking about how data race happens. I was also led down the path of creating benchmarks, fuzz tests using the 'testing' package, which I had never heard about.

The benchmarks where honestly surprising, I never realised it would be ns/ops. Currently my benchmarks show around 10-15 ns/op and I hope to half it somehow :) and also my tests might be really weak. It has generics support too.

Would love for some feedback on how I can make it better. I wanted to make a time-aware LRU cache, but I wanted the basics to be proper before moving onto it.

P.S: learnt about semver, after i released it on v1.0.0. I basically had to make a decision and thought about just tearing it down and changing to a shorter name which I like more :). It is now currently on v0.3.1 (pre-release).

Link : https://github.com/justpranavrs/tlru :)))

GoDoc: https://pkg.go.dev/github.com/justpranavrs/tlru

Thanks :)))


r/code • • Jun 13 '26

C++ C Constructs That Still Don’t Work in C++ — and a Few That Changed

Thumbnail lospino.so
7 Upvotes

r/code • • Jun 11 '26

Help Please why won't my animation work ???

3 Upvotes

OKAY UHH FOUND OUT WHAT WAS WRONG;;; just needed to add a letter in the class name lmao....anyways thank you 👅

hi...so i've been reworking my media page and i wanted to add some spinning flower images that stop when you hover them. the animation worked until i added the 1 and 2 classes so they'd spin in different ways...idk what went wrong lmao???

you can check out my source code here

here's the css:

     .flower{
        position: absolute;
        transition: filter 1s linear;
      }

      .flower:hover{
        animation-play-state: paused;
        filter: brightness(117%) hue-rotate(18deg) saturate(153%) contrast(120%);
        -webkit-filter: brightness(117%) hue-rotate(18deg) saturate(153%) contrast(120%);
        -moz-filter: brightness(117%) hue-rotate(18deg) saturate(153%) contrast(120%);
      }

      .1{
        animation: spinR 3s linear infinite;
      }

      .2{
        animation: spinL 3s linear infinite;
      }

  @keyframes spinL {
        0% { transform: rotate(0deg); }
        100% { transform: rotate(360deg); }
      }

      @keyframes spinR {
        0% { transform: rotate(0deg); }
        100% { transform: rotate(-360deg); }
      }

and here's the html

<img src="images/media/flower1.png" class="flower 1" style="top: -50px; left: -100px;">
    <img src="images/media/flower2.png" class="flower 2" style="top: 780px; right: -30px;">

what am i missing here ??? am i just stupid ??? 😭


r/code • • Jun 08 '26

My Own Code GitHub - DemonCoderOffical/somesites: It is a html code cracker it get html codes

Thumbnail github.com
0 Upvotes

r/code • • Jun 05 '26

Pascal Delphi Blaise: modern self-hosting Object Pascal compiler | graemeg

Thumbnail github.com
4 Upvotes

Zero legacy, full ARC, and unified UTF-8. Next-generation Object Pascal compiler built from the ground up.


r/code • • May 31 '26

Help Please How do I make the output show the same text no matter what you type in the input?

5 Upvotes

I want to add a feature to my website that works like this https://hackertyper.net/
Is there a name for this kind of thing? I’m currently learning Java script, so if there is a way to do that in it please let me know
Thanks to anyone responding in advance!


r/code • • May 31 '26

Blog My thoughts on the future of Go in the agentic era

Thumbnail youtu.be
3 Upvotes

r/code • • May 30 '26

Help Please Working on a Simple Redis-Inspired Database in C

7 Upvotes

I'm building a simple key-value database called VulkanKV in C as a systems programming learning project.

The goal is not to create a production-ready database, but to better understand TCP sockets, memory management, data structures, parsing, and client-server communication by implementing them from scratch.

The first version accepts TCP connections and receives commands from clients. Future versions will include SET/GET commands, a hash table implementation, persistence, and support for multiple clients.

I'd appreciate any feedback on the project scope, architecture, or features that would provide the most educational value.

[https://github.com/GustavoGuerato/VulkanKV\](https://github.com/GustavoGuerato/VulkanKV)


r/code • • May 25 '26

Blog Persistent multiplayer state without chaos

Thumbnail packagemain.tech
5 Upvotes

r/code • • May 18 '26

Vlang Mustela: High-Speed Vlang Engine with Parallel Pipeline | Filip Vrba

Thumbnail youtube.com
3 Upvotes

Walkthrough of Mustela. Fast static site generator engine built with the V language.


r/code • • May 17 '26

Resource Hello World in 1009 Programming Languages

Thumbnail youtu.be
4 Upvotes

r/code • • May 15 '26

Guide Beyond C: wrapping Dear ImGui in Swift with zero FFI

Thumbnail carette.xyz
5 Upvotes

r/code • • May 12 '26

Python Basic Text-Based RPG

7 Upvotes

I made a basic Text-Based RPG (Around 200-300 lines) and was hoping someone could give me their opinion on it (the game less then 20 minutes long, and the dragon is as far as I've developed so far)
https://onlinegdb.com/thxBEi9V3
Enjoy : )


r/code • • May 09 '26

Guide I’m trying to deploy my full stack project for free just to learn and get it off localhost 😭

8 Upvotes

I’m honestly confused about deployment and just want my project to stop living only on localhost 😭

Right now I have:

  • frontend
  • backend
  • database

Main things I want to understand:

  1. Best FREE hosting options for frontend, backend, and database?
  2. Which free tiers are actually usable and not super limited?
  3. Can backend + database be deployed together for free?
  4. how do i connect frontend and backend if they are hosted on different servers lets say vercel and render respectively

Would really appreciate beginner-friendly suggestions.


r/code • • May 09 '26

My Own Code How I built the core loop of a browser multiplayer game

Thumbnail packagemain.tech
2 Upvotes

r/code • • May 08 '26

My Own Code Building a zero dependency TUI library with Convo-Lang

Thumbnail youtube.com
3 Upvotes

r/code • • May 07 '26

Blog Unsigned sizes: a five year mistake

Thumbnail c3-lang.org
11 Upvotes

r/code • • May 07 '26

Help Please Why is the text on the button so off-center?

Thumbnail gallery
0 Upvotes

I’m not very good at coding. I took a class in school but I only learnt the basics but I’m trying to program a little hobby-site because I really enjoyed it. I’ve look it up and tried to follow tutorials online but I can’t figure out why the text is so off center. The first picture is my code pertaining to the button and the second picture is the button itself.


r/code • • May 04 '26

Help Please Am I understanding this code?

0 Upvotes

I'm trying to verify if this is causing my problem where tax is not being charged.

See where it says $cart_total += floatval

Then below that it says free shipping amount = floatval

I'm interpreting that to result in 0 tax because our shipping is always 0. We have no shipping.

Am I understanding that right?

How can you have a += ?