Lambda Expressions
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 →Marion’s Banana and Walnut Cake
This cake is delicious, quick and easy to make.The amount of sugar is reduced because the banana has natural sweetness. I have substituted rapeseed oil for cooking margarine as it is a healthier option. Using this method you do not need a food processor.
Ingredients
- 225g (8oz) self raising flour
- 1 level teaspoon baking powder
- 55g (2oz) demerara sugar
- 2 large ripe bananas
- 55g (2oz) walnut pieces
- 55g (2oz) sultanas
- 2 eggs
- 2 tablespoons rapeseed oil
- milk to mix
20cm cake tin (or similar)
Read more →Hiding Edit Button
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
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.getLocationOnScreen(l);
// Get tap position
float y = e.getY() - l[1];
int scrollY = markdownView.getScrollY();
int contentHeight = markdownView.getContentHeight();
float density = getResources().getDisplayMetrics().density;
// Get markdown position
final float p = (y + scrollY) / (contentHeight * density);
The function to get the view location on screen is a bit arcane in that you must provide a two element array for the X and Y co-ordinates. The position as a proportion of the total length of the displayed markdown is calculated from the corrected Y position, the scroll position and the density.
Read more →Fixing Basin Waste Pop Up
There are two things that seem to go wrong with pop up basin waste plugs, either the clicker stops working or the O ring washer fails.
Clicker
The clicker can stay stuck down, refuse to stay down or come apart.
If it sticks down it can possibly be pulled back up with a drain plunger, otherwise you will need to take off the U bend and poke it back up with a long screwdriver. To take it out, unscrew the plug from the top and use a small adjustable spanner to remove the clicker. It will be choked up with sludge and hair, clean it out and put some petroleum jelly or WD40 on it for lubrication. It should then work again.
Read more →