Bill Farmer

Random thoughts on random subjects

Using Emacs in Android Development

by Bill Farmer. Categories: Hacking .

I’ve got a folder full of country flags which I have renamed using scripts so the names correspond to currency symbols. I want an integer array with references to the flags as android resources. This can be automated using emacs.

I get a list of the file names into a buffer using find, which I then open with emacs.

  % find src/ -name flag* > data/sym-flags.lst

Flags

They are already sorted, but just to make sure I use M-x sort-lines.

Read more →

Markdown OpenStreetMap Maps

by Bill Farmer. Categories: Hacking .

There does not seem to be a convention for showing maps or co-ordinates in Markdown, but almost anything gets put in square brackets [<anything>].

I had a request from Marco the other day to put OpenStreetMap maps in my Diary app using

  [<lat>,<lng>]

syntax. So I did a bit of a search to see if there was a convention in Markdown for co-ordinates and couldn’t find anything. So we seem to have broken new ground here.

Read more →

Getting Related Content working

by Bill Farmer. Categories: Hacking .

The latest release of Hugo includes Related Content, which I thought would be nice to add to my blog. However the docs, although they show you how to set it up, don’t explain how it works. To find that out, I had to look at the various threads on the Hugo forums.

There are four parts - you need to create a new partial template in layouts/partials/related.html containing something like this:

{{ $related := .Site.RegularPages.Related . | first 5 }}
{{ with $related }}
<hr>
<h3>See Also</h3>
<ul>
  {{ range . }}
  <li><a href="{{ .RelPermalink }}">{{ safeHTML .Title }}</a></li>
  {{ end }}
</ul>
{{ end }}

You need to add a reference to your new partial template in your single page template in layouts/_default/single.html possibly near the end:

Read more →

Adding a calendar event in android

by Bill Farmer. Categories: Hacking .

The android docs for the Calendar Provider are quite useful, but recommend the use of an AsyncQueryHandler for querying or adding events to calendars in an asynchronous thread. However the AsyncQueryHandler docs don’t include much guidance as to how to use it.

To add an entry to an android calendar you first have to find out the calendar id using an asynchronous query on the calendars table.

// QueryHandler
public class QueryHandler extends AsyncQueryHandler
{
    private static final String TAG = "QueryHandler";

    // Projection arrays
    private static final String[] CALENDAR_PROJECTION = new String[]
        {
            Calendars._ID
        };

    // The indices for the projection array above.
    private static final int CALENDAR_ID_INDEX = 0;

    private static final int CALENDAR = 0;
    private static final int EVENT    = 1;
    private static final int REMINDER = 2;

    private static QueryHandler queryHandler;

    // QueryHandler
    public QueryHandler(ContentResolver resolver)
    {
        super(resolver);
    }

    // insertEvent
    public static void insertEvent(Context context, long startTime,
                                   long endTime, String title)
    {
        ContentResolver resolver = context.getContentResolver();

        if (queryHandler == null)
            queryHandler = new QueryHandler(resolver);

        ContentValues values = new ContentValues();
        values.put(Events.DTSTART, startTime);
        values.put(Events.DTEND, endTime);
        values.put(Events.TITLE, title);

        if (BuildConfig.DEBUG)
            Log.d(TAG, "Calendar query start");

        queryHandler.startQuery(CALENDAR, values, Calendars.CONTENT_URI,
                                CALENDAR_PROJECTION, null, null, null);
    }

This method is called from an app activity.

Read more →

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 →
Previous page Next page