Bill Farmer

Random thoughts on random subjects

Whatever-o-meter revisited

by Bill Farmer. Categories: Hacking .

I wrote the whatever-o-meter about five years ago in PHP and Javascript as a Wordpress plugin. As I have migrated my blog to Hugo, I thought to have a go at reimplementing it. The exporter I used made a good job of translating the Wordpress custom fields to Hugo front matter parameters. I had to put dashes in quotes, otherwise they get interpreted as [<nil>].

intro: Please answer the following questions carefully and truthfully.
question:
  - You are lying in bed on Monday morning...
result:
  - '%d percent, Perhaps you should consider emigration.'
  - '%d%, Consider taking a long holiday somewhere far away.'
left:
  - Go and jump in the shower quick
right:
  - Jump on him
weights: 2,1,1,1,1
centre:
  - '-'
  - '-'
  - So so
more: https://billthefarmer.github.io/blog/morris-o-meter

The javascript part should just work as it is, the PHP plugin needed re-implementing as a hugo shortcode. The first part of the plugin just outputs svg code to draw the dial and pointer, that was fairly easy to implement, it just has some iteration in it. I had to change the ticks slightly as Hugo doesn’t appear to support floating point arithmetic in templates.

Read more →

Migrating this blog from Wordpress

by Bill Farmer. Categories: Hacking .

I have got fed up with Wordpress. It required constant updates, which doesn’t work automatically on Sourceforge developer web, and it’s slow, especially in admin mode. I came across a reference to Hugo while following up on something unrelated, so I decided to investigate.

I looked for migration tools, and found two:

I found a blog post from Justin Dunham documenting migrating his blog. He tried the WordPress to Hugo Exporter first, but couldn’t get it to work, so he used Exitwp. I tried this, which just worked, but I didn’t like the look of tidying up all the blog entries to work with Hugo.

Read more →

Resolving content uris in android

by Bill Farmer. Categories: Hacking .

If you write an android app that handles images or any other sort of file your app may be required to deal with ‘content’ uris (content://). There is a very useful utility which resolves these into ‘file’ uris (file:///) FileUtils.java. This contains one external reference to LocalStorageProvider, which can be resolved by removing the function isLocalStorageDocument() and references to it.

    // import com.ianhanniballake.localstorage.LocalStorageProvider;
    // ...
        /**
         * @param uri The Uri to check.
         * @return Whether the Uri authority is {@link LocalStorageProvider}.
         * @author paulburke
         */
        public static boolean isLocalStorageDocument(Uri uri) {
            return LocalStorageProvider.AUTHORITY.equals(uri.getAuthority());
        }

Having done that, you can then resolve ‘content’ uris

Read more →

Handling run time changes in Android

by Bill Farmer. Categories: Hacking .

Two articles, Handling Configuration Changes and Handling Configuration Changes with Fragments recommend the use of fragments to retain data and background tasks in Android during the life of an app. There are two problems with this:

  • An android fragment is quite a complex heavyweight object to use just for retaining data and possibly a background task, and the fragment management is not simple.
  • Fragments are not retained if the associated activity is discarded by calling finish().

A simpler and less complex solution is to use a static singleton, mentioned here in a different context: Setting Up a RequestQueue. This is quite simple to implement, like this:

Read more →

Using Emacs as an IDE

by Bill Farmer. Categories: Hacking .

I had to learn Emacs on Unix many years ago as it was at that time the only development environment for Smallworld Magik. Having learnt it, I have stuck with it as it provides a consistent platform for editing source code and building applications in as many computer languages and platforms as I have used and many more I haven’t. It is the only source code editor I have used that always gets the indentation and syntax highlighting right.

Read more →
Previous page Next page