Articles

Affichage des articles du 2019

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 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 .. 5.inc) { 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 5.inc instead of the more verb