RSSAmplifier

Blog

Infinite monkey - Nico Brailovsky's blog

Wroks in my machine

monkeywritescode.blogspot.comRSS feed ↗25 posts

Latest posts

Fix Spotify deeplinking in Linux + custom SpotiWeb UI

After a recent update I found my custom Spotify UI (*) wasn't working. The way my custom UI works is by generating a simple list of followed artists, and then playing in the native app by using deep-linking. A recent update seems to have broken this in Linux based OSes, so here's my fix: sudo mv /usr/share/spotify/spotify /usr/share/spotify/spotify.real sudo echo '/usr/share/spotify/spotify.real…

Translated to Chinese!

Small celebratory post, because I never expected it: Someone translated one of my open source projects to Chinese!

Bash script preamble

All background Bash scripts should start with this preamble: set -euo pipefail exec > ~/log.log 2>&1 There are countless articles explaining why, and the main purpose of this one is a reminder for myself, so I won't go into the details. For reference: -e halts the script on error -u errors when using an undefined variable -o pipefail makes pipe error return value sane exec > ~/log.log 2>&1…

Where is the fun in that?

You can always find coders asking why coding isn't fun anymore. I can somewhat relate but I never understood why the answer isn't obvious: coding isn't software engineering. When you go from coding to engineering, the focus changes. A lot of the interesting stuff is there, but there's also not-interesting-stuff in the mix. Maybe testing and documenting isn't your thing, you just want to build…

reboot succesful?

Since "migrating" from Wordpress to Blogspot: Traffic to Wordpress fell from ~100ish visitors a day to ~30 or ~40ish. This site went from 0 to also ~30 or ~40ish. That went much better than I expected, considering I couldn't set up a proper HTTP301-permanently moved (WP charges you for that, which IMO is slight extortionate for a site I don't want to monetize). Let's see how it goes 10 years from…

sudo reboot

Recently found out Wordpress had pretty aggressive ads on my blog. That worked as the encouragement I was needing to work on a task I'd been putting off for years: fix bit-rotted content! I took the opportunity to fix all (most) broken links and source code snippets from the last 14 years. It was supposed to be a short sed script, which of course ended up being 3 days of work - a lot of it manual.…

Vimtip: Open path

If you are editing a file which references another file (like, say, a cpp file #including a header file) then you can use Vim to open the referenced file in a new tab like this: #include "foo/bar.h" Place your cursor anywhere in "foo/bar.h" and press `gf` to open the referenced path. More interestingly, you can also do `C-w`, release and then `gf` to open in a new tab. Today I learned you can also…

Weak symbols to mock c-APIs with gmock/gtest

I recently worked with a c-style API interface which wasn't very open to mocking. The API in question looked something like this: handle_t h = api_open(); api_foo(h, param1, param2); api_foo2(h, 42); api_close(h); This *almost* looks like a C++ interface, with extra steps that make it really really hard to mock (and, thus, to test). If it were a c++ interface, it would be possible to "virtualize"…

jq: grep and prettify json

If you don't use jq , you are missing a very important utility in your bash toolset. jq let's you query and filter json files from a cli. Just like awk or sed, js's "language" is basically write only, meaning whenever you need to do something there's a 99% chance you'll just be copy-pasting recipes from Stackoverflow until you find the one that works for you. Here are a couple of recipes I found…

Mixin(ish) classes with parameter packs in C++

For some reason I couldn't find many examples of how to use a parameter pack as a mixin, to enable different features with no runtime overhead. Here is a full example of you might implement this (be aware there are some nasal daemons in the code below!). The technique is really based on this one line: int dummy[sizeof...(Config)] = { (Config::apply(p), 0)... }; This idiom will unpack a parameter…

Presenting tips: make your presentations suck a bit less

I spent the last few years in a role that required a significant part in communicating with other people. Some of that in the form of slides and presentations, because not having slides isn't enterprisy. I'm far from being a great presenter, but I did learn a thing or two. All this is quite general, so it should apply to any kind of topic... as long as that topic is software engineering. I'm still…

Bash tip: Default value for a variable

In my Bash scripts, I used to hack my way around default values for variables. Turns out there is a very simple way to give your variables a default value while also letting other override them if they want to: FOO=${BAR-bar} If someone export's BAR, then FOO will equals the already exported value of $BAR, if $BAR doesn't exist then FOO will have the value of the literal 'bar'.

std::is_constant_evaluated: make debugging a little bit harder for
yourself!

Let's pretend you find this: const int a = foo(); int b = foo(); Would you be tempted to assume that a==b, always? I would. What if 'foo' actually depends on a global variable, and its return value depends on that global setting? Suddenly the code above will raise a few eyebrows in a code review session. Coming to your friendly c++20 standard now: constexpr int foo() { return…

Vim multiple search

I keep forgetting about this one. Maybe writing it down will help me remember: Vim can search for (and highlight) multiple patterns at the same time. Just start your search with \v and split the patterns with |. Eg: :/\vfoo|bar

Bash: Color in command line prompt PS1

I'm lately dealing with lots of hosts in different environments (eg local, dev, test, etc). Some actions are safe to perform in some of these hosts, in others not so much. To help quickly figure out which hosts are safe, I wanted to add a color to my Bash prompt (PS1) - for example green for dev, where it's unlikely I'll break anything other than my stuff, red for hosts where carelessness might…

The bestest autocomplete for Vim

TL;DR: I like YouCompleteMe A post in Hacker News drew me to look at autocompletion in Vim. After trying a few plugins years before, I settled for the available-by-default autocomplete in Vim. It's pretty dumb, but pretty dumb covers 90% of what I need: autocompletionForReallyUglyOrLongNames. Vim's omnifunc completer is enough if no fancy features are necessary: fast, available, trivial to setup.…

Howto: shutdown a TV with HDMI CEC Chromecast

That's a long title just to say "how to turn off your TV". Only I want to show how to do it even if you lost your remote control. Chromecast can turn your TV on and off, as long as it supports something called HDMI CEC. Of course the Chromecast itself needs to be powered, i.e. you can't plug it to a USB port in your TV. The "on" part is easy: you just start casting something ( your pictures, for…

Say nice things

As software developers, we need to put much more emphasis on positive interactions with our peers. Engineering requires critical thinking. Looking for cases where something (code!) will break. Criticizing what we do, on the hope of doing it better, is a key and necessary aspect of our profession. However, even when done properly (already a hard enough job!) this practice emphasizes negative…

GCC instrumentation flag: slow everything down!

Here's a nice gcc tip if you think your code is running too fast: instrument everything! (Ok, it may also work if you need to create a profile of your application but for some reason Valgrind isn't your thing). Compile with g++ foo.cpp -ggdb3 -finstrument-functions You can get a list of symbols with nm and c++filt, or you can implement your own elf reader too for extra fun. extern "C" { bool…

Chromecastic Slideshow

Plug for a new script I've been working on: https://github.com/nicolasbrailo/ChromecasticSlideshow Slideshows in Chromecast directly from your filesystem, without going through any online service. No Google Photos, Facebook or anything else: plain old random files straight from your disk to your Chromecast. Hope someone else finds this useful!

VimTip: Search and f(replace)

Pre-tip: When using search and replace in Vim, you don't need to use slashes This works just fine: %s#search#replace Did you know $replace doesn't have to be a literal expression? You can also use Vim functions! For example: %s#bar#\=line('.') will replace every occurrence of 'bar' for its line number. You can get creative and use any other Vimscript function.

std::byte - great idea. Meh execution?

I love the idea of C++17's std::byte . A data-type that makes it explicit we're dealing with ugly low-level details? What's there not to love! One thing only, turns out. First, the good part: separating character (human) representation from binary (low-level) representation is brilliant. No implicit conversion between the two separates the domains very well and creates a much clearer interface.…

-Wmisleading-indentation

This gcc switch is a few years old but I discovered it recently. I'm not sure if that means my code is always very clean or my toolchain too oudated... in any case, -Wmisleading-indentation (which you get with -Wall) warns about this gotcha: if (foo) bar(); baz(); Neat!

GitHub tip: Prefill a bug report

Getting feedback from users is hard. In a platform such as Android, with apps evaluated in a couple of seconds, it's even harder. While trying to get bug reports for VlcFreemote I found a neat GitHub trick: you can pre-fill a bug report by using url parameters. For example, check this link: https://github.com/nicolasbrailo/VlcFreemote/issues/new?title=foo&body=bar Awesome! Takes a second and makes…

Happiest bug report

Something is wrong: I'm happy over a bug report! A few years back I developed a VlcRemote control app for Android. According to this chart , I didn't actually save any time doing so. The time I spent spent developing the app is more than the cumulative time I would have spent by getting up from the couch and manually controlling VLC. That said, not having to leave the coziness of a warm blanket in…