Articles

Affichage des articles associés au libellé D

Re-imagining mapstruct in D

Mapstruct is a Java library that makes it easy to map one type to another. I've been using it at work to map DTOs to JPA entities and vice versa. While it might seem unnecessary, it's one of those things I adopted just in case our REST responses deviate from our database structure. I won't go into details as to why one should or shouldn't use Mapstruct because it's beyond the scope of this article. What I want to talk about, instead, is the port itself. Motivation One of mapstruct's selling points is that it generates mappings at compile time. I simply write an interface such as this one: @Mapper(componentModel = "spring") public interface Mapper { @Mapping UserDTO toUserDTO(User entity); } With User and UserDTO being: class User { long id; String username; String password; //getters and setters } class UserDTO { long id; String username; //getters and setters } Then after building the project, an im...

Porting a Golang and Rust CLI tool to D

Image
A few days ago, in the programming subreddit, Paulo Henrique Cuchi shared his experience writing a command line tool in both Rust and Go . The tool in question is a client for his side project, Hashtrack. Hashtrack exposes a GraphQL API with which the clients can track certain twitter hashtags and get a real time list of relevant tweets. Prompted by this comment , I decided to write a D port to demonstrate how D can be used to achieve a similar goal. I'll try to keep the same structure as the one he used in his blog post. Source code on Github How did I end up using D? The main reason is that the original blog post compared statically typed languages like Go and Rust, and made honorable mentions to Nim and Crystal, but didn't mention D. D falls under this category, so I think this will make for an interesting comparison I also like D as a language and I have mentioned it in various other blog posts. Local environment The manual has a lengthy page on how to downlo...

Decoding JWTs in the terminal

Image
These past few days, I have been working on integrating IBM App ID into our Java backend and Android frontend codebases. Because of this, I would find myself going back and forth between the terminal and JWT.io whenever I need to inspect a JWT's payload. I don't want to call it a "JWT token" because that would be a bad case of RAS and I'm pedantic like that, but I digress. Instead of relying on a website to do that for me, I figured why not just do it from the terminal. I did some reading and it turns out that JWTs are relatively easy to parse : Split the token using the dot character as a delimiter Base 64 decode the first portion to get the header Base 64 decode the second portion to get the payload The third portion serves as a signing mechanism for the token. I chose to ignore the signing logic for the script I intended to write because it was irrelevant for my use case. I ended up writing a command line tool in D to help me inspect JWTs. The ma...

Re-adjusting out-of-sync subtitles.

Re-adjusting out-of-sync subtitles. Have you ever downloaded a .srt file only to find out that it is out of sync ? Even a small delay can be intolerable. Back in the day, I used VLC to readjust the subtitles in real-time. But since there wasn't a way (that I know of) to save the changes, I decided to look elsewhere. For a while I wondered how easy it would be to make a script for this simple task. After looking into it, it turned out, to my surprise, that the SRT file format is quite simple. It is composed of fragments that are formatted like this : N HH:MM:SS,mmm --> HH:MM:SS,mmm Actual subtitle It starts with a number N that identifies the fragment. This number starts from 1 and keeps incrementing for each subtitle that's displayed on screen. A line with two timestamps follows. These represent the time during which the subtitle will be displayed. Note that these are somewhat precise as they also include milliseconds. The third line contains the actual subtitle, an...

Writing a naive keylogger in D

Image
I would like to start by saying that this is strictly for educational purposes and to demonstrate how to interact with the Windows API in D. The reason why I know how keyloggers work is that I once wrote [a tool to intercept pressed keys and in return, simulate key presses that are defined in a config file] . I had to do this because some of my keys stopped working and I thought it wise to reuse some of the already functional ones as a replacement. It should come as no surprise to you at this point that I am an extremely lazy individual, so it was natural for me to writer "keymapper" instead of actually getting the keyboard fixed. I only found out a year later that the keyboard was not broken at all. In fact, I had opened up my laptop to fix the power jack which resulted in me unscrewing a bunch of stuff, so when it came time to put it back together, I botched the operation and may or may not have inserted the keyboard connector correctly. By the time I was done, I noticed ...

Decrypting .eslock files

Image
Edit of Feb 9, 2025: I built a web version of this tool . It doesn't upload the whole file for processing, only the extracted MD5 hash. (Edit of july 13, 2025: the MD5 decrypting APIs I was using are down, the tool will only give you the extracted hash but you'll need to decrypt it yourself) I was feeling nostalgic the other day so I decided to take a trip down memory lane by browsing some old entries on my phone. To my surprise, I found a few encrypted files that I don't remember putting there. After trying a few passwords that made sense, it quickly became apparent that a mental dictionary-based brute force approach was not the way to go. I turned to Google in search of answers. The first pages mention an app that can decrypt .eslock files, and while it looked promising, I wasn't sure it would be smart to trust a black box of an app with data that I once deemed private enough to encrypt. I had to find another way. This blog post in particular caught my eye. It ...

J'écris un émulateur en D

Image
J'ai une philosophie dans la vie : celle de réinventer la roue non seulement pour comprendre son fonctionnement, mais aussi pour mieux apprécier son utilité et le génie qui est derrière. J'ai appliqué cette façon de penser auparavant en créant (ou en essayant de créer) : un client HTTP, un ORM (ah ah la naïveté), un serveur HTTP (si, si), quelques jeux simples, et d'autres petits projets dont je n'arrive pas à me rappeler. Quand on ne saisit pas la complexité d'un programme, d'une machine ou autre, on a tendance à comporter comme un gamin ingrat dès que celle-ci rencontre le moindre problème, on se met à se plaindre au moindre bug ou ralentissement qui surgit, même si c'est notre faute dans 60% des cas. Parlons un peu de notre émulateur. En réalité, le terme correct pour décrire cette.. chose que j'ai écrite est "interprétateur", mais je suppose que "émulateur" est aussi valable. Je l'ai appelé ChippeD car il est écrit en D et ...