August 22nd, 2011

4 comments

geek, how to, web

Maintenance page with .htaccess

Photo of a diversion signIn keeping with my post about hiding simple changes to a site in php, I thought I would share my method for hiding bigger changes using .htaccess.

My other method is great if you are just changing one file, but tonight I am upgrading the MediaWiki installation over at MedRevise, so I want to hide the whole site until I’m done.

I didn’t just want a blank space, so I sent my visitors to the MedRevise blog, where I put a “Sorry, I’m updating!” message, whilst keeping it so that I could still access the site myself.

How did I manage this magic? I simply changed .htaccess file to the following:

RewriteEngine On
RewriteCond %{REMOTE_ADDR} !^123\.123\.123\.123$
RewriteRule 302 [^/]*$ /blog/

I’ll take you through it:

  1. First off, RewriteEngine On turns on the Rewriting system in Apache.
  2. Then RewriteCond %{REMOTE_ADDR} !^123\.123\.123\.123$ tells Apache “For all ip addresses except 123.123.123.123, do the next line“.
  3. Finally  RewriteRule 302 [^/]*$ /blog/ sets up a temporary rewrite of any files from root to the blog directory. The 302 redirect tells search engines that this is just a temporary redirect.

Perfection.

Image by Ian Britton. Thanks!

Simple testing on a live site

Ever wanted to make changes to a live site without disrupting it for visitors? Use isset() as a cloak of mystery…

As ever, I’ve been making some changes to my site WhenWillIBeSober.com (roadmap here), and I’ve been wanting to fiddle with things without disrupting the live site.

Normally you have two options on testing:

  1. Set up a duplicate install, make changes on that, then ship them over.
  2. Don’t do that, and hope that no one uses the site in moment when its broken.

Option 1 can be a lot of hassle, and Option 2 can cause your users a lot of hassle, so I implemented a very simple method: Option 3…

Simple add an isset($_GET["test"]) statement to your code, and put all your changes inside it. This way, people visiting the page won’t see your changes, but you can check them out by adding ?test=1 onto the url.

So, the code I’ve used today is:

<?php if (isset($_GET["test"])) {
include 'php/graphs.php';
}
else { ?>
<h3>Watch this space!</strong>.</h3>
<p>Coming soon is an exciting graphs area...</p>
<?php } ?>

And my site changes are only visible to anyone who visits the url with the test variables – as you can see in the screenshot below. Happy testing people!

Image by Richard Anthony Morris. Thanks!

Coming in First: 5 minutes on effective SEO

I was asked to talk about search engine optimisation at this month’s SYWP. It went down fairly well, so I’ve included the talk below:

Healthy Onion Bhaji recipe

I like eating Indian food. I especially enjoy crispy onion bhajis, ideally covered in mango chutney. Last night, we were eating curry, and I decided to work out a bhaji recipe.

Three delicious looking onion bhajisI had a look online, had a chat with my mum (an awesome cook), and muddled something together, that tasted pretty awesome. Try it out for yourself below (and try my Sweet Potato and Parsnip soup too…)

I warn you, I am a non technical cook. I firmly believe a happy cook just throws stuff in a pan, rather than measuring 18g of this and 3.5 medium egg yolks of that. I suspect that if you ignore everything I’ve written below except the bits in bold, it’ll still work.

Enjoy!

Ingredients

  • 4 medium onions
  • Spices: turmeric, coriander, cumin, ginger
  • Flour
  • Water
  • Garlic paste
  • Tomato puree

Recipe

  1. Chop the onions into mediumish slices. Don’t dice them, have loads of nice long strips. Throw them in a pan with plenty of oil, and fry them until they are stinging your eyes something rotten.
  2. Chuck in loads of the spices above. Add a dash of chilli powder too. Keep stirring until it smells good enough to eat.
  3. While that’s cooking, get a big baking dish, put a good splash of oil in it, and pop it in the oven at roughly 180°C.
  4. Take a biggish mixing bowl, and pour in some flour. I used about 1/4 of a bag (250g), but whatever looks right to you, you can always add more. ‘Proper’ recipes use buckwheat flour. Good luck finding that in your local supermarket, and normal flour tasted fine.
  5. Add more spices to the flour, especially the turmeric.
  6. Pour the spiced onions into the flour bowl. Mix them with a big wooden spoon, until all the onion is coated in flour.
  7. Squirt a nice amount of garlic and tomatoe into a small glass, top it up with water, and give it a good stir. Mix it all together until you have a gooey paste. I used about 1/2 a glass of water (150ml) total.
  8. Spoon out lumps onto the baking tray, and cook until brown.

Well brewed

Many, many years ago, I had my first true encounter with the refreshing, hydrating glory of the “cuppa”. I won’t pretend to remember exactly when it was, although I suspect it was in my early teens, and I may have been spending too much time with my friend (and intrepid international explorer) Jon.

It happened something like this:
Jon: Fancy a cup of tea?
Me: Actually, yes I do.
[5 minutes pass, then, after taking the first sip]
Me: Ahh… That’s better!

And, indeed, better it was. The beverage that won us an empire – surely no cigarette to a dying man ever achieved so much, no heroin addict ever gained so much release from a hit as I do every single time from the day’s first cup of hot stewed leaves.

Following on since that brewful day, there have been so many moments of timeless memory, stapled into my grey matter with the cold steel of an “Ahh…”

The result of this is that when coffee was first mentioned to me, I responded like a 16th century Anti-Reformationist when asked “fancy some moveable type?”. In that I was rather unimpressed, stopping however, just slightly short of strangling and burning the coffee offerer (or cofferer).

And I felt my reaction was right; because how could it ever replace tea?! What I now realise (obvious as it sounds, and stupid as it makes me look) is that it doesn’t have to.

Coffee (and indeed, hot chocolate, bovril and battery acid) are just other options. And if, as I believe, tea is the king, then surely it needs some contemporaries to reign over. So to any one I’ve ever ranted about coffee (or battery acid) too – I apologise. Not only is coffee not evil, it can actually be quite nice too. (Although you won’t ever persuade me that a £17 coffee in Starbucks even comes close to the humble power of a 50p cup of well brewed tea in a builder’s cafe).

Below are some shots of me brewing and drinking some tasty coffee with the help of a traditional stovetop expresso maker – also known as a macchinetta (meaning “small machine“), or a moka express.

Using a Macchinetta

(Click on pictures for hi res versions)



Step 1 – Get a stovetop coffee maker, clean it, buy some coffee, and find yourself a kitchen. Step 2 – Top up the bottom chamber with water, then fill the basket with coffee. The more you put in, the stronger the resulting brew.
Step 3 – Screw it together, and chuck it on the hob until the top chamber is full. Keep the lid on, or it sprays everywhere! Step 4 – Pour into a mug, add milk, and (lots) of sugar, then drink. This photo was taken just as I realised the milk was off.

Might have taken me a while to get round to writing this post, but I got there in the end. In my defence, I actually wrote this on the flight home, it’s just taken me 4 days to getting round to downloading photos.

x Chris

April 15th, 2010

Leave a comment

geek, how to, links, web

Batch resizing images tutorial

There are times when you will have a huge pile of images, each 2 or 3 mb, and you need to upload them to a website. They don’t need to be that size for most things – Facebook resizes images to , meaning your time uploading them is wasted, (as is your internet, if you pay for amount of useage).

The solution is to “batch process” them, meaning resize a whole load of them at once.

I use a program called, MyImageResizer, which you can download from its website, or just directly by clicking here. The program is dead easy to use. Simply follow these instructions:

  1. Open MyImageResizer.
  2. Go to “Open”, and select all the images you want to resize. Do this by going to the folder you want in the “Open” dialog, then press Ctrl+A on the keyboard, then click “Open”.
  3. In “Target size”, type in a number, next to “maximum”. This is the maximum number of pixels you want each image to be in any direction. For facebook, for example, you would put “720″, as this is currently the maximum.
  4. Now press “convert”.
  5. Now in your folder you will have smaller versions of every single photo, renamed as image_originalphotoname.

Win? I think so!

For an example, the three images below are my photo A daffodil, resized to 500px, 300px and 100px.

January 10th, 2010

4 comments

how to

Spicy Sweet Potato and Parsnip Soup

I decided to do a little Delia, and give you a recipe for an extremely tasty soup. I warn you I’m not big on exact quantities, I’m from the “chuck it in and stir” school.

This will make one big batch that will serve about 8 people, or more.

Ingredients:

  • Parsnips – I used 3 big ones.
  • Sweet Potatoes – I used 2 big ones.
  • Some carrots, or potatoes, to add a bit of body, not affect the flavour and still be cheap – I used 5 carrots.
  • Onions – I used 2 big ones.
  • Vegetable stock cubes.
  • Gravy granules.
  • Mixed Herbs – 1 table spoon.
  • Cumin – 2 table spoons.
  • Coriander – 2 table spoons.
  • Chilli Powder – 1 table spoon.
  • Few cloves of garlic.
  • A load of butter.

The recipe:

  1. Get a big pan, with a lid, on a low heat. Chuck all the butter in.
  2. Peel the sweet potatoes, the parsnips and the carrot/potatoes. Chop them, the onions and the garlic into smallish bits.
  3. Put all the chopped veg into the pan. Stir it occasionally, replacing the lid between stirs, and just let it “sweat” in the butter for ten minutes. You aren’t trying to cook it, just make the vegetables sweat. My mum taught me this, and it’s golden – makes everything taste better.
  4. You should also add all your herbs and spices at this point. Careful with the chilli powder – I use mild chilli powder, and more of it, because I love the taste of chillies, but don’t necessary need the burn.
  5. Whilst that’s going, prepare about 2 litres of stock. Chuck loads of stock cubes in, and a good load of gravy, leaving you a slightly thickened brown juice.
  6. After 10 minutes, pour the stock into the pan, and bring the mixture up to boiling point, stirring it frequently.
  7. Once its reached boiling point, you can turn the heat down a bit, and just cook it for about 10 minutes, stirring it well.
  8. Using a hand blender (if you like smooth soup), blend it now, or just leave it lumpy.
  9. If the soup is too thick for you, or you want it to go further, add more stock.

Serve with bread. You can butter the bread if you want. The best option is probably rolls, warmed up in the oven.

Enjoy!