Rust module system

I’ve been writing small programs in rust as a way to learn the language. While trying to organize one of the application, I realized I didn’t fully understand how the module system worked. The official docs say that if you have your code organized in a single rs file, you can just split up the module into different files and the same rules apply. Without understanding how the module system actually works, you might be mislead into making false assumptions and hence run into errors that you might not understand how to solve. I think I must have read the documentation 3-4 times before I realize that just skimming over the the documentation wasn’t going to work. ...

January 27, 2020 · 7 min · 1448 words · Bilal Durrani

A bit of rust

While killing some time online, I can into a blog post that explained the origins of some weird numbers by looking at the hex data and converting that to strings. This gave me something to try in rust. Specifically, taking the bit of python code that converted strings into unsigned 32-bit and 16-bit integers and porting that to rust. I started by converting a string to bytes. 1 2 3 let raw_bytes_slice = command.as_bytes(); let raw_bytes_vector = raw_bytes_slice.to_ve println!("raw_bytes {:?}", raw_bytes); Rust strings are UTF-8. I had a set of well-defined strings so there would be no encoding issues. ...

January 19, 2020 · 3 min · 521 words · Bilal Durrani

PSA: You can keep using your original Doxie with Windows 10

This is more of a reminder for me than anything else. I’ve had my doxie original for a number of years now. With Windows 10, they stopped supporting the driver. After some investigation, turns out an original Doxie is actually a DocketPORT467. If you still want to keep using your original Doxie, but you’re ok with going without the other Doxie software, just grab the drivers from the docucap website I’ll also upload the drivers for Windows 10 here. This is current as of Dec 2019. ...

December 25, 2019 · 1 min · 112 words · Bilal Durrani

Using find/map/reduce with javascript iterators

I come from the .NET world, where I’m used to using LINQ for massaging collections of data in a clear functional way. ES6 added lots of useful functions to Array that lets me write code like 1 [1,2,3,4].filter(x => x ===3).map(x => x *2); I like this style because it avoids deep nested loops and makes the intention of the code very clear. To my surprise, I learnt that I can’t write code like this for other data structures like Map. because these expose their data as iterators and not as Arrays. ...

March 23, 2018 · 6 min · 1194 words · Bilal Durrani

Mocha tests hanging with Timers

When setting up unit tests for a specific JS class, I noticed that even though the mocha based unit tests was always passing, the test process would never actually exit. Here is what the class looked like, in it’s pared down form. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 class Blah { constructor() { this.stopCleanup = false; const interval = 1000; const run = () => { this.dothings(); setTimeout(run, interval); }; setTimeout(run, interval); } methodUnderTest(){ // do some other work } dothings() { console.log('doing things'); } } There was a timer running in the class that would clean up some resources in regular intervals. ...

February 21, 2018 · 3 min · 469 words · Bilal Durrani

Highlight optional meetings in outlook

I find that Outlook calendar (I currently use the 2016 version) doesn’t highlight optional meeting invites very well. You have to read the fine print of the invite or dig around in the Scheduling assistant in the Calendar view. One trick I found on stack overflow lets you change the color of any meetings on the calendar where you were an optional invite. Right click on the calendar Select View Settings Select Conditional formatting Add a new rule, give it a name and a colour of choice Select Condition and then Advanced Click Field, select All appointment fields and then Optional attendees Set the condition to includes and the value to your name. Optional appointments should then show up in a different colour. ...

February 7, 2018 · 1 min · 133 words · Bilal Durrani

Running node http in the background

This is something simple I needed to do, but had to dig around a bit to figure it out since I’m a Windows guy. I just wanted to run http-server as a background job in linux. 1 npm run server > http.log 2>&1 & Redirect stderr (the 2) to http.log, referred to by &1. The & at the end just means run in the background.

January 24, 2018 · 1 min · 65 words · Bilal Durrani

VMVare and Windows 10

I recently upgraded by developer machine to Windows 10. After the upgrade, VMWare would fail to start any image with an error about disabling Hyper-V. Specifically this was the error 1 VMware Workstation and Hyper-V are not compatible. Remove the Hyper-V role from the system before running VMware Workstation After many cycles of uninstalling and reinstalling VMWare and Hyper-V, turns out the problem is actually related to something called Device Guard. ...

January 22, 2018 · 1 min · 133 words · Bilal Durrani

Moving to Hugo

I’m trying to bring this blog back to life. I realized one of the things that was preventing me from updating more often was the fact that Jekyll is really complicated to set up on Windows. I would take a break from writing anything, come back and try to set up the toolchain, only to discover that something had updated and the existing toolchain broke on Windows. Hugo is easy. There is a single executable I can download annd run. The only dependencies I have is pygments, a python module that is a quick pip install away. No building anything from any SDK. ...

January 18, 2018 · 1 min · 148 words · Bilal Durrani

Inline assembly in C#

I was working on trying to figure out how sqeeze out some more speed for some calculations, which involved the following bit of math. SumOfSquares=i=0Ndatai2 The language of choice was C# with Visual Studio 2013 for a 64-bit process. One idea was to try and use SSE to improve the throughput of the computation. Unfortunately the .NET framework currently (as of .NET 4.2) does not generate SSE instructions as part of its JIT compiler. A workaround would be to make a dll with the math function exported, and call that exported function from C# using PInvoke. The Visual Studio compiler (2012 and above) is an excellant optimizing compiler with the ability to auto-vectorize loops. But then I would have to add a C dll as a dependency of my C# application. One more file to keep track just for a single calculation. ...

October 1, 2015 · 16 min · 3326 words · Bilal Durrani