Skip to content

Passive data structure in TypeScript

I really like this kind of construct in C/C++

struct Point
  double x;
  double y;

as a way to have a structured dictionary that should have nice auto-completion.

After learning the TypeScript way to do it in a course I forgot it, before finding it back so I’ll save it here for safekeeping ^^ Basically, the TypeScript solution to create a PDS / “plain old data structure” / “POD-structs” (not really sure how to call those…) is to hijack the interface, like this:

interface Point
  number x;
  number y;

This way when you declare

let mypoint: Point = {x: 1, y: 5};

you’ll then have autocompletion to access mypoint.x and mypoint.y. And since TypeScript’s interfaces completely vanish during compilation, that “misuse” won’t have any consequence.

Thanks to this article with many strange data structures for pointing me to the solution 🙂

Posted in JavaScript / TypeScript / Node.js.

How to remove a printer that keeps coming back in Windows 7

I never had any trouble with the “Devices and Printers” control panel in Windows 7 before, apart from the usual difficulties when trying to connect to networks printers. So I was pretty puzzled when I got into trouble trying to disconnect from one.
Basically, I take my laptop at work, and when I changed office there was an old printer from the former office that I didn’t manage to delete: every time I deleted it, it would seem successful but it would come back whenever I restarted the computer (popping up a firewall alert in the process).

I eventually found a way to delete it manually, for good:
– go to Services (if you don’t know how, type “Services” in the start menu)
– find the Print Spooler service and stop it
– open Windows Explorer and go to the C:\Windows\System32\spool\Printers folder. That’s where things can get complicated: ideally, you should delete just the file related to the printer you want to remove (for me it was easy, I only had 2 files and the creation dates were different enough for me to be able to pick the right one). If you can’t identify the right file, I guess you can either remove them all (if you don’t mind losing your other printers’ settings), or make a backup of them and try to delete (and restore) the files one by one (NB: I didn’t try that so I’m not 100% sure making a backup of those files is enough to restore your settings – but I don’t see why it wouldn’t be).
– go back to Services and restart the Print Spooler service.

For me, that did the trick. If you still have difficulties, maybe check out this answer on Superuser, with more options like the use of printui

Posted in Windows Se7en.

How to get a random item from a JavaScript array

var myArray = ['a','b','c'];
var randomItem = myArray[Math.floor(Math.random()*myArray.length)]

Math.random() returns a number between 0 (included) and 1 (not included), which is why this piece of code won’t overshoot by picking a number equal to the array length (reminder: array indexes start at 0, meaning last index is length – 1).

Math.round() is not appropriate as it would result in sometimes hitting a number equal to the array length. Hence the Math.floor().

Posted in JavaScript / TypeScript / Node.js.

How to configure email and name in Git

I’m using SourceTree as a Git GUI for the sake of simplicity, but some settings are still hard to find. Among those, how to set up (or change) the name and email that you’ll automatically attach to your commits, either system-wide or for the current repository.
Gladly, it’s easy enough to do via the command line: for the current repository, that would be simply:

git config ""
git config "My Name"

If you want to set those globally, just add a --global flag, e.g.:

git config --global ""

Posted in programming.

How to make Tor Browser remember permission settings across sessions

Warning: this is not recommended at all, as it makes it easier to link your different browsing sessions. I’m actually mainly posting it here for future reference on how to disable it. If you really do know what you’re doing, read on.

It’s simply a boolean setting: in about:config, set permissions.memory_only to false if you want Tor Browser to remember your permissions from a browsing session to another. This can be used for instance when you’re tired of being asked for permissions to use HTML 5’s Canvas-of-Doom. Personally, I’d prefer an easy setting to just kill Canvas once and for all.

Posted in privacy, security, Tor.

A few things I learned from my Windows 10 disaster recovery

After a crash, Windows 10 managed to restart but decided its partition should be “fixed”. So I rebooted to let it “fix” it, which caused it to become unbootable. My few recovery attempts failed, and since I had a partition setup that would preserve my important data (ie, everything except what the stupid programs decide to store into %appdata%), I quickly reinstalled. And learned a few interesting things in the process.

About installing over a previous Windows

First, when you install Windows on a partition which already contained Windows, it warns you it will move the previous Windows installation to a Windows.old folder. I was afraid it would only move the former “Windows” folder there, but it turned out it moved everything on the partition there (NB: I only had standard folders, like Users, Program Files, etc, so I’m not sure it would also move custom root folders although my guess is it probably would). Pretty handy to grab your former program settings (those in %appdata%, sadly not those in the registry), documents (I got to keep my desktop contents, yay), etc.
Edit: well actually, something strange happened just the day after I wrote this part: most of the contents of that Windows.old folder vanished overnight… :s So now I’m happy I used a Linux LiveUSB (NB: Tails is nice for that, as it’s pretty small) to duplicate the contents of the C: partition elsewhere myself.

About Cortana and other bloatware

Second, there exists a version without Cortana, Windows Store, and Windows Media Player. It’s version N (without Windows Media Player) and Long Term Servicing Branch (LTSB), which is without Cortana, Windows Store, but also the Edge browser, Photo Viewer and the UWP version of Calculator. Wikipedia has a nice page detailing the different editions and notes that Windows 10 Enterprise N LTSB is the most stripped down edition of Windows 10 available.

The N flavor will create some issues for video playback in your browsers. For instance, Youtube will work, but Twitch won’t (there are other ways to watch Twitch streams though, for instance Streamlink). If that turns out to be a blocker, however, you can download a patch by Microsoft (the “Media Feature Pack”), which will restore those functionalities. So there’s no risk in trying out N, it’s not irreversible.

The LTSB comes without Edge, so I was wondering if I’d need Firefox on a stick to get started 😉 But it turns out it contains… good old Internet Explorer 11. The lack of Photo Viewer means your pictures will open in Paint (or Internet Explorer as usual for the GIFs). I still have to find a replacement, because opening pictures in Paint works great but I find it a bit risky (I’m always afraid to accidentally draw a few pixels and save)

About PuTTY and my backup software

Third, I already used it before but I had forgotten about it, PuTTY settings can be easily exported to a reg file with this command:

regedit /e "%userprofile%\Desktop\putty.reg" HKEY_CURRENT_USER\Software\SimonTatham

Of course, this only works on a working Windows. In my case I gladly had those settings +/- duplicated exactly on another computer, so yay ^^

Fourth (and last for this post ^^), backup software are unequally easy to migrate.
For SpiderOak, I simply copied the old AppData/Local/SpiderOak folder and then reinstalled SpiderOak, and it behaved just as if nothing changed.
For LiveDrive, I used a backup I had of the registry settings (and found nothing of value in %AppData%), and it recognized the computer but had lost the most important backup settings (namely, which folders to back up, for fucking fuck sake)

Well that will be all. Hopefully I won’t have a use for this in the future, but for some reason I’m pretty sure I will :/

Posted in Windows 10.

Emojis in a MySQL database

A while back, I’ve had issues when user input contained an emoji: the database field would then cut after (and including) the first emoji). My table seemed to be configured properly for Unicode though, so that was a bit puzzling.

It turned out that “utf8“, in MySQL/MariaDB language, doesn’t actually mean the real, proper UTF-8: it contains a MySQL-specific limitation preventing use of characters numbered above 0xFFFD (source, with also a comparison between utf8mb4_unicode_ci and utf8mb4_general_ci). So you’ll want to use utf8mb4, which is the real deal and will store emojis without issue.
The good news is, if you already have an utf8 database or table, the migration may be as easy as just switching the column types (still you should make a backup first, just to be safe), at least for me it was. You might want to have a look at this first, though: How to support full Unicode in MySQL databases.

While looking into this, I also found some stuff about utf32. Not sure if I’ll ever use it but here it is for bookmarking purpose.

Sorry that was once again a brief post, I’m cleaning up my tab groups because after Firefox decided to kill the feature, they now also killed the extension that tried to continue the feature… Thanks again Mozilla! 😡

Posted in web development.

How to generate a file of a specified size on Windows

The command is:
fsutil file createnew [filename] [size in byte]

Note that it doesn’t generate random contents: the contents is all zero bytes. If you want a random file, you can use something like Random Data File Creator, or encrypt a zero file that you generated with fsutil (I find AES Crypt pretty convenient for that purpose)

Posted in Windows.

How to get rid of Music.UI.exe

Lately (maybe since last month), I’ve had that Music.UI.exe executable, located in C:\Program Files\WindowsApps\Microsoft.ZuneMusic_3.6.19261.0_x64__8wekyb3d8bbwe, regularly (like, every few hours) popping up in my firewall, trying to access the network 😮 Every time, I denied it and killed it, but it kept coming back.

I tried deleting the file, with no success (permission denied, even as admin).
I eventually found the solution: go to Settings > Privacy > Background Apps, and turn off Groove Music. While you’re at it, you might want to disable the shitload of other apps that are there too.

Posted in Windows 10.

How to prevent Windows 10’s auto volume reduction?

Sadly this time it is still an open question.
Whenever there’s a system beep sound, Windows 10 automatically lowers the volume of everything else for a pretty damned long while (maybe 5-10 seconds). This is particularly annoying when trying to adjust the volume, as adjusting the volume will itself generate a beep, causing the volume to be automatically reduced (WTF were those engineers thinking when then did that? :o).

Anyway, apparently this could be caused by Windows trying to be smart and “guessing” that you are using VoIP, and then reducing the volume of other activities so that you can hear your communication better. The solution, as I found there for instance, would be to disable that feature, by going to system sound settings, then in the “Communications” tab and choosing “When Windows detects communications activity, do nothing” (the default is a huge “reduce the volume of other sounds by 80%” :o).

Sadly, for me it didn’t do the trick, even after a restart (which was suggested there).

I’m running out of ideas to fix this (already), so if you have a magical solution do post it in the comments ^^

Off-topic bonus: apparently Windows 10 comes with an annoyance called Xbox DVR, which doesn’t seem to be necessarily linked to owning an Xbox and can fuck up performance in some games. Steam provides a guide to disable it there.

Posted in Windows 10.