Cloning an infrared remote controller

Context : One of my earliest paychecks went into a cheap 22" TV. It's not fancy at all, but it was a nice upgrade from the old Sony Trinitron TV that was starting to show its age. The new TV has a brand name of "Vision", which is less glamorous than "Sony", but it has been working well so far, so I can't really complain. Just the other day, I found out that it is possible to get it to record something while it's on standby. It's a feature I never knew I needed until I discovered it. A couple of months after I got it, I ran into a problem with the remote controller. Luckily it turned out to be caused by a dead battery. Even though it was trivial to fix, this minor incident planted the seed of fear in me. Since the TV doesn't have physical buttons, I concluded that it would become useless should the remote stop working for some reason or another. Because of this, I decided to make a backup of the remote in case something happens to it. To d

Porting a Golang and Rust CLI tool to D

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

My experience with Win by Inwi

In my previous post, I mentioned how I was using a data plan that amounts to 10 DH per gigabyte. Being a relatively light streamer, I can usually get by with 10 gigabytes per month. These days however, I often find myself abusing my data plan for calls and screen sharing and whatnot. This month for example, I spent 250 DH on internet alone. With a monthly spending like that, I realized that I might as well get ADSL or a cheap optical fiber subscription. So why didn't I ? Well, for one, I don't want to get tied down by a monthly subscription. Secondly, I don't want something that requires a heavy installation with all the fees and the time that it implies. And finally, I want to have the option of carrying it with me wherever I want. When I was searching for alternatives, a friend of mine suggested Win by Inwi . I looked into it and it seemed to satisfy my needs of portability and ease of use. In short, you can customize your plan as you wish , handle the paperwork onlin

Life during the COVID-19 lockdown

Given the state that the world is in right now, many companies, mine included , offered their employees the option of working from home. I decided to jump on the "working from home" bandwagon and write an entry describing how I personally managed it. Hardware A few days before the state of emergency took effect, I bought an HP monitor, a Logitech keyboard and the cheapest mouse I could find. With this, I set up an impromptu workstation for the days to come. I chose this monitor because it supports both HDMI and Display Port. I use the former with my work issued laptop and the latter with my own Thinkpad. The choice of keyboard was driven by the lack of an alternative. Most of the keyboards I was shown looked like cheap knockoffs of popular brands. As for the mouse, I picked the cheapest one because I'm not a heavy mouse user, and I figured any mouse would do the trick. I regretted this decision when I found out that the mouse sometimes releases mid-click, which resul

Decoding JWTs in the terminal

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

Quickly sharing files over wifi

I sometimes find myself needing to transfer a file to someone at the office. It's a common scenario. To solve this problem, a few options present themselves. The easiest one, in my opinion, is to just serve the file in question through HTTP from my own machine on the local network. I then send the link to whoever needs it. If you think about it, you will realize that it has many advantages : It's easy to setup Everyone these days has an HTTP client on their computer Files can be protected from prying eyes thanks to HTTP authorization You can resume downloads You can serve entire directories It has, however, a few downsides : The file is no longer available if the server is turned off The client has to be on the same network It's probably not the most secure solution out there To use this method, I usually resort to python's built in HTTP server. It's only a matter of navigating to the directory you want to serve and running the python3 -m http.serv

Inclusive looping in D

D lets us write for loops in the following form : foreach(i; 0 .. 5) { //do something with i } While convenient, I sometimes find myself needing to iterate over a range inclusively, which means that I want the upper bound to be included in the loop. Kotlin supports both inclusive and exclusive looping with the .. and until operators. Nim's .. and ..< operators behave respectively like Kotlin's .. and until. Swift supports a similar construct as well. D doesn't support one natively, but it shouldn't be too difficult for us to come up with something. Naive solution The following hack makes use of UFCS to provide a readable solution to the problem outlined above : T inc(T)(T input) { return cast(T)(input + 1); } void main() { foreach(i; 0 .. { writeln(i); } } inc stands for inc lusive, but it can also be thought of as inc rement since that's what really happens here. UFCS lets us write instead of the more verb