Sunday, May 19, 2013

Perl snippets - Date manipulation

I am an amateur web perl programmer. All my slightly complicated web sites are built using perl. When I get stuck on some small bit of code the answer can sometimes be found on the internet somewhere.

From time to time I am going to post up some of the solutions I have found on my travels in the hope that it may help someone else out.

So the problem:

On one of my website I am automating the creation of a spreadsheet for upload to the google merchant's feed. I needed to create the entry for the Sale price effective date.

This is not something I store in the main database so needed to create the entry on the fly. Basically I needed to create the following entry:

2013-05-19T17:44:51Z/2013-06-19T17:44:51Z

So I started with today's date and then added a month to it, then put in the google specific bits like the '/' and the Z.

Here is the code:

use Time::Piece;

my $t = localtime;
my $t2 = $t->add_months(1);
my $t3 = $t->datetime.'Z/'.$t2->datetime.'Z';

Basically call the module Time::Piece then set variable $t to localtime. Create second variable $t2 which is $t + 1 month and then merge it all together in variable $t3 with $t being put into the correct format "2013-05-19T17:44:51" append a 'Z/' and then amend the other date in a month's time.

Simple really. 

Sunday, May 12, 2013

Colourscape 2 - Steps

I have completed a second colourscape.

This one is called steps and takes a random colour as the base colour. Then in each of the red, blue and green components it steps back and forward by a set amount to see what happens if you change the value of one component but keep the others the see.

Basically it will show you what happens to the colour if you change the blue component only, the red component only or the green component only.

Or if you like it is something fun to play with...

Wednesday, April 24, 2013

Worton Organic Garden Cafe - an unfriendly welcome

It is not often I write about poor customer service that I receive because in the majority of cases I am fairly easy going. However, at the weekend I took a trip out with my partner in the local area and was so appalling treated that I feel obliged to put pen to paper as it were.

We live in a fairly rural area and being rather green minded I was looking for a local farm shop. I found Worton Organic garden on the internet which had even been recommended by a national newspaper. Why not, I thought, it even had a cafe where we could find a spot of lunch.

So off we went, Worton does have a lovely organic garden and a nice farm shop mainly focusing on what is grown in the garden with a few other oxfordshire bits and pieces. So far so good, we started looking forward to some lunch. Even better it was seafood special weekend with a lovely set menu and we both fancied the lemon sole.

Luckily we managed to find a table and after a while when nobody came we went into the cafe and someone said they would be out shortly. Five minutes later a worker from the garden wandered by and apologised for the delay but someone would be out shortly, she couldn't take our order because she didn't work in the cafe and didn't want to mess up carefully laid plans.

Fair enough, nobody minds a bit of waiting for some good food. After all it was a nice day and we were enjoying the sunshine.

Finally a lady comes over to take our order, her first question is "did we book?", I apologised and said we didn't know we had to, any chance you could fit us in. She asked us whether we had spoken to anyone in the cafe. I answered "No". Off she trots to the kitchen and is back two minutes later. "Sorry, we cant serve you any food, we are really busy". She then went on to say that they served restaurant quality food without the restaurant prices. Plus she explained we are recommended by word of mouth and mainly locals come here and being a special weekend they were fully booked.

Fair enough didn't book , will know for next time. I had checked the website which did not say anything about booking or it being a special weekend. Plus it really does not look the sort of place you need to book.

At this point I was expecting to have a drink and cake order taken. Sadly, no that was it, having said she wouldn't serve us food, it was apparently time to leave.

I was left wondering whether we were just not her type, perhaps not local enough for her. Either way I have not been treated so badly in a long time. Given that you can only get to this place by car and we were not even offered a drink to say I was annoyed is an understatement. I am still fuming 4 days later as I write this.

Of course the food may be very good and it is a lovely place but based on the welcome we had on our first visit we will not be going back. Shame as I would have liked to buy some of the home grown vegetables, I really liked the look of the garlic.

So congratulations Worton Organic Garden Cafe, your poor customer service has lost you some business and I will happily never recommend you to my friends.

Tuesday, April 02, 2013

Even the well educated lie sometimes

'Lying Doctor' (BBC news)

I am starting a new research project. Basically it is about people that lie during the recruitment process.

This has all started because after years of interviewing I have finalised realised that the elephant in the room is that people lie and can trick the interviewers.

As evidence I shall offer the following. Recently I have interviewed some people who always tell the honest truth (basically cannot lie), I have asked a simple question where the answer is obvious to any reasonable individual, it asks you what you would do in the situation. There is a text book / right interview answer but in real life there is probably some considerations and thoughts before you do the right thing. The people I interview give me the answer as it runs through their brain not the definitive / decisive answer they should be giving in a formal interview situation.

They are being brutally honest in a way. To quote another well used scenario if given the choice of taking an action that kills one person or 100 people you should say you would kill the one and save the many. Now the people I have been interviewing cant actually lie (or are totally honest depending on your point of view), so they talk about the difficulties they would have in making the decision etc.

However, if you really wanted the job (knowing that the situation probably wouldn't come up that often), you have done the research for the role, you know the answer to the question and regardless of your personal thoughts you would say "I would kill the one person and save the many". So at a very primitive level you have lied to get the job because faced with the decision in real life you have not stated what you would do.

Now pull that back into the mundane and what these candidates have shown me is that in all probability interviews reward good definitive liars. So if we could somehow spot or challenge potential liars then getting the right person into the right job would be easier.

More thoughts on this will follow. For now I am going to start clipping articles off the net and collecting them here on my blog.

First up, a Doctor that lied on his CV. Even those with brains who clearly understand the consequences will still take a big risk in being caught out.

Wednesday, December 19, 2012

Jamie Oliver - Books for Christmas 2013

Three years at the top of the book charts for Jamie Oliver's recipe books. Two years with Jamie Oliver's 30 minute meals and in 2012 top of the chart's with Jamie's Oliver's 15 minute meals.

According to his publishers Jamie is really pushing the limits of cooking with his next title for Christmas 2012. It is Jamie Oliver's 3 minute meals.

One of the receipe's has been released as a teaser:

Step 1
Visit Sainsbury's

Step 2
Buy Jamie Oliver's Italian meat balls spaghetti ready meal.

Step 3
Take home

Step 4
Put in microwave, set for three minutes and wait.

Step 5
Enjoy another spectacularly quick Jamie meal.

***Sorry Jamie could not resist - zephyrist***


Monday, September 24, 2012

Project Colourscape

I am not sure why I have named this project colourscape other than it relates to colours. I think the scape part come from my considering the variations of colours as a landscape or surface of colour.

Anyway this project is about looking at colours and creating colour palettes. I am going to create a series of pages looking at RGB colours in different ways. The practical application is that you will be able to create and experiment with various colours to create a colour palette either for a web page or for some other practical applications.

ColourScape 1

This lets you choose colours from a randomly generate selection. You can select a background colour and a text colour to create a pallet of five colours.The hex codes appear in the relevant boxes for you to cut and paste.

The only problem with it is that each time the page loads you refresh the random selection, so you cant choose two colours from the same random page, although you could hover over the colour to get the hex value and then type it directly into a box.

Similarly you can type any hex value into any box to display that colour, which is useful if you  are looking for a colour to match some colours you already have.

Add-on possibilities: box to give you the palette html and CSS code.

Possible other Colourscapes

SQL version of Colourscape 1 to store and sort the random colours

slot machine version where the colours are in 3 columns, red, green, blue with the chosen colour in the bottom and then colours with each graduation flowing out like a slot machine. Difficult one to explain, easier to write the perl script.

If anyone has any other suggestions I am always open.


Monday, September 03, 2012

Predictive Market V2.0

Experimental Predictive Market 

Version 1 was a flop that had some very obvious flaws, mainly that the uplifitng mechanism over £10 would encourage people to buy all the stock and hold onto it for ever or I would have to intervene with an upper price limit. Plus why should a price change just because the day has changed.

Experimental Predictive Market The Rules V2.0

Main rules

  • Each stock is a question i.e. "Workers in the UK should be given 1 extra bank holiday?".
  • Each stock initially lists at a price of £10 with 1000 shares for sale (Numbers would change if it ever became really popular).
  • Down Escalator - If no one buys the stock, the price will drop at a rate of 0.04p per day (the stock and therefore idea is unpopular). The idea is that the price of stock will drop until it finds the level at which people are willing to buy
  • If someone buys stock the price rises at a rate of: 'Number of shares bought * 0.04p'.
  • If someone sells stock the price falls at a rate of: 'Number of shares sold * 0.04p'.
  • Trading limit of 100 shares per transaction.
  • If price above £10.00 stock rises at a rate of 0.04p per day (Idea is popular and will keep rising until investors tempted to sell - Price will hopefully stabilise at the value of the idea) 
  • If all shares are available for sale, the price gets on the "down escalator" again until the new "willing to buy" level is found
  • If the stock reaches zero it is archived.
Liquidity Rules
  •  Stock can only be held for 180 days - at the 180 day limit all stock is hold at list price
  • At close of an event e.g. general election all stock is sold at list price
Futures Market
  • As well as buying and selling shares you can make a futures bet on whether a certain price will be reached within the next seven days.
  • You can only have one bet per stock per 7 day period
  • If the price is reached you win the small amount.
  • This gives an indication of whether people want to buy or sell. The more buyers in the market the higher the price will go, the more sellers in the market the lower the price will go.
I am sure there will be a new version along shortly when I find some flaws with this one.