Bill Farmer

Random thoughts on random subjects

Lambda Expressions

by Bill Farmer. Categories: Hacking .

Lambda expressions or anonymous functions can be quite useful. For example using jQuery in JavaScript all the work gets done in anonymous functions unless you particularly want to extract them and give them names… jQuery(document).ready(function($) { // ... // Process the start button $("#start").click(function() { question = 0; $("#data").css("display", "none"); $(".intro").fadeOut(function() { // Do stuff }); // ... }); }); In C++ the syntax is curious in that there are a pair of square brackets enclosing ‘captured’ variables…

Read more →

Hiding Edit Button

by Bill Farmer. Categories: Hacking .

My Diary and Notes apps have a floating button in the corner of the screen which is used to switch between editing markdown text and viewing the result. Although it is part of the android Material Design, this button has been the subject of several issues raised by users. I have seen apps which hide this button on scrolling, and this was one of the suggestions by users. Getting this to work correctly turned out to be more complex than initially considered, requiring two boolean flags and a lambda expression.

Read more →

Derive Edit Position from Markdown

by Bill Farmer. Categories: Hacking .

I had a request to switch to the edit view from the markdown view at the double tap position in my Diary app. The app already has a gesture detector so I just had to add an onDoubleTap function. To get the tap position in the markdown view it is necessary to compensate for the position of the view on the screen, scrolling, and the display density. // onDoubleTap @Override public boolean onDoubleTap(MotionEvent e) { if (shown) { int[] l = new int[2]; markdownView.

Read more →

Pi-hole Cloudflare, DNSCrypt, Unbound Setup

by Bill Farmer. Categories: Hacking .

Pi-hole I came across a reference to Pi-hole recently, so as my old pi has been gathering dust, I thought I would try it out. The pi already had Raspbian Stretch Lite installed, so I uninstalled some of the packages I had previously installed, and loaded Pi-Hole using the One-Step Automated Install. The installation script asks a series of questions using text dialogs and produces a log as it goes.

Read more →

Source Code Syntax Highlighting

by Bill Farmer. Categories: Hacking .

One of the enhancements suggested for my android editor is syntax highlighting. The libraries I have found, including the one used in this blog, parse the input and produce output in HTML, using styled spans. Emacs makes extensive use of regular expressions for highlighting. HTML output is not very useful for a text editor. It could be used with Html.fromHtml() to produce styled text. This would then be loaded back into the editor all while the user is attempting to edit the text.

Read more →
Previous page Next page