Elm and Maximum call stack size exceeded

2022-04-21

A-ha, this will be an easy blog post!

So perhaps your JavaScript console tells you Uncaught RangeError: Maximum call stack size exceeded.

That probably means your recursion isn’t tail-recursive. A recursive function calls itself. A tail-recursive function calls itself as its final step – it does not further modify the result of the recursive call.

A thing that caught me out just now, while f (a b) and f <| a b are functionally equivalent, the former is tail recursive while the latter is not.

From Basics.elm:

{-| Saying `f <| x` is exactly the same as `f x`.

It can help you avoid parentheses, which can be nice sometimes. Maybe you want
to apply a function to a `case` expression? That sort of thing.
-}
apL : (a -> b) -> a -> b
apL f x =
  f x

In f (a b), the a b part is evaluated first, and then f is called as the last thing. In f <| a b, the <| itself is application of a function, thus breaking the tail elimination as f is not the last thing called.

Elm says no runtime exceptions. Generally true, not too much of a stretch. But you still do have to watch out a tiny little bit…

Audio books

2022-02-16

Long walks, I get plenty of them these days. Usually listening to podcasts. I choose podcasts to learn something, but if you ask me what I listened to a week ago, I probably won’t be able to tell. So, if it’s just entertainment, I could listen to fiction as well?

It turns out there’s plenty of good audiobooks on LibriVox. Here’s Ruth Golding’s list of British readers on Librivox.

I recently finished listening to The Count of Monte Cristo, and the following quote near the end of the book quite struck me:

There is neither happiness nor misery in the world; there is only the comparison of one state with another, nothing more. He who has felt the deepest grief is best able to experience supreme happiness. We must have felt what it is to die that we may appreciate the enjoyments of living.

School is easier than work

2021-06-12

You think having to go to school is bad? These are the easy years, life is going to get much tougher when you’re an adult and have to work.

So adults told me when I was little, and I believed it, because I had no point of comparison. And it might be true, but misses the point.

School is forced upon children by adults, and even if it weren’t too bad, it wouldn’t be how children would choose to spend their time. Adults, however, have it exactly like the children think: adults have freedom and can do whatever they want. I’m not surprised kids want to be adults, because they want to have this same freedom. Children don’t want to have it easy, they want to have freedom.

I still regularly see adults claiming kids should be grateful for being kids. Why do adults do this? It feels like taking advantage of the kids’ naivety. Adults should be grateful for being so lucky as to be adults!

Adults: you have to work? Nope. You’ve just made some calculations and choose to work, because you want to have a roof over your head and food on the table and buy clothes and what not. It’s a choice, you can stop going to work anytime. Perhaps you can get another job, or you can do without and live under a bridge.

Children: you want to have freedom? Good news – you have freedom. When adults tell you that you must do something, you don’t have to listen. Bad news – if you don’t do what the adults want, we’ll probably punish you. I’m so sorry.

New Blog 2021

2021-05-01

I’ve not only stopped writing things on the blog, I also stopped updating its various workings, styles, etc. Time to change the latter, and see if it leads to the former. Knowing life, it probably won’t.

Why not WordPress?

WordPress has served me well since 2006. 15 years? Not bad – there are few things with this longevity in my computers. But I’ve grown afraid of it:

  • The interface keeps changing. I’m old and don’t like it when interfaces improve.
  • Everything is stored in MySQL. Fine, I can take a mysqldump every now and then? But what can I do with it really? And I have to actually keep running a MySQL server! If WordPress were able to use SQLite, I might’ve stuck with it.
  • PHP, WordPress… guess how often I updated them? Yes – how didn’t everything get hacked yet?

Why Jekyll?

I like versioning things with git. I like simplicity. I like plain text files I can just edit. Digital restraint or hipsterism?

I’ve used Middleman in the past, and now can’t update my tsumego website. Apparently my Ruby is too new for my dependencies, so I update the dependencies, and then run into a Thor issue, which also is tracked on Debian and Ubuntu, and I really don’t care about any of this and just want things to work. Jekyll seems to continue working. I hope it continues working for the next 10 years at least. And if it breaks, I’ve got everything in relatively plain html/markdown files and should be able to take it from there.

Comments

Your wonderful comments were often much more interesting than my posts, and I worked hard to preserve them. Unfortunately, I’m not sure how to make commenting possible without suck. Some options:

  1. Disqus, Facebook, etc: yes it’s easy, but where is the simplicity? I wanted more control and predictability and safe feelings, using a centralized third party to handle your precious comments would be downright irresponsible.
  2. The Jekyll resources page lists some options that allow commenting using GitHub issues: I quite like that a bit, but the end result looks dodgy – each commenter has to agree to give some random app the write access to their soul.
  3. The poor-man solution. As this is mirrored on GitHub anyway, just go and create a PR to add a comment? It’s not exactly user friendly, but hey, at least there’s a barrier to entry. I’ve written down instructions how to add comments. If GitHub ever goes away, the comments will be part of the repo and I can take them elsewhere. That, plus no one comments here anymore anyway.

Common addictions

2021-03-11

Many items of daily use have exactly the opposite effect to what’s desired. One’s body gets used to the thing, and then can’t do without, exacerbating any problems one might have started with.

In my particular case, the lip balm has been the worst offender. I started using lip balm quite young, my lips were dry and a lip balm immediately made me feel better. At some point during my use, my lips switched from becoming dry to simply burning. Suddenly, I had to apply the lip balm all the time, otherwise I’d get an immediate burning sensation. This was very annoying, but oh well, I just took a lip balm with me everywhere. Then one day it dawned on me that other people didn’t have this problem. I tried different lip balms, to no avail. Then one day, I stopped using lip balm. Within two days, the burning sensation turned into the much more bearable dry lips. After ceasing usage, my lips became ok after a week.

Things of daily use for which I’ve developed an addiction and managed to get rid of it:

  • Lip balm – the worst, avoid!
  • Nasal spray – I blame it for my prolonged colds. Perhaps three years ago, girlfriend told me not to use nasal spray when I had a cold, and I suffered a little at the beginning, but went through the cold quicker and I haven’t had much of a cold since. Coincidence? I don’t know…
  • Antiperspirant – Used one for one summer, smelled like a dead cat whenever I forgot to use it for a day. Afterwards, reeked for weeks. Never again.
  • Shampoo – I had to wash my hair every day otherwise my head would become oily and itchy. Some years ago on a yacht, Regina told a story about a woman who stopped shampooing her hair. I tried the same with great success: now that I only wash my head with warm water, it no longer feels the need to produce as much oil. Mind, I’m still bald.

Things I have not developed an addiction for:

  • Hand lotion – If you use hand lotion, I’ll show you my hands. You can admire the silkiness. I never use gloves when dealing with aggressive detergents etc.
  • That’s it! Can’t think of anything else I’m not addicted to. I’ll amend this later if I come up with something!

[This blog post brought to you by Diana. Diana said I should write a blog!]

Make Gnome on Ubuntu 20.04 usable

2020-10-06

Back when I hated Unity, I wrote down some steps to make it nicer. Well I’m still on Ubuntu (which might change soon – snaps suck), and these days like to hate on Gnome.

I’ve since moved some settings to config files, but most of the setup is still manual and will keep evolving as Gnome keeps breaking things.

Start by installing gnome-tweak-tool. Under “Windows”, choose “Focus on Hover”, perhaps tweak some other settings, and then install the Extensions.

Gnome ignores ~/.xsession, ~/.xinitrc etc, so under “Keyboard & Mouse”, choose “Additional Layout Options” and “Ctrl position” and “Swap Ctrl and Caps Lock”. Also “Switching to another layout”, “Two shifts together”.

Must have, without these I’d off Gnome:

  • Workspace Matrix – my virtual desktops must be in a grid. In settings, select “Show workspace grid in the overview”.
  • No Title Bar – Forked – Vertical space is precious, don’t take it away from me. There used to be “Pixel Saver”, then “No Title Bar”, and now “No Title Bar - Forked”. Gnome keeps breaking things, extension developers can’t keep up.
  • System Monitor Next – I really need to see what my system is doing. Same story as above, there are many versions, most no longer work.

Nice to have:

Sleep

2020-09-17

I’ve been having trouble with insomnia for several years. It came in waves, a couple weeks it was better, a couple weeks worse. I’ve been using a sleep tracking app to keep track of how bad I slept. I’d look at it and analyze everything and feel sorry for myself.

Say it was like 3 years and say I spent on average 2 hours a night not being able to sleep. That’d be over 2000 hours lost, and that’s probably a conservative estimate.

I always knew one had to get up regularly, but haven’t been doing it since probably 2012. I’d try to limit blue-light in the evening, and did all kinds of things which are tangential to good sleep. Anything but regular sleep schedule!

About two weeks ago I decided enough was enough, deleted the sleep tracking app, set up a “dumb” alarm for 7:07 every day of the week, and reduced total time in bed to something uncomfortably short (around six and half hours). For the past week I’ve been sleeping great, all thanks to these two things. I still have trouble getting up at 7:07, but that’s a short moment of discomfort compared to hours of insomnia.

There’s a wonderful page describing how to sleep better. I didn’t even need to do all that much to cure my terrible insomnia – just the basic basics helped almost immediately. I wonder, how else can I easily drastically improve my quality of life?

The joy of Elm

2020-05-02

Elm is a purely functional programming language for creating web frontend. It is strongly typed, largely influenced by Haskell – without some of the things that make Haskell difficult for newcomers, and with much better error messages.

I’ve recently written two small (~2k lines total) side projects in Elm. Writing code in Elm is an absolute joy:

  • It’s easy to get started and Elm is a simple language.
  • Very strong typing – seems somewhat stronger than in Haskell. Eg List.head is of type List a -> Maybe a and won’t crash on you in runtime – if the list is empty you get Nothing. If it compiles it usually works.
  • Elm has amazing error messages. They don’t just tell you what’s wrong, they try to explain why that could be and suggest how you could try to fix the error. I have never before encountered errors this helpful.
  • There’s Ellie – a wonderful online environment to play around and share snippets.
  • The Elm Slack is the most helpful and responsive community I’ve ever participated in.
  • Refactoring is a breeze – it compiles it works. I’ve never had a refactoring mess up things that worked before.
  • Yes Elm compiles to JavaScript, and I’ve never had to dive into the generated code.

That said, there are some potential drawbacks:

  • No higher kinded polymorphism: to map over a List, you need to use List.map, to map over Set, use Set.map. This is slightly verbose and sucks for the library developers, but isn’t a big problem for the end user.
  • Elm-land is an autocracy. Evan has been a very enlightened ruler, so this could also be seen as a benefit.
  • The development of Elm itself is intentionally slow: they try to get it right rather than get it out quick. Some things one would like in the standard library are external libraries. The repository of Elm packages is rather comprehensive.

Set DNS server in Ubuntu 20.04 Focal Fossa

2020-05-01

Set contents of /etc/systemd/resolved.conf to:

[Resolve]
DNS=45.90.28.239 45.90.30.239
Domains=~.

Apparently spaces are separators. Those are NextDNS servers in the example btw. NextDNS has not sponsored this post.

Then run: $ sudo service systemd-resolved restart

This was one of about two hundred million things that took me too long to figure out while setting up Ubuntu 20.04.


And in case you want to resolve single-label lookups, systemd-resolved don’t do that.

  • apt install dnsmasq resolvconf
  • Set /etc/dnsmasq.conf config, eg values from my.nextdns.io
  • Disable systemd-resolved
  • Set dns=dnsmasq in /etc/NetworkManager/NetworkManager.conf
  • Set nameserver 127.0.0.1 in /etc/resolvconf/resolv.conf.d/base
  • Restart all teh things

Three years of cold showers

2019-10-20

I don’t start my showers cold, but always end them so. I start the shower warm, then switch to hot, then at the end as cold as possible for about half a minute. In the beginning it was mildly uncomfortable, but I’ve become accustomed to it quickly. Showering in different places, I’m often surprised at the range of different temperatures of the coldest water available.

A cold shower really wakes you up. It closes your pores, which is good for the skin, and prevents heat loss. After a cold shower, you’ll always feel great about yourself.

Interestingly, ending with cold showers is perhaps the only positive habit I’ve built recently. I usually find forming habits challenging. This one didn’t require much work at all – usually I’m good at finding excuses, the easiest one being “I don’t have time for this”, which doesn’t apply here. Yes, I do have half a minute (and so do you, you’re reading this after all).