r/code 6d ago

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

Thumbnail github.com
4 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 8d ago

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 13d ago

Help Please how to do Scraping

5 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 19d ago

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.


r/code Jun 22 '26

Go Excessive nil pointer checks in Go

Thumbnail konradreiche.com
3 Upvotes

r/code Jun 19 '26

Jai Jai: The World Is Not Ready | Valigo

Thumbnail youtube.com
3 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
6 Upvotes

r/code Jun 11 '26

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

4 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
3 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

6 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 19 '26

Help Please Built this on Code.org and need help

Enable HLS to view with audio, or disable this notification

3 Upvotes

Object.assign(player, sweepCollider(player, group, 2));

function sweepCollider(collider, target, checkNumber) {
checkNumber = Math.floor(Math.max(1, checkNumber));
var tempGroup = createGroup();
for (var i = 1; i <= checkNumber; i++) {
var sprite = createSprite(collider.x, collider.y, collider.width, collider.height);
sprite.velocityX = collider.velocityX * i / checkNumber;
sprite.velocityY = collider.velocityY * i / checkNumber;
sprite.x -= collider.velocityX - sprite.velocityX;
sprite.y -= collider.velocityY - sprite.velocityY;
sprite.visible = false;
tempGroup.add(sprite);
}
var tempReturnValue = {};
tempGroup.overlap(target, function(colliderSprite, targetSprite) {
var differenceX = colliderSprite.x - targetSprite.x;
var differenceY = targetSprite.y - colliderSprite.y;
var tempWidth = (colliderSprite.width + targetSprite.width) / 2;
var tempHeight = (colliderSprite.height + targetSprite.height) / 2;
var tempVX = colliderSprite.velocityX - targetSprite.velocityX;
var tempVY = colliderSprite.velocityY - targetSprite.velocityY;
if (tempVX < 0) {
differenceX = Math.max(0, tempWidth - differenceX);
} else {
differenceX = Math.max(0, tempWidth + differenceX);
}
if (tempVY < 0) {
differenceY = Math.max(0, tempHeight + differenceY);
} else {
differenceY = Math.max(0, tempHeight - differenceY);
}
var pathX = differenceX / Math.abs(tempVX);
var pathY = differenceY / Math.abs(tempVY);
if (isNaN(pathX)) {
pathX = Infinity;
}
if (isNaN(pathY) ) {
pathY = Infinity;
}
if (pathX < pathY) {
if (tempVX < 0) {
colliderSprite.x += differenceX;
} else {
colliderSprite.x -= differenceX;
}
colliderSprite.velocityX = 0;
Object.assign(tempReturnValue, {x: colliderSprite.x, velocityX: colliderSprite.velocityX});
if (Object.keys(tempReturnValue).length < 4) {
for (var i = 0; i < tempGroup.length; i++) {
Object.assign(tempGroup.get(i), {x: colliderSprite.x, velocityX: colliderSprite.velocityX});
tempGroup.get(i).collide(targetSprite);
}
} else {
return;
}
} else {
if (tempVY < 0) {
colliderSprite.y += differenceY;
} else {
colliderSprite.y -= differenceY;
colliderSprite.velocityY = 0;
}
Object.assign(tempReturnValue, {y: colliderSprite.y, velocityY: colliderSprite.velocityY});
if (Object.keys(tempReturnValue).length < 4) {
for (var l = 0; l < tempGroup.length; l++) {
Object.assign(tempGroup.get(l), {y: colliderSprite.y, velocityY: colliderSprite.velocityY});
tempGroup.get(l).collide(targetSprite);
}
} else {
return;
}
}
});
return tempReturnValue;
}
Object.assign = function(object, properties) {
for (var i in properties) {
object[i] = properties[i];
}
};

The problem is that since the objects the player collides with are in a group, the objects are checked left to right, top to bottom since that’s the order they were added. However, this means that when moving into a block and jumping, the player first collides with the block above and to the right, since the player moved right into the block. This cancels their upward momentum before pushing them out of the lower block next, so then the player just doesn’t jump. This also happens with moving to the left, as the velocity y makes the player clip slightly into the ground, and therefore sometimes catches the edge when crossing tile borders and stops momentum.

In the video, the player can’t jump when moving into a wall. Also, the player will sometimes get caught on tile borders when moving horizontally, resulting in the player coming to an abrupt full stop and an inability to move left without first moving right.

How do I stop the player from snagging on tile edges?


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
6 Upvotes

r/code May 12 '26

Python Basic Text-Based RPG

6 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

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

Thumbnail packagemain.tech
2 Upvotes

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 😭

9 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 08 '26

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

Thumbnail youtube.com
3 Upvotes

r/code May 08 '26

My Own Code Hey I am Aman, a class 9 indian student, I have made a proggraming language ,it's extensions(named traits), it's package manager and registry for trait!

0 Upvotes

Hey everyone, I am Aman, currently studying in my 9th std and I have created a language by the name Ethos that can be used as a beginner language to teach fundamentals and basics of programming to beginners and mostly school students.

What is Ethos?

Ethos is a programming language with an English‑based syntax. Every statement is a sentence. Every sentence ends with a period. No brackets, no semicolons, no cryptic symbols. It transpiles to Python, so it's quick to get running and easy to extend.

What is Forge?

Forge is the official package manager for Ethos. It installs Soft Traits (Python packages from PyPI) and Hard Traits (compiled native binaries) into your Ethos environment.

Example code:

```ethos

ask "What's your name? " into name.

set greeting to "Hello, ".

say greeting.

say name.

set score to 95.

if score is above 90.

say "That's an A.".

otherwise if score is at least 75.

say "That's a B.".

otherwise.

say "Keep going.".

end.

```

Extensions:

· Soft Traits – Python packages from PyPI or local files

· Hard Traits – Compiled C/C++/Rust binaries loaded via ctypes

Getting Started:

· Windows – Combined installer for both Ethos and Forge (releases page)

· macOS – Combined .pkg installer for Apple Silicon and Intel Macs

· Linux – OBS repos, AUR, and universal tarball (see https://github.com/AmanCode22/ethos-lang/blob/main/LINUX_INSTALL.md)

- Android Via Termux - Install deb or add repo( for more see (https://github.com/AmanCode22/ethos-lang#android-via-termux)

Hard Trait APIs:

- C: https://github.com/AmanCode22/ethos-trait-c-template(Example Trait: https://github.com/AmanCode22/ethos-trait-greetc)

C++: https://github.com/AmanCode22/ethos-trait-cpp-template(Example Trait: https://github.com/AmanCode22/ethos-trait-greetcpp)

Rust: https://github.com/AmanCode22/ethos-trait-rust-template(Example Trait: https://github.com/AmanCode22/ethos-trait-greetr)

Ethos Foundry:

Hard Traits registry for Ethos.

Use Forge to install native C/C++/Rust extensions. Hosted on Cloudflare Pages.

You can add your trait by opening a pr.

Hosted at:

https://foundry-ethos.pages.dev

And

https://amancode22.github.io/ethos-foundry/

What's next?

· Future Rust rewrite for native compilation and performance

Contributions welcome! Especially Hard Trait SDK bindings for Go, Java, Zig, or any language other than C/C++ and Rust.

Links:

· Ethos: https://github.com/AmanCode22/ethos-lang

· Forge: https://github.com/AmanCode22/forge

I would love to hear your feedback and suggestions!

It's currently in beta and would publish stable after its much tested as no more features are planned from my side all bugs are fixed according to me , but still I want some testers! After testing for suggestions/issue please feel free to open issue and also please tell me what you think of it here in reddit.

Edit: If you liked it then please star the repo


r/code May 07 '26

Blog Unsigned sizes: a five year mistake

Thumbnail c3-lang.org
10 Upvotes