31 July 2017

How to build waifu2x command-line version on osx

Waifu2x is a popular image converter backed by neural-network models, typically used to upscale images from anime. The various web versions are easy to use but typically don't allow for batch-processing, because it's a relatively intensive operation. However, there is a command-line version that is fairly easy to compile on Windows and Linux. OSX support was notably absent... until now.
These are the steps required to get it working on Mac:
  1. brew tap science && brew install opencv3
    (if you don't have Homebrew, go install it now - it's wonderful)
  2. git clone https://github.com/DeadSix27/waifu2x-converter-cpp.git
  3. cd waifu2x-converter-cpp
  4. cmake -DOVERRIDE_OPENCV=1 -DOPENCV_PREFIX=/usr/local/Cellar/opencv3/<your version here> . (remember the dot at the end!)
  5. make -j4
At this point, you have the executable waifu2x-converter-cpp in the directory; you can make install if you really want to (I prefer to keep custom stuff in my home dir). To test it's working, the following command should return info on your system:

./waifu2x-converter-cpp --list-processor

If you need some images to test, here you can get quite a few stills from the gorgeous 5 Centimeters Per Second. Note: you might have to rename the folder "models_rgb" into "models" before converting.

BONUS: Qt GUI

If you hate the command-line, there is a simple QT wrapper. To compile it you will need Qt-Creator and Qt installed and configured. This used to be very complicated, but both items have now been packaged for Homebrew so it's all awesomely simple (well, compared to what it was, at least). Note that you still have to do the steps above - the wrapper needs the waifu2x executable to be already compiled.

Install and configure Qt and Qt-Creator

  1. brew install qt && brew cask install qt-creator
  2. Launch Qt Creator from Launchpad, then go to Qt Creator -> Preferences (Command + ,)
  3. Select Build & Run, then the Qt Versions tab
  4. Click on Add... and select “Macintosh HD”
  5. Press Command + Shift + . to show hidden directories
  6. select /usr/local/Cellar/qt5/<your version>/bin/qmake then OK and OK again to close the Preferences window
  7. Reopen Preferences -> Build & Run, select the Kits tab and click Add
  8. Set the following options:
    • Name to something like "Qt CLang Desktop" 
    • Both Compiler options to Clang X86 64bit
    • Qt Version to the version you just created
    • Click on Make Default then OK to close Preferences.

Compile waifu2x-converter-qt

  1. git clone https://github.com/toyg/waifu2x-converter-qt.git (the original repo looks abandoned, so I forked it and tweaked it a bit)
  2. cd waifu-converter-qt && open waifu2x-converter-qt.pro (this should open Qt Creator; if it doesn't, launch it manually and File -> Open Project -> select the .pro file).
  3. Select Build -> Run (or Command + R). The resulting .app bundle should now be in a folder called build-waifu2x-converter-qt-<something something>, just beside your main project folder.
When you first launch the GUI, you should probably go to Preferences and set the path to your waifu2x-converter-cpp executable.

Windows "vintage" default desktop colours

Note to self: these are the default desktop background colours for old Windows versions.
  •    008080 (RGB 000-128-128) - Windows 95/98
  •    3A6EA5 (RGB 058-110-165) - Windows 2000
(I know you love them, even if setting a wallpaper was the first thing you did after logging on a new PC. It's called nostalgia.)

18 May 2017

How to get Ctrl-arrow shortcuts working in RDP sessions on macOS / OSX

It looks like recent versions of the official Microsoft Remote Desktop client are a bit shy when it comes to sending CTRL to the remote Windows session. I discovered this because I use Ctrl-Arrow very often to move from word to word, and it just stopped working in RDP.

The solution is to make sure you don't have any overlapping OSX shortcut - typically, CTRL is used for Mission Control actions. Just disable them from System Preferences -> Keyboard -> Shortcuts -> Mission Control and you should be good to go. Any recent Apple keyboard will have real keys dedicated to those actions anyway.

(Come on Microsoft, show some guts - have an option to bypass Mac shortcuts entirely!)

03 May 2017

Ambushwhack, a Warhammer Quest helper

Last week someone on Hacker News linked a site dedicated to HeroQuest. This quickly resulted in me buying Warhammer Quest: Shadows over Hammerhal to play with my kids. I've not dabbled in fantasy miniatures for 20 years, but Hammerhal looked like a self-contained dungeon crawler in the same style as HQ, and indeed that's what it is: a gamemaster arranges a dungeon for a party of 2-5 adventurers, who then proceed to clear 8 levels full of bad guys.

The box includes 31 miniatures; one will need some decent glue, a sharp boxcutter, and a few hours to assemble them... but it's worth it. The kids loved it so much, we're now playing it every day before bedtime - it's a great incentive to get them to do homework, clean up their rooms, and brush their teeth quickly and without fuss.

The game requiring a gamemaster is good in the sense that I can tweak the game and keep the fun flowing. My son is 5 and doesn't really enjoy complex rules, so we started with a simplified set: one move+attack turn for each character, all characters moving 6 spaces, no hero dice or destiny dice, rolling only to hit, and rolling for unexpected events only when they enter a room. I used the Gryph-hound character as an NPC to show them these mechanics, and I'm slowly replacing introducing a few real rules every couple of sessions. So it's all great, right? Well, kinda.

Being a classic dungeon master inevitably involves some dice-rolling. Hammerhal is not too bad in that regard, leaving most of the rolling to adventurers, but one notable exception is ambushes. *Every* turn an adversary is not on the board, the gamemaster is supposed to roll for ambush; if the ambush happens (1 in 6 chances), he has to then roll further for character quantity and behaviour, which means between 2 and 7 throws depending on level and results. That can significantly slow down proceedings, and I found myself "forgetting" to roll quite a few times to keep things going.

So I did what any geek would do: I automated it away. The result was Ambushwhack, a simple and mostly self-contained webpage that does all the rolling for you. I made buttons big enough to be usable on phones and tablets, added a few pics of my unpainted miniatures (since Games Workshop are infamous for aggressively defending their IP, they would likely come after me if I used their own pics), and now I use it every day.

I posted it to a few Warhammer Quest forums (boardgamegeek etc) and people asked to support Silver Tower, the other version of Warhammer Quest currently available, which has a similar (but different) set of ambush rules. A kind soul sent me most of the necessary details, so here it is. It lacks pictures and action titles but it's usable, at least until I can justify splurging on another big box of toys :)

I hope someone else will find it useful and maybe volunteer to redesign it a bit - my CSS skills are almost as bad as my miniature-painting ones. Because I'm lazy, I've only tested it on Firefox and Safari, but my javascript style is so '90s (no jQuery!) that it should work flawlessly everywhere these days. Each page is entirely self-contained (except for pics) so it can be used offline, and I slapped in an iOS icon so you can add it to your home screen. I will probably put it on github when I get some time. Have fun!

25 April 2017

how to force-refresh macOS text auto-expansions without turning off iCloud

One of the little niceties OSX has had for a while is the automatic synchronization of text-expansion shortcuts across all iCloud-enabled Apple devices (i.e. what you find in System Preferences -> Keyboard -> Text on Mac, and General -> Keyboard -> Text Replacement on iOS). Unfortunately Apple tries a bit too hard to make it look "magic", which means that there is nothing one can do when the magic somehow refuses to work.

In my case, I ended up in a situation where the mac had lost all shortcuts. Various people on the internet recommend turning iCloud Drive on and off to get them back, but that's a very disruptive step I didn't want to take.

Luckily, this worked for me:

  1. Open a command terminal
  2. rm -rf ~/Library/Mobile\ Documents/com~apple~TextInput
  3. Log off
  4. make a change to the list of expansions on some other device (e.g. iPhone)
  5. log back on
This seems to have forced a refresh, and got all my shortcuts back.

It would be nice if Apple provided some command-line tool to perform this sort of explicit management for iCloud elements. As the saying goes, cache invalidation is one of the hardest problems in Computer Science; in order to do the right thing, any system needs all the help it can get. I should be able to say "just blow all my settings for this feature and refresh from iCloud" or "these are the good settings, overwrite whatever is in iCloud for this feature". Magic is nice, but as the citizens of Troy found out so many years ago, it's better to have backup plans for when the gods are against you.

12 March 2017

A new Freestyle ...?

A bit of serendipity. Yesterday I noticed that hey, I barely charge my Bluetooth Kinesis Freestyle2 (which I reviewed here) once or twice per year. I duly tweeted about it, and the folks at Kinesis replied saying 4 to 6 months on a single charge is expected, which is awesome.

Then I went to their twitter page to follow their account, and there I discovered that they now have a kickstarter for a new Freestyle model, supposedly built for gamers. This looks awesome, in the sense that it addresses my few issues with the old model: the ability to program and remap keys, real mechanical switches, and backlighting.

It looks like the "first edition" pledges are US-only, but the simple preorders shipping in September are worldwide, so - go support the campaign! I did :)