Skip to main content

Snippets

Short solutions to problems I've had

The cover of "Detox and React Native: UI testing Android permission flows"

Detox and React Native: UI testing Android permission flows

I’m currently learning React Native and Expo as an alternative to native app development. To do this, I’ve been working on an app so that I can get hands-on experience with React Native app development. This includes end-to-end UI testing, using Detox.

I was surprised that Detox doesn’t have an API to interact with permissions. The device.launchApp function does have a permissions field, but this only works on iOS and runs on app start-up - it doesn’t allow you to test the actual user flow.

In this article, I will explain how you can do end-to-end testing with Android permissions, including simulating user interaction with the Android permission request modal.

Read more of "Detox and React Native: UI testing Android permission flows"

Better word counts and reading time in Eleventy (11ty)

I recently switched to using Eleventy to generate my blog. As part of this process, I needed to implement word counts for each of my posts. I made my own plugin for this as I was unable to find an existing one that met my requirements - they either used regex to parse HTML or included non-text like scripts and code snippets in the count.

Read more of "Better word counts and reading time in Eleventy (11ty)"

Android: Complete, generic data-binding RecyclerView adapter

Data binding greatly reduces the amount of code you need to connect user-interfaces with ViewModels. It keeps Activity and Fragment code small, and makes it easier to manage lifecycles.

<EditText
    android:id="@+id/username"
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:text="@={viewModel.username}"/>

I discovered that there was no attribute to bind the elements in a RecyclerView, due to the fact that a RecyclerView needs an adapter to be able to create element views. It would also be nice to automatically use data binding to create the viewholders. There are a number of guides to do both of these halves, but I now present the code to do the whole.

Read more of "Android: Complete, generic data-binding RecyclerView adapter"

Mingw-w64 and CMake: unrecognised option -rdynamic on Ubuntu

I had an issue where CMake was failing on a compiler test with the following error:

error: unrecognized option '-rdynamic'

The problem was that CMake caches settings such as compiler flags in CMakeCache.txt, so you need to clear the cache when changing the platform. Do this by deleting CMakeFiles and CMakeCache.txt

Read more of "Mingw-w64 and CMake: unrecognised option -rdynamic on Ubuntu"

How to emit a single particle using SFML's Thor Particle System

Usecase: shells dropping in sync with firing, fake bullets, etc

You must use a particle emitter to create particles, however this doesn’t mean it’s impossible to create single particles on command. You can create a particle emitter which simply adds particles from a queue to the system

Read more of "How to emit a single particle using SFML's Thor Particle System"

Move private repos from Bitbucket to GitHub

Now that Github supports unlimited private repos in all plans, you might as well keep things all together (although definitely have backups elsewhere incase Github is DDOS’d again, dies or goes evil). Simply change “rubenwardy” to your username and “XXXX” to a personal access token with “repo” checked. Also make sure you have an SSH key for Github.

Read more of "Move private repos from Bitbucket to GitHub"

Getting user profile data from external phpBB forums

I recently wrote and released a python module to allow fetching of profile data.

You can install it using pip:

pip install beautifulsoup4 phpbb-parser

Here’s how you import and use a profile:

import phpbb_parser as parser

username = "rubenwardy"
profile = parser.get_profile("https://forum.minetest.net", username)

if profile:
    signature = profile.signature.text
    location = profile.get("location") or "unknown"
    github = profile.get("github") or "none"

    print(username + " from " + location + " has github " + github)
    print("Signatue: " + signature.text)
else:
    print("Could not get profile!")

profile.signature is a beautifulsoup4 object.

Next: Linking a user account to an external phpBB forum.

Read more of "Getting user profile data from external phpBB forums"

Convert folder of images to PDF with filenames

Here is a shell script specific for GNU/Linux based operating systems to use. On different operating systems the convert commands will be the same, but the for loop will be different due to a different batch file syntax.

rm /tmp/imageex -r
mkdir /tmp/imageex
for filename in *.png; do
    echo "Processing $filename"
    convert $filename -background White \
        label:$filename -gravity Center \
         -append -pointsize 14 \
        /tmp/imageex/$filename.png
done
echo "Exporting to PDF..."
convert /tmp/imageex/*.png output.pdf
echo "Done."

Read more of "Convert folder of images to PDF with filenames"