Articles

Quickly sharing files over wifi

Image
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 setupEveryone these days has an HTTP client on their computerFiles can be protected from prying eyes thanks to HTTP authorizationYou can resume downloadsYou can serve entire directoriesIt has, however, a few downsides :The file is no longer available if the server is turned offThe client has to be on the same networkIt's probably not the most secure solution out thereTo 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.server command. The directory l…

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 solutionThe 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 .. 5.inc) { writeln(i); } } inc stands for inclusive, but it can also be thought of as increment since that's what really happens here. UFCS lets us write 5.inc instead of the more verbose inc(5) alte…

Web scraping tips and tricks

I've listed various webscraping-related tips and tricks below. I have collected these throughout the years, hopefully you will find them useful.Tip #1 : don't do itScraping should only be considered as a last resort. If the website from which you intend to extract information offers an API, use the API instead. It'll be easier to parse a nicely formatted JSON response then it would be to download an entire web page and go through verbose and sometimes malformed HTML just to extract a small piece of information.Tip #2 : check for mobile versionsMobile versions of websites tend to be lighter and more to the point, which makes them easier to scrape. Mobile websites also tend to be less reliant on Javascript than their desktop counterparts. Certain websites offer a mobile.* or m.* domain, while others simply redirect you based on your user agent. In this case, you might need to craft a specific user agent in order to fool the website into thinking you're on mobile. Others,…

Does C++ have the array[x, y] syntax ?

The short answer is no. At least not out of the box.This happened a few months ago but I forgot to document it. I was reading the solutions of that [Monday's r/dailyprogrammer challenge] when I came across [an elegant C++ solution] that was posted by fellow user MrFluffyThePanda. Having written [a C++ solution] myself, I found it particularly interesting that MrFluffyThePanda's solution used a syntax I did not know C++ supported : int* field = new int[8,8]; The field array was later accessed with the field[x, y] syntax. The only language I know of that supports this syntax is C#, where they're referred to as "rectangular arrays". Was it one of those [secret C++ gems] that no one (read: me) knew about ?The answer was much simpler than that. My initial assumption was that the compiler translates field[x, y] into field[x * width + y], a method I sometimes use to avoid the headaches of working with multidimensional arrays in C. This was suggested by the fact that fie…

Hotmail is having problems today

Outlook hasn't been functioning properly today. My Hotmail account can neither send nor receive emails, and after checking Google News, it appears that [I am not the only one] who's suffering from this issue.Earlier this afternoon, I messaged a seller on Avito via a form on their website in order to inquire about a certain product. Avito offers the possibility of emailing you a copy of the message, and although I checked that option in the form, I never received the email.At first I suspected it was a problem on Avito, or that maybe the email ended up in my spam folder. I then ran a few tests that consisted of sending emails between my main Outook account and my secondary GMail account, then between two Outlook email addresses, both from my mail client and from the web interfaces. Unfortunately, none of the emails were delivered. It was only after I turned to Google for help that I came across the article linked above.I'm only writing about this to let it be known that thi…

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, and the f…

Remapping an arbitrary combo to ALT TAB in (L)Ubuntu

My laptop has a missing Tab key. This has led me to some [interesting workarounds], but I could never quite get the keyboard's behavior back to what it once was with these hackish solutions.I installed Lubuntu in dual boot with Windows 7 a few weeks ago. Lubuntu comes with Openbox, a customizable and lightweight window manager. I didn't feel like rewriting Keymapper for Linux since it relies on low-level hooks so I turned to Google in search for an alternative. I quickly discovered that it's possible to use some of the already-installed tools to accomplish what I needed.One such tool is Xmodmap. It lets you configure a mapping for a given pair of keys. In order to figure out the key codes I needed, I used xev, yet another utility whose purpose is to open a small window and print events on the terminal as they happen.Let's say you want to remap 1 (& on an azerty keyboard) to tab. Running xev and pressing 1 while the xev window is on focus produces the following outp…