dlow's bloghttps://blog.dlow.me/Recent content on dlow's blogHugo -- gohugo.ioen-usSun, 08 Nov 2020 09:45:27 +0000Setting up Home Lab with VPS and Wireguardhttps://blog.dlow.me/everything/setting-up-homelab-with-vps-and-wireguard/Sun, 08 Nov 2020 09:45:27 +0000https://blog.dlow.me/everything/setting-up-homelab-with-vps-and-wireguard/This post documents my journey setting up a home lab, where I run open source software like shaarli, wallabag and nextcloud, and exposing it on the internet using a cheap VPS and Wireguard.
There is no shortage of online tutorials on installing wireguard on Ubuntu, Debian, and Raspberry pi. However, it still took me about 1 full day to get a full system working. Half of it was debugging why it wireguard wasn’t installed properly.A side car puzzlehttps://blog.dlow.me/maths/a-side-car-puzzle/Wed, 28 Oct 2020 23:59:41 +0000https://blog.dlow.me/maths/a-side-car-puzzle/Problem 32 from the penguin book of puzzles.
A Side-car Problem Atkins, Baldwin and Clarke had to go a journey of fifty-two miles across country. Atkins had a motor-bicycle with side-car for one passenger. How was he to take one of his companions a certain distance, drop him on the road to walk the remainder of the way, and return to pick up the second friend, who, starting at the same time, was already walking on the road, so that they should all arrive at their destination at exactly the same time?A walking puzzle where you're only told distanceshttps://blog.dlow.me/maths/a-walking-puzzle-where-youre-only-told-distances/Wed, 28 Oct 2020 23:16:36 +0000https://blog.dlow.me/maths/a-walking-puzzle-where-youre-only-told-distances/Problem 39 from the penguin book of puzzles.
A man named Jones set out to walk from A to B, and on the road he met his friend Kenward, ten miles from A, who had left B at exactly the same time. Jones executed his commission at B and, without delay, set out on his return journey, while Kenward as promptly returned from A to B . They met twelve miles from B.A walking puzzle where you're only told about timehttps://blog.dlow.me/maths/a-walking-puzzle-where-youre-only-told-about-time/Tue, 27 Oct 2020 21:51:13 +0000https://blog.dlow.me/maths/a-walking-puzzle-where-youre-only-told-about-time/Problem 26 in penguin book of puzzles.
A Walking Puzzle A man set out at noon to walk from Appleminster to Boneyham, and a friend of his started at two p.m. on the same day to walk from Boneyham to Appleminster. They met on the road at five minutes past four o’clock and each man reached his destination at exactly the same time. Can you say at what time they both arrived?IMO 2020https://blog.dlow.me/maths/imo-2020/Wed, 14 Oct 2020 08:09:47 +0100https://blog.dlow.me/maths/imo-2020/IMO 2020 was an interesting one because it was completely virtual due to Covid-19. Personally, I would feel disappointed if I were a contestant because I would have loved to use this as an opportunity to visit Russia, which would have been a costly trip on its own.
The problems can be found on the imo-official website.
I tried the problems and this is the write up for my attempts and motivations.Objects and Data Structure/Containerhttps://blog.dlow.me/programming/object-and-data-structure/Wed, 14 Oct 2020 06:34:42 +0100https://blog.dlow.me/programming/object-and-data-structure/The differences and how it affects code maintenance.Using the reflect packagehttps://blog.dlow.me/programming/golang/using-the-reflect-package/Tue, 15 Sep 2020 22:54:19 +0100https://blog.dlow.me/programming/golang/using-the-reflect-package/An example of how to use reflect package to access fields of unexported structs in golangLiar's paradox and truthfulness of statementshttps://blog.dlow.me/everything/liars-paradox-and-truthfulness-of-statements/Sun, 13 Sep 2020 10:18:25 +0100https://blog.dlow.me/everything/liars-paradox-and-truthfulness-of-statements/An essay on truthfulness of statements and what we can learn from themGeometric puzzles using elementary operationshttps://blog.dlow.me/maths/constructing-tangent/Fri, 17 Jul 2020 10:11:55 +0100https://blog.dlow.me/maths/constructing-tangent/I’ve been playing Euclidia and I love it so far. Here’s some of the interesting challenges that I was stuck at for a while. The stage which the puzzle happens is included in the brackets.
The following challenges must be solved using only elementary Euclidean operations, which is defined as a construction that can be made with a real compass and straight edge. Marking intersections are not counted as an operation.Some notes harmonic meanhttps://blog.dlow.me/maths/harmonic-mean/Thu, 16 Jul 2020 09:44:46 +0100https://blog.dlow.me/maths/harmonic-mean/These are some notes on harmonic mean taken some time in 2016.
Harmonic mean We start by introducing three number sequences:
An Arithmetic Progression (AP) is given by $a$, $a + d$, $a + 2d$, … A Geometric Progression (GP) is given by $a$, $ar$, $ar^2$, … A Harmonic Progression (HP) is given by $\{1/a_i\}$ where $\{a_i\}$ is an AP. Given a number sequence, we can define its mean.Geometric problem 1https://blog.dlow.me/maths/geometry-1/Thu, 16 Jul 2020 09:00:15 +0100https://blog.dlow.me/maths/geometry-1/Found this while browsing and thought it was interesting. I’m still deciding whether this should live on this blog. Don’t permalink to this yet!
Source
Technically there are two possible answers for x, but if you restrict ABC to be acute, then there is only one solution.
Posed differently:
Given an angle A and an internal angle bisector of A Let $A = 2 \beta $ Choose a point D on the bisector Choose B on one leg of the angle such that $DBA = \alpha$ Find the loci of C on the other leg such that $DCB = 90^\circ -\alpha - \beta$ Solutions: Stolen from the comments from the original source: Using Ceva’s theorem: We can simplify it to become $$ \frac{\sin(\alpha)}{\sin(\pi/2-\beta-x)} \cdot \frac{\sin(\pi/2 - \alpha - \beta)}{\sin(\beta)} = 1 $$Metaphorical fences in programminghttps://blog.dlow.me/programming/metaphorical-fences/Mon, 06 Jul 2020 08:53:17 +0100https://blog.dlow.me/programming/metaphorical-fences/Imagine that you bought a new house with a huge backyard garden and there’s this ugly high opaque fence in your garden. You’re eager to redesign the garden to your liking, and wish to tear down this fence. Before you tear the fence down in this thought experiment, stop and think about why it was put up in the first place. Perhaps it was to prevent wild animals from entering your premise, or perhaps it was to protect your privacy from nosy neighbours?Powershell in 2020https://blog.dlow.me/programming/powershell-in-2020/Tue, 09 Jun 2020 09:20:00 +0100https://blog.dlow.me/programming/powershell-in-2020/One day, my colleague told me that powershell is actually decent and that convinced me to try it out. The main motivation for trying out comes from my wanting to do automation on my personal laptop which runs Windows. At my day job, I work with Linux servers so my expertise is with working with Linux shells like bash or zsh, often writing scripts for mundane tasks. When I want to do any automation on Windows, I go through the awkardness of running a virtual machine (VM) like Windows Subsystem for Linux (WSL).Reflections on note taking softwarehttps://blog.dlow.me/everything/reflections-on-note-taking-software/Fri, 29 May 2020 22:44:18 +0100https://blog.dlow.me/everything/reflections-on-note-taking-software/With so much information out there today, having a system to process and manage them is crucial to not be overwhelmed. For me this involves having a good digital information capture and retrieval workflow, a.k.a note taking. I classify notes into three categories: micro text notes (<500 characters), notes consisting primarily text (including code), and notes that have embedded media like images. Micro text covers consists of fleeting thoughts and requires almost immediate offloading from the mind otherwise it will be forgotten.Anti pattern: turning struct into interfacehttps://blog.dlow.me/programming/golang/anti-pattern-turning-struct-into-interface/Sun, 24 May 2020 12:44:55 +0100https://blog.dlow.me/programming/golang/anti-pattern-turning-struct-into-interface/Previously I wrote about using struct embedding to achieve pseudo inheritance for code reuse. In this post, I want to explore an example of what I think is an anti pattern as a result of the lack of inheritance and how I think it could be better.
In the absence of inheritance in golang, it is very tempting to turn fields into functions of an interface.
As an motivating example, consider the following:Struct embedding as implicit compositionhttps://blog.dlow.me/programming/golang/struct-embedding/Fri, 22 May 2020 11:26:33 +0100https://blog.dlow.me/programming/golang/struct-embedding/In programming, the principle “don’t repeat yourself”, DRY for short, recommends that we try to reuse the same implementation where possible. In this post, I will cover what it’s like to do it in golang through struct embedding and my personal thoughts on that pattern.
Golang struct embedding One common way of code reuse is inheritance. In Java, we can do this by implementing a method on the parent class, then subclasses will inherit this implementation.Using arc lengths to solve geometry problemshttps://blog.dlow.me/maths/using-arc-length-to-solve-gemetry-problems/Thu, 21 May 2020 10:22:50 +0100https://blog.dlow.me/maths/using-arc-length-to-solve-gemetry-problems/Let’s start with this problem that appeared on my news feed.
WARNING: Stop reading if you want to solve it yourself first.
Recall from high school maths that angle subtended by an arc (or chord) to a point on the circumference of the circle does not change as the point moves around the circle.
We can use this to transform the given angle problem into one that deals with lengths.An example of leaky abstractionhttps://blog.dlow.me/programming/some-thoughts-on-leaky-abstraction/Sun, 19 Apr 2020 20:06:51 +0000https://blog.dlow.me/programming/some-thoughts-on-leaky-abstraction/Leaky abstraction An example of the maxim that all abstractions are leaky.
type Book struct { author String } func (b *Book) Validate() error { return nil } DB layer
func (d *DB) UpdateBook(b *Book, newAuthor String) error { b.author = newAuthor if err := b.Validate(); err != nil { return fmt.errorf("bad validation") } if err := d.Update(b); err != nil { return fmt.errorf("Server error") } return nil } ... API layerFlexbox for humanhttps://blog.dlow.me/programming/webdev/flexbox-for-human/Sun, 19 Apr 2020 08:28:00 +0000https://blog.dlow.me/programming/webdev/flexbox-for-human/.container { border: 1px solid #c3c3c3; display: flex; flex-direction: row; } .container div { width: 60px; height: 60px; } Easy :) Flexbox is great and makes centering things easy, and that’s mostly what I’ve ever used it for. However, when I want more complex layout arrangement I find myself just searching for answers on stack overflow without actually learning how to do it. I decided to make an attempt to understand flexbox properly and share my findings in this post.The ambiguous builder patternhttps://blog.dlow.me/programming/the-ambiguous-builder-pattern/Wed, 11 Dec 2019 23:08:12 +0000https://blog.dlow.me/programming/the-ambiguous-builder-pattern/There are two interpretations of the builder pattern. There is the Gang of four (GOF)1 definition which to me resembles a lot like an inverted strategy pattern, and it is concerned with separating the procedure of building a complex object from the representation of its parts. Then there is what I call the fluent builder pattern which is really trying to solve the constructor with many parameter problem.
Gang Of Four interpretation/definition The motivating example given in the book is an odd one if you’re expecting a fluent style builder pattern.