Tag: code

Dealing with weird keywords in Clojure specs

Recently I’ve been working on a Clojure implementation for ActivityPub. In the process I wanted to use specs, but I ran into a pretty significant problem. Namely the very first line in basically every single ActivityPub JSON object: { "@context": "https://www.w3.org/ns/activitystreams" }.

Do you see the problem? Well. This JSON will arrive at the server, where it’ll be handled by Cheshire or something along those lines. Point is, keys in JSON maps will end up turned into keywords. Clicked the link? The guide isn’t exactly specific about what can and can’t go into a keyword.


The case of the deaf BroadcastReceiver

This weekend I decided to upgrade my old Android #nowplaying app. For the new version I decided to use Kotlin and also make it usable from my Android smartwatch. Honestly, it went much smoother than expected, except for one big caveat.

Out of some weird impulse, I decided to target the Oreo SDK (26). Both my phone and my watch are Oreo based, so that wouldn’t be a problem. Yet I kept running into the weird problem that my BroadcastReceivers wouldn’t receive any intents whatsoever. Interestingly enough, the WearableListenerService I used to to listen to Messages from the watch (I want to post when I tap a button on the watch) worked almost instantly.


Sync to my phone

I originally planned to make a Rust program that would fix the broken encodings in my music files. Luckily, I could solve that without Rust. Luckily, because from what I’ve experienced since then, it would’ve been a horrible pain in the ass to do.

I still wanted to give Rust a try. Contributing Servo is pretty much out of question – it’s just too high level to jump into as a complete beginner. (And honestly, I don’t think I’ll get past “complete beginner” with Rust anytime soon if ever.) It wasn’t hard to find another issue.


Munching the squares of immortality

Become Immortal is at this point the only 1kyu kata I tried (and solved) on CodeWars. It took me 3-4 days to solve it. It was definitely pretty damn difficult to figure out, but in the end I managed it myself.

Looking at the example tests it was immediately obvious that trying to generate the actual rectangles and xoring everything was out of question. For the heck of it I tried once, but even for the last “basic test” I’d run out of memory (on my desktop) very quick. Sure it works fine if the rectangle is 30-40 rows and columns, but not for scales in the millions. I used it to dump rectangles on the console and double check my solution.


Product of integer partitions

Another CodeWars kata, by the same person who did Twice linear. It was annoying in a different way. Once again, a naive solution was out of question (or so I thought), so I kept trying to figure out a way to shortcut the whole problem with maths.

Generating the integer partitions (and their products) isn’t particularly difficult. There are plenty of resources out there about how to do it – though for some reason mostly in Python.


Talk about linear

There’s a CodeWars kata called Twice linear. It’s one of those problems where a naive solution is just not feasible. Not to mention the first tests aren’t indicative of what’s expected so by the time I hit the wall of very big numbers, I already had a solidified (and naive) mental model. Getting rid of that isn’t an easy task.

Generating the list of numbers isn’t difficult. Keeping it sorted and not adding duplicates makes it a bit more tricky. I tried using Ruby’s SortedSet at first, then Enumerators and plain loops, but everything crapped out at bigger numbers. All tests are supposed to run within 12 seconds on CodeWars, and my code at that point was taking 20+ minutes to run for 60000.


CodeWars

I really like Medium’s weekly digest. It keeps providing me with great articles. A few weeks back there was one with advice from a young girl developer, and (among other pretty solid advice) there was a mention of a certain CodeWars. First time I heard of it. This was Thursday evening.

On Sunday I had 50 or so kata behind me and I was challenging an 1kyu one. It’s really addictive, because I just keep pushing the “next kata” button and can’t rest until I’ve dealt with it. However, this approach doesn’t work if I wanted to solve 5 kata a day as advised, because the algo keeps giving me harder and harder challenges, and even “easier” ones end up taking a few hours.


Subcomponents in Vue.js lists

In my winter break I’ve been working on a Vue.js client for Mastodon. I’ve got two big reasons for doing it: I want link/video previews on my timeline and I have to get familiar with Vue for work.

I’m not very familiar with Mastodon’s API, nor with Vue, so I think I’ve been running into lots of problems that I shouldn’t have. For example, I added card (that’s the Mastodon name for link or video previews) autoloading to the timeline and I noticed something weird.


Rails counter_cacheの罠

counter_cacheはいいぞ。 #いいぞ

counter_cacheって?

アプリの大きさや目的に関わらず結構早い段階からいろんなものを数えたくなる。ユーザー何人?記事についてるタグ何個?


ルビーのパパ

昨日またルビーイベント参加してきた。今回はルビーの作者マッツさんの話が聞けるという訳で楽しみだった。実際に気になっていたことや、ここから半年で気になるだろう的なこともいっぱい聞けてよかった。