# Moths – Why do they always fly toward artificial light?

## Moths and other flying insects will naturally gravitate toward a source of light.  Sadly, if this source of light is in the form of a flame, rather than a bulb, it usually means certain death to boot.  So why do they do it?

Moths and their behaviour towards light have fascinated me for a long time, so I’ve been reading up on the subject.  However, it has not been an easy topic to resolve, by a long, long way.

### Theory 1 – Transverse Orientation

Transverse Orientation is a popular theory on the internet.  Moths using the light of the moon to navigate is an old theory.  By keeping the lunar glow in the same position, relative to themselves as they fly, moths can keep a pretty straight line.  You have to bear in mind that relative to the moon and it’s movements, moths are insignificant.  As far as the moth is concerned, the moon is a fixed object in the sky.

The Transverse Orientation model goes on to suggest that the problem this causes for moths and other insects, is the new distance to the light sources they are finding.  The moon is a long way away [citation needed], whereas artificial light sources are not [citation: my monitor is only 20″ from my face].

Let’s say that a moth keeps the moon on the left when flying.  Even better, let’s say that a moth is finding a straight path by keeping itself perpendicular to the moon, but then finds an artificial light source.  What will happen?

Here comes the merry go round.

#### A little bit of Newton

As analogies go, this isn’t great, but I’m going to try it like this.  Newton’s first law of motion states [broadly] that an object travelling in a given direction, will continue to do so unless another force acts upon it.  Imagine then a ball on a piece of string being swung around and around above your head.  If the string were to disappear at any given point, the ball would disappear off into the distance.  No longer would it be a ball in a circular motion, it would head off in a straight line.  The reason it doesn’t while the string is attached is that the string is providing a force which is keeping the ball perpendicular to the strings point of origin.  In this particular case, the root point is your head.

I would also like to apologise for the terrible stock photo demonstrating a ball on a string in circular motion.  It’s amazingly hard to find a stock photo of somebody swinging a ball around their head.  If anybody would like to take one and send it in, I will be happy to replace this one.

Well, we have our moth who is trying to fly in a straight line.  The moth sees an artificial light and moves toward it [see theory 3: phototaxis].  Now, to fly in a straight line, the moth has to keep the light 90 degrees to its left.  This flight pattern works until the moth has flown a tiny amount. However, then the light source shifts angle because it’s close, relative to the moth, so more adjustments are needed.  Ok, the moth thinks, I need to bear left slightly to maintain my 90-degree angle to the light.  These adjustments work for another tiny amount of flight, and the same happens again.

We could continue this into the thousands of words, but by now you should see what is happening.  The moth is permanently adjusting its coordination and flight path, which to the moth is a straight line.  However, looking on from outside this frame of reference, we see a moth flying around and around the light in a continuous loop.

You can sometimes see the circular motions getting bigger and smaller as the moth experiments with different patterns to attempt to get this right.  These experimental motions often result in the moth running into the light source.

Running into the light source is OK if its a lightbulb, but not so OK if it’s a candle or fire.  Poor moth.

### Theory 2 – Infrared Sex

The infrared sex theory is a puzzling one.  Personally, given all I have read, I don’t have a great deal of confidence in this theory.

Just as a sidenote, I’m really pleased that everything in the whole world, including biology is explained by some branch of physics.  Chemistry can now be explained at a quantum level, as too can biology.  This demonstrates that physics, is by far the best, most interesting and most relevent branch of science.

There are a handful of studies that suggest that the wavelength of certain lights, especially infrared (as emitted by an open flame), matches certain wavelengths emitted by the female moth’s sex hormones.  This theory is used to provide evidence of why male moths zoom straight over to these lights and jump on them.  I’m unsure about this though, as ultraviolet light is far more attractive to moths than infrared.

If it is true though that the males are trying to pounce onto these light sources because they think they are females, it could be potentially harmless.  That’s if it’s a lightbulb.

If it’s a candle or a fire.  Poor moth.

### Theory 3 – Phototaxis

I like phototaxis as a theory.  Transverse Orientation does a pretty decent job at explaining the circular motion of the moths around light sources.  Sometimes, though, simpler is better.

Imagine that you are a moth.  Then imagine you are happily sitting on a branch in your bush or tree when a bird swoops down and lands.  You, being a moth, are naturally going to want to escape your place of resting as quickly as possible.

The problem; its nighttime and dark (we’re pretending you are also thousands of years into the past and there are no artificial lights).  So what do you do?  You need to make a split second decision about where you are heading.  Hello, Phototaxis.

Phototactic animals fall into two categories.  Positively phototactic and negatively phototactic.

I’m going to try again with an analogy, but have to say, its a little on the tenous side.

If there were such a thing a heat-taxis, then humans would be negatively heat-tactic.  If you put your hand onto something hot, your immediate instinct is to pull your arm away.  There is no conscious decision made here; it’s just something you do.  This is kind of how phototaxis works.  There is no conscious decision made; it’s just something that happened instinctively.  Phototaxis is an instinctive reaction to light.

Cockroaches are a great example of an animal that is negatively phototactic.  While scurrying around, eating the leftover nibbles from your floor in the dark is fun, somebody walking in an turning a light on, is not.  As soon as the light comes on, Cockroaches will instinctively head for the dark, and quickly.  Phototaxis also applies, but to a lesser degree, to earthworms.  This trait is a useful aid to worm farmers who can stop their worms from escaping by shining a bright light on top of the worm beds at night.

Moths are the opposite.  Moths are positively phototactic, meaning that in a dangerous situation, they will instinctively do the opposite to cockroaches and fly toward the light.

Back to our moth in a tree.  You are suddenly startled and need to flee.  If you flee left, right or down, you will likely hit something.  So, the only way to go is up.  But which way is instinctively up?  Well at night, with no other artificial light sources around, up, is towards the moon and stars.  Any other direction is dark.

### Conclusion:

Having looked at multiple articles on this subject, I cannot conclude that any of these theories are correct.  Nobody else can either.

If I had to make a choice, I would conclude that as moths have had millions of years with no artificial light to evolve, it would seem logical they would need the light for escape and navigation.  Moths are nocturnal after all.  So my final answer is, it is a mix of both transverse orientation for one aspect of their lives, and phototaxis for their instinctive survivability.

If anybody can give me some more ideas about moths artificial light fetish, then please get in touch.  You can do this via the contact page.

# Piano Medley To Play At Christmas Time

## If you’re like me and like a piano sing song at Christmas time, then you can’t beat a good, pre-compiled medley to play through.

After seeing this video on YouTube:

Here’s the playlist for the video:

1. It’s Beginning to Look a Lot Like Christmas (0:01)
2. Let it Snow (1:18)
3. Winter Wonderland (2:35)
4. Christmas Tree (3:59)
5. Silent Night (4:55)
6. The First Noel (6:55)
7. Hark! The Herald Angels Sing (8:40)
8. Joy to the World (9:50)

If like me you want to play this medley at Christmas, you can find the sheet music for all tracks as a single bundle, for sale, here.

I found it to be the perfect mix of soft, upbeat and classically “swingy” Christmas arrangments I’ve seen in a while.

Enjoy!

# Pasta / Bolognese with hidden vegetables – perfect for the kids

## We have multiple children and getting them all to eat the same veg at the same time is a bit of a nightmare, so I thought I’d try hiding a whole bunch of veg in some sauce to see if I could get away with it.  I did.

All kids seem to go through the “I’m not eating my vegetables” stage, so it’s not something I worry about, mainly.  However, they do still need to consume as many of the life-boosting plants as possible.  After poking around in the fridge, I found some veg that I thought would cook down well and decided to give this sauce a go.

You can make this with, or without, the meat element.  If you use the meat, you end up a with a tasty bolognese.  However, if you prefer just a light pasta sauce, it will work just as well without.  I’ve written the recipe in such a way as you can do either.

#### Ingredients:

• 500g lean mince (optional, see below)
• 2 carrots
• 1 large onion
• 1 leek
• 2 peppers (red or yellow)
• 2 sticks of celery
• 2 x 400g cans of chopped tomatoes
• 2 cloves of garlic
• 1 tbsp caster sugar
• 1 tbsp balsamic vinegar
• salt & pepper
• 300 – 400g spaghetti or penne pasta (dried)
• A gulp of oil; olive or vegetable

#### Method:

1. Chop the carrots, onion, leek and celery in pieces.  Smallish pieces, although the size doesn’t matter.  Getting everything around the same size is the most important thing here.
2. Heat a glug of oil in a large non-stick pan and start to cook the above.  You are looking to soften these, not brown them, so an extended time over a lower heat is best.  Around 20 minutes.
3. While these are cooking, deseed and chop the peppers and peel/chop the garlic.
4. When the carrot, celery, onion and leek are softening, add the pepper and the garlic and continue to cook for a further 10 minutes.  Again, keeping the heat low so as not to burn the garlic.
5. Add the tomatoes, sugar and balsamic vinegar, stir and bring to a boil.
6. Reduce the heat down again and cook for a further 20 minutes.  The longer, the better here actually.  I put a lid on and cook for around 40-45 minutes.  If you don’t have a cover for your pan, add a little water every now and again if the sauce is looking a bit thick.
7. While this is cooking, cook the pasta, according to the pack guidelines.
8. Once everything is soft and melded together, blitz the mixture with either a hand blender (soup blender), or if you want a super thin hidden veg sauce, pop it in a food processor and blitz on high speed for a few minutes.  It may pay you to let it cool a bit before using the food processor option.
9. While in the blender, or using a separate pan if you want to save time, brown the mince.  Get it nice and hot, and beautiful brown as this caramelisation adds a mass of flavour.
10. Once you have some browned mince, a sauce and some cooked pasta, combine all in a pot and serve.

This dish is lovely with some grated parmesan on top.

I’m not a chef so the instructions may be a little awkward.  It may pay you to read through the method first and get everything done into your order.

# PHP – Validate a UK postcode

## Returns a true/false against a UK postcode, as well as attempting to format it correctly.

There are a million versions of this code on the internet, but being true to my FluffedVision roots and treating this as my notebook, rather than a traditional blog, I’m noting this snippet down here.

```function isValidPostcode(\$originalPostcode)
{
\$alpha1 = "[abcdefghijklmnoprstuwyz]";
\$alpha2 = "[abcdefghklmnopqrstuvwxy]";
\$alpha3 = "[abcdefghjkpmnrstuvwxy]";
\$alpha4 = "[abehmnprvwxy]";
\$alpha5 = "[abdefghjlnpqrstuwxyz]";

\$pcexp[0] = '/^('.\$alpha1.'{1}'.\$alpha2.'{0,1}[0-9]{1,2})([[:space:]]{0,})([0-9]{1}'.\$alpha5.'{2})\$/';
\$pcexp[1] = '/^('.\$alpha1.'{1}[0-9]{1}'.\$alpha3.'{1})([[:space:]]{0,})([0-9]{1}'.\$alpha5.'{2})\$/';
\$pcexp[2] = '/^('.\$alpha1.'{1}'.\$alpha2.'{1}[0-9]{1}'.\$alpha4.')([[:space:]]{0,})([0-9]{1}'.\$alpha5.'{2})\$/';
\$pcexp[3] = '/^(gir)([[:space:]]{0,})(0aa)\$/';
\$pcexp[4] = '/^(bfpo)([[:space:]]{0,})([0-9]{1,4})\$/';
\$pcexp[5] = '/^(bfpo)([[:space:]]{0,})(c/o([[:space:]]{0,})[0-9]{1,3})\$/';
\$pcexp[6] = '/^([a-z]{4})([[:space:]]{0,})(1zz)\$/';
\$pcexp[7] = '/^ai-2640\$/';
\$postcode = strtolower(\$originalPostcode);

\$valid = FALSE;

foreach (\$pcexp as \$regexp)
{
if (preg_match(\$regexp, \$postcode, \$matches))
{
\$postcode = strtoupper (\$matches[1] . ' ' . \$matches [3]);
\$postcode = preg_replace ('/C/O([[:space:]]{0,})/', 'c/o ', \$postcode);
preg_match(\$pcexp[7], strtolower(\$originalPostcode), \$matches) AND \$postcode = 'AI-2640';
\$valid = TRUE;
break;
}
}

return \$valid ? \$postcode : FALSE;
}```

Usage:

```if(isValidPostcode("thePostcodeToCheck"))
{
// postcode is valid
}
else
{
// postcode is not valid
}```

# How to make Yorkshire puddings

## How to make great Yorkshire puddings and get them right every time.

Yorkshire puddings are a simple baked batter mix with a soft and fluffy inside and a lovely crispy outer.

There are a vast number of recipes online with suggestions for how to make Yorkshire pudding.  Some of the recipes are simple; some are way too complicated.  Over the years I’ve been cooking and having tried dozens of recipe tweaks, it is now clear that the perfect pudding comes from the baking, more than the mixture.

We should get a little bit of terminology cleared up here as well.  The individual little puds that you see in the picture are popovers.  Yorkshire pudding – if you’re getting funny over the wording – is the result of cooking the same batter, but in one large pan.

Either way, Yorkshire pud is yummy with a beef dinner, so let’s crack on.

### Ingredients:

• 140g plain flour
• 200ml milk
• 4 eggs (medium-largish)
• Oil
• Salt & Pepper

### Method:

1. Take a 12 hole muffin tin and add a drop of oil into each hole.
2. Put your tin into the cold oven and turn it on, then heat your oven to 210C (fan) / 220C (regular) / Gas 8.  I find this a good way of making sure the pan and oil are super hot when you come to pour the batter mix into it.  A cold tin ensures a soggy pudding.  The oil should be just smoking when you get the tin out to add the batter.
3. While the oven and tin are heating, add your eggs to the flour and beat until it forms a thick paste.  I find an electric beater always excels for this.
4. Slowly add the milk to the egg/flour mix, still beating as you do.  You’re looking for a lump-free, beautifully smooth liquid that is similar to the consistency of the sauce you find in Heinze baked beans (which is probably a crap analogy, but it’s all I can think of).
5. Season the batter with salt & pepper.
6. When the oven is up to temperature, take the tin out and pour enough liquid in to fill each of the holes.  Do this quickly and evenly (don’t worry about spilling a bit).  You are aiming to have to tin out of the oven for as little time a humanly possible.
7. Bake in the oven for 20-25 minutes, or until golden brown all over.  You will see them rise up and then change colour as they cook.
8. Remove and eat immediately.

#### A few notes and tips for perfect Yorkshire puddings:

• Keep the pan as hot as you possibly can at every stage of the cooking.
• Ensure your batter is lump free.
• DO NOT OPEN THE OVEN DOOR at any point of the cooking.  The puddings rely on having a hard outer shell to keep them in shape.  If you open the oven door before this outer shell has formed, you will see them deflate in front of your eyes to a sorry looking squidge.  The Yorkshire puddings will NEVER recover from this.
• You can make these Yorkshire puddings ahead of the meal, to free the oven up for the other things.  As soon as you take them out of the oven, place them on a wire rack to let them cool down, which stops them sweating in the pan and going soft on the bottom.  They’ll stay crunchy on the wire rack for a couple of hours.  If you need to leave them longer than that before eating, put them in a sealed tub to avoid going soft.  You can pop the Yorkshire puddings back in the oven for a few minutes to warm them up while plating up the rest of the dinner.
• Once the Yorkshire puddings have cooled, you can freeze for up to 2-3 months.

I keep forgetting to mention this: If you need to have a look at a conversion chart, there are some common conversions here.

# Create a character countdown for text inputs and textarea’s using jQuery

I think it may have been Twitter that first pioneered the use of the text character countdown years ago.  I could be wrong, maybe they just popularised it, but either way, it is a convenient way of keeping user inputs to a length that is acceptable to your site.

I’m not sure that this is the place to mention it, but I do still find myself writing shorter tweets, despite the limit raise a while ago.

There are going to be three main parts to this:

• Create an HTML form that needs the input characters kept in check.
• Write some jQuery code to keep an eye on what is happening when the user’s types.
• Style a little blank <span> underneath the input to show the user how they are getting on.

For those of you that read regularly, you will know I am a big Bootstrap fan (hark the Twitter reference again), so the form has some Bootstrap elements to it.  This form will work just as well without the BS references.

### Create the input:

```<label for="myInput"><strong>My Limited Input:</strong></label>
<input class="form-control" type="text" id="myInput" maxlength="50">
<span id="showCountdown" class=limits"></span>```

I’ve used the HTML “maxlength” in the above snippet so that the browser automatically restricts any more inputs at that point.  The HTML “maxlength” has nothing to do with the character countdown.  “maxlength” is universally accepted on most browsers except for the ancient, so you shouldn’t run into many [if any] compatibility problems.

Just for curiosities sake, the default value for maxlength is 524288.

Next, we need to add some jQuery to do the counting and append the <span> underneath the input:

```\$('#myInput').on("keyup change", function ()) {

const max = 50;
const len = \$(this).val().length;

if (len >= max) {
\$('#showCountdown').text("No more room ...");
} else {

const char = max - len;
\$('#showCountdown').text(char + ' characters remaining');
}
});```

So what’s happening here?

The browser is looking for either a keyup event or a change event occurring in the input.  Change is handy because, in the majority of cases, the will also catch the user if they try and paste something into the box.  When the event is detected, it counts the length of the string inside the input.  It then compares it to the max variable we’ve included and deducts one from the other.

After evaluating whether the length of the input is smaller (by x number) or equal to the max value, it adds an appropriate message into the empty span underneath the box.

### Now a little styling:

```<style>
#showCountdown {
font-size: 12px;
color: #3399ff
}
</style>```

You can style this in any way you wish.

Below is an example of this text input in action on a site I’m working on at the moment,  Although I think I used dodgerblue as the colour:

# How to show your latest blog posts on a non-WordPress page

Quite often on a website, there is a need to show your WordPress blog posts outside of the WordPress installation.  You may already have an HTML / PHP site, and you have decided to add a blog page, but want to show some of the posts on the front page (for example).  Luckily, WordPress makes this process as easy as adding a few lines of code to your pages.

You will need a little bit of familiarity with PHP, but realistically, anybody should be able to do it.

There are two things to do:

First, you need to tell your non-Wordpress page that you are going to be extracting information about your posts. So, at the top of the page add the following:

```<?php
define('WP_USE_THEMES', false);
query_posts('showposts=4');
?>```

Let’s break this down a bit.

The first line tells WordPress that it won’t be needing to use any of its themes.  We are adding the posts to a page that we will assume is already using a stylesheet of its own, so we need the extracted WordPress information to blend in accordingly.

```// If it's in a directory called "wordpress"

// If you need to backtrack to server root to get to you sub-folder

The exact structure of this line is individual web server and code dependent so will need to be adjusted to suit your exact requirements.

The second line is pretty self-explanatory, it is telling the page to use the WordPress loader.  The loader is required whenever you call anything from WordPress, be it posts, pages, categories etc.

The third line is what we want to extract from the WordPress database.  In this case, we are pulling the lastest four posts.

Following this, we will need to display the posts on the page.  We do this using the standard WordPress API in the form of WordPress hooks.

So:

```<?php while (have_posts()): the_post(); ?>

<h4><?php the_title(); ?></h4>

<?php the_excerpt(); ?>

<?php endwhile; ?>```

That’s it!

The first and last lines tell the page to show posts if there are posts available.  From there, it is just a list of standard WordPress hooks, which on the whole of quite explanatory.  While we are looping through four posts, for each of them, show the post’s title, the excerpt from the post – which can be adjusted in the WordPress admin panel – then add a link to read more.  This link will take the user to the main blog page.

Want to show the full post and not an excerpt from it? No problem.  Just replace “the_excerpt” with “the_content”.

Want to add the posts featured image as well?  No problem, include:

```<?php
if ( has_post_thumbnail() ) {
the_post_thumbnail();
}
?>```

Here are some working examples:

An example snippet that would show the title of the post, along with the featured image and an extract of the content:

```<?php while (have_posts()): the_post(); ?>
<h4><?php the_title(); ?></h4>
<p>
<?php
if ( has_post_thumbnail() ) {
the_post_thumbnail();
}
?>
</p>
<?php the_excerpt(); ?>
<?php endwhile; ?>```

An example snippet that will show the title, full post, but no image:

```<?php while (have_posts()): the_post(); ?>
<h4><?php the_title(); ?></h4>
<?php the_content(); ?>
<?php endwhile; ?>```

If anybody would like to add some more code examples to the comments, I’ll be glad to see them and we’ll get them added to the main post to build up a little library of useful snippets.

# The best blackberry crumble recipe on the internet

Now that is a ridiculously bold claim in the title, but I do believe after amalgamating several recipes for this classic English dessert, I’ve finally nailed one that I will use over and over.

Hope you enjoy it if you venture to make it.

Ingredients:

• 200g plain flour
• 100g butter
• 50g caster sugar
• 50g porridge oats
• A punnet of blackberries (fresh or frozen)
• Four apples (green are best)
• Lots and lots more sugar for layering

Method:

1. Preheat your oven to 180C (160C fan), or gas mark 4 (I think).
2. Grab a dish.  Anything.  Pie dish, casserole dish, or anything around 1.5-2 inches
3. Prep the crumble.  Weigh your flour into a mixing bowl and rub in the butter until breadcrumb like flakes emerge.  This doesn’t need to be perfect, as some lumpier bits will add to the textures at the end.
4. Add the sugar and the oats.  Again, rub this together to achieve a breadcrumb consistency.
6. Using a knife slice around the edge of the apples, the get some thin slices,  stopping at the core.
7. Rub some butter around the dish, to stop the fruit sticking to the sides and bottom.
8. Add one thin layer of apple to the bottom of the dish.
9. Sprinkle with some sugar.
10. Add a layer of blackberries.
11. Sprinkle with sugar
12. Keep going with steps 8 to 11, until you have used all of your fruit.  Neatness is NOT the key here,  as this is a homely crumble, not a work of art.
13. Spread your crumbly crumble mix onto the top of the fruit.
14. Add another layer of sugar.
15. Cook in the oven for 35-40 minutes if you’ve used fresh blackberries, or 45-50 minutes if you’ve used frozen.  Make sure the top doesn’t burn.
16. Leave for 10-15 minutes before serving to ensure all the juices in the fruits thicken up.

A little note about the apples.  People do say that peeling and coring the apples is a necessity.  I disagree with anybody that gives this advice.  Unless you are producing a dessert where the apples will be on display, this is uncessary.  Just peel the apples using a standard veg peeler and then run the sides up and down the slicer edge of your standard kitchen grater.  Or, you can use a knife.  Or, if you’re posh and have one to hand, you can use a Mandolin.  Any of these will do the job just fine.