An LRU in Go (Part 2)

So we create a concurrency-safe LRU in the last post, but it was too slow when used concurrently because of all the locking. Reducing the amount of time spent waiting on locks is actually not trivial, but not undoable. You can use things like the sync/atomic package to cleverly change pointers back and forth with basically no locking needed. However, our situation is more complicated than that: we use two separate data structures that need to be updated atomically (the list itself and the index.

An LRU in Go (Part 1)

In my job, I often catch myself having to implement a way to keep data in memory so I can use them at a later time. Sometimes this is for caching purposes, sometimes it’s to keep track of what I’ve sent some other service earlier so I can create a diff or something. Reasons are plenty. I noticed that I keep writing versions of the same thing over and over and when we’re doing that, maybe it’s time to try and create a more generic solution.

How to Use Fileserver With Gorillas Subrouter

I’ve just spent much more time than I ever wanted to get this right, so here’s how I did it for future reference. I have a function that returns an http.Handler, kind of like this: func Handler(prefix string) http.Handler { r := mux.NewRouter().PathPrefix(prefix).Subrouter() r.HandleFunc("/foo/", fooHandler).Methods("GET") r.HandleFunc("/bar/", barHandler).Methods("GET") return r } The prefix could be something like “/api/” or “/ui” or whatever, so this http.Handler will serve /api/foo and /api/bar, for example.

Scitech Links November 4 2017

China wants to be the first country to build a practical space-based solar power station. Space-based solar power would presumably be much more sustainable and clean than fossil fuels and more efficient than the current sustainable energy sources we have on Earth. There are many problems still to be solved before these power plants can exist so China’s expectations are more wishful thinking than based on reality. Astronomers have found a massive gas-giant that is astonishingly 23.

Science and Tech Links (October 21, 2017)

Rodney Brooks writes about the 7 Deadly Sins of AI Predictions. The text articulates a lot of my personal doubts about much of what I see on the news regarding AI. Some people seemed to read this article as a rebutal of AI itself, which I find puzzling as I did not read that at all. If anything, Brooks seems to believe AI will be much bigger than we can possible imagine.

Caddy and the Importance of Licenses

I haven’t commented on the recent brouhaha caused by Caddy’s decision to offer commercial licences, so I’ll do it briefly here before moving to the important part. I am fine with it. I don’t love it, but it’s fine. The Caddy authors have every right to try to profit from their work. Best of luck to them, they deserve it. Do I think they mangled the announcement? Yes. Do I think the amount of vitriol out there was justified?

Returns in Go and C#

Whenever someone posts anything related to the Go programming language on Hacker News, it never takes long before someone complains about error handling. I find it interesting because it is exactly one of things I like the most about Go. I don’t want to specifically talk about error handling though. I want to talk about a feature that is intrinsically tied to it in Go: the ability of functions to return multiple values

Casting objects and boxing

I’m back from a trip to a customer. How was it? Okay. I got more snow that I expected on the way there, so the drive wasn’t much fun. Then again, a part of the trip goes through a beautiful forest that was worth everything else. Cool! Also, while showing the customer a new feature, the app crashed. Typical. Blame it on Murphy! That’s what I did at first. Then I blamed it on the developer.

Retreating back into my bubble

A few months back I decided to try and burst out of my bubble. I then decided to follow some public figures from all sides on Facebook and Twitter. On Facebook this is particularly weird because you’re forced to like the page. So it tells the world “Roberto likes Mrs. Public-Figure”, which is sometimes undesirable. Still, I wanted to see what both sides of the political spectrum were saying. Also, I consider myself a centrist so I expected to agree with everyone on at least something.

When the revolution comes

I’ve been reading this interesting article on the New Yorker about how the super-rich are preparing for the fall of civilization. What really caught my eye was right at the top of the article: a picture of an armed, private soldier guarding the entrance to the Survival Condo, a project to convert missile silos into “luxury appartments.” My very first thought was that as soon as the revolution comes, the mercenaries who serve as security will simply kill the people insideĀ and take over.