Saturday, 23 February 2013

Vatican impervious to irony of its own press release

According to the BBC today:

'The Vatican's chief spokesperson has criticised the media for reporting "misinformation" about the Church.'

I wonder how this pedophile-protecting, gold-encrusted, religious organisation that takes from the poor to give to the rich came to the conclusion that it's core message had become somehow corrupted?

Monday, 18 February 2013

Finally Facebook Free!

What with the recent revelations on tax avoidance, the general privacy issue and a refusal to adhere to UK law, I've finally lost it with Facebook and deactivated my account.

Some things are too big to fail, but they don't include services that are built on mutual trust and respect.

So fuck you Facebook.  Fuck you.

To deactivate your Facebook account, follow these simple-to-follow instructions today: http://www.facebook.com/help/214376678584711/ .

Tuesday, 5 February 2013

Exception Handling with Parallel.Foreach

The .NET Framework's Parallel.Foreach is genius.  It eases the pain of making multiple tasks run in parallel.  It's just the ticket!  Oh, if only it were that simple.

What order do the tasks run in?  What when the parallel tasks throw exceptions?  How should that be handled?  When one task fails should the others be cancelled? Do we need to roll anything back?  What state updates are needed?  It soon becomes quite complex, quite quickly.

The project I'm working on right now has the following requirements:
  • It does not matter which order the tasks execute in;
  • There is no requirement to roll back the transaction should any individual task fail
  • If an exception is thrown, a SINGLE exception should be propagated upwards
The following achieves this, demonstrated in a console app, written in C#.


using System;
using System.Threading.Tasks;

namespace DavidBond.Net.ParallelTest
{
    /// <summary>
    /// Command line demonstration of Parallel.Foreach when Exceptions are thrown
    /// </summary>
    public class Program
    {
        /// <summary>
        /// Program entry point
        /// </summary>
        public static void Main()
        {
            Console.WriteLine("Program start.");

            // Create an array of task names
            var taskList = new[]
                {
                    "Task A",
                    "Task B throws Exception",
                    "Task C",
                    "Task D throws Exception"
                };

            // Try to run all the tasks in parallel
            try
            {
                // The following line is the equivalent of:
                //Parallel.ForEach(taskList, taskName => Execute(taskName));
                Parallel.ForEach(taskList, Execute);
            }
            // If there are any exceptions, wait until all tasks have completed
            catch (AggregateException aggregateException)
            {
                foreach (var innerException in aggregateException.InnerExceptions)
                {
                    Console.WriteLine("Exception occurred on task.  Exception message was [{0}]", innerException.Message);
                }
                // Uncomment the next line to escalate multiple underlying exceptions as a single exception.
                // throw new Exception("Not all tasks completed successfully.");
            }

            Console.WriteLine("Program complete.");
        }

        /// <summary>
        /// Writes the line "[taskName] ran successfully" to the console
        /// </summary>
        /// <exception cref="Exception">Thrown if the taskname contains the word "exception" (not case sensitive).</exception>
        /// <param name="taskName">The task name</param>
        private static void Execute(string taskName)
        {
            //
            if (taskName.ToLower().Contains("exception"))
            {
                throw new Exception(string.Format("Exception thrown by task [{0}]", taskName));
            }

            Console.WriteLine("{0} ran successfully", taskName);
        }
    }
}


DO NOT copy-and-paste this example if your situation varies considerably.
Props to http://www.manoli.net/csharpformat/ for the formatting!

Tuesday, 25 December 2012

Atheist wishes all a Happy Christmas

The eldest of the Bondie household has used his Christmas Facebook status message to spread good wishes to all regardless of religion, personal beliefs and life choices.

The Archwizard of Maidenhead, David Bond, said Christmas was "lovely" and a "time for friendliness".

Speaking to the congregation of Christmas Day iPhone Facebook app users, Archwizard David said miserable old duffers had no mandate to push through any laws around humbug and exclusion.

"There was no announcement in any party manifesto, no Green Paper, no statement in the Queen's Speech. And yet here we are on the verge of a "nice day" with the people we love.

"From a democratic point-of-view, it's a shambles. Awesome. Let's all stay home and warm instead. And avoid the West Coast Mainline like the plague.

"George Osbourne is shambolic," he added.

The Archwizard claimed during a "period of using their eyes", those who looked outside this morning were "7-1 against doing anything energetic today".

In the past, the Chief Daft Old Brush in England and Wales has likened committed relationships to "profound friendships".

The government launched a 12-week consultation in March on how to remain relevant when more people voted for Strictly Come Dancing than Police Comissioners. Only policemen responded, resulting in "the worst selection bias ever seen in the history of Statistics".

'Peace and Joy'

Delivering his first Christmas Day message from The Bondie Household wearing only his T-Shirt and Boxers as one of the spirited leaders of the Bondie household, The Archwizard meanwhile will acknowledge that although the vote for women has fundamentally changed the definition of "Democracy", no-one got hurt..

He will also acknowledge comments made in November, in which many said he had "lost a measure of credibility" after the Company Christmas Do.

The Archwizard will not take up the role of Master of Magdalene College, Cambridge in January
He said at the time atheists had "considerable" work to do both internally and externally to redress perceptions of arrogance and over-reliance on "science" in the eyes of both the secular and Christian communities.

"We have, to put it very bluntly, a complete lack of explaining to do," he added.

More positively, he will also cite 2011 census data which showed a 46% decline in the number of Britons who still view themselves as Jedi when compared to 2001.

The Archwizard has also listed some of the people he has had the "privilege" to meet during the past year in his sermon.

He has paid tribute to his lovely friends and family and has acknowledged their "willingness to explore the new humanity of forgiveness and rebuilding relations" despite their own suffering at knowing him.

"These are the ones who look, as if at a raving lunatic but without actually pointing and laughing," he added.

David, along with his lovely wife, the Chief Bondy Mummy, are not going to "live tweet" their Christmas ramblings on the micro-blogging site Twitter, as it is "pretty much a dead duck" technology-wise and "utterly pointless".

They are expected to be joined by around 3 billion Church members also not tweeting on Christmas morning.

Happy Christmas everyone - children are awake now... Please switch off your gadgets...

Tuesday, 4 December 2012

Creating a list of numbers in TransactSQL


To create a simple list of  numbers in an SQL table,
(from http://www.simple-talk.com/sql/t-sql-programming/faking-arrays-in-transact-sql/), the following TransactSQL does the job for a small number of rows (fewer than 32768)


WITH Nbrs ( n ) AS (
        SELECT 1 UNION ALL
        SELECT 1 + n FROM Nbrs WHERE n < 500 )
    SELECT n FROM Nbrs
    OPTION ( MAXRECURSION 500 )


Alternatively (for higher row counts):

declare @i int
declare @rows_to_insert int
set @i = 0
set @rows_to_insert = 1000

while @i < @rows_to_insert
    begin
    INSERT INTO #temp VALUES (@i)
    set @i = @i + 1
    end

Wednesday, 14 November 2012

Disable annoying Panasonic banner ads

http://m.cnet.com/news/how-to-ban-the-banner-ads-from-panasonic-smart-tvs/57450197?ds=1

Saturday, 20 October 2012

Adding accents to letters on a UK Keyboard

Grave accents can be added to characters by pressing [ ` ] (above the tab key) and pressing the another key: àÀèÈìÌòÒùÙỳỲẁẀ

Acute accents can be added by pressing [ Alt Gr ] (to the right of the spacebar) and pressing another key: áÁéÉíÍóÓúÚýÝẃẂ

Similar results can be achieved in some applications (e.g. Microsoft Word) with Control key combinations. Here are some examples:

[Ctrl] + [ ' ] then [ e ] --> é
[Ctrl] + [ ^ ] then [ e ] --> ê
[Ctrl] + [ , ] then [ c ] --> ç
[Ctrl] + [ : ] then [ i ] --> ï
[Ctrl] + [ & ] the [ o ]--> œ
[Ctrl] + [ ~ ] then [ n ] --> ñ