Friday, March 7, 2014

Silhouette Oracle

Silhouette Oracle is a website that was written by a colleague of mine. It's very basic but effective, as people surprisingly seem to base their lives on it.

You can pick between Yes/No, Tarot, Runes and I ching and ask any question. You will then get an answer back.

http://www.silhouetteoracles.com/

Whether the answer is the right one or the wrong one, that is up to you to decide.

Do you believe in oracles?

M

Thursday, March 6, 2014

Cookie Clicker



I would like to introduce you to Cookie Clicker. This game has single handed brought down the productivity of companies all around the world. It is an OCD nightmare. It starts off small, but before you know, you've lost hours, days or even weeks.

http://orteil.dashnet.org/cookieclicker/

The point of the game is to click cookies. You can buy "add-ons", like grand mothers to help you produce cookies without clicking cookies yourself. The more you buy, the more expensive the items get. You reach a point where cookies and Grandmother run the world. It all sounds mundane, but believe me, it is hard to stop clicking, not to try and get all of the achievements. If you are an achievement addict, this is the game that will ruin your life.



Many websites and applications have been dedicated to Cookie Clicker. One application used is http://sourceforge.net/projects/hf-auto-clicker/, that clicks on your behalf. And the popular cheating website http://cookieclicker.wikia.com/wiki/Cheating.

Enjoy!
M

Wednesday, February 9, 2011

WCF Datatable, connection was closed and exception was thrown.

At the current time of writing I'am working on a project using the .net 3.5 sp1 Framework.

I encountered a strange error while trying to return a DataTable from a webservice using WCF. If the DataTable is initialized with the default constructor and no parameters are given then WCF cant serialize to object and return it to the client, the error thrown will look something like this:

An error occurred while receiving the HTTP response to *SERVICENAME* . This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details.

Luckly the work around is easy :

just initialize the DataTable with the constructor where you specify a tableName, and then walla, the serialization works :)

Alternatively you can added the DataTable to a DataSet and return that to the client.

Happy Programming


Tuesday, January 25, 2011

wpftoolkit datepicker infinite loop and lost focus issue

When the value in the datepicker has changed, the datepicker will Invalidate the control to get the current value. This will cause .net to reevaluate the control which in turn fires the bindings and converters etc., as well as the LostFocus event.

When evaluating the current value the DatePicker will try to parse the current value as a DateTime?. Because a DateTime object is aware of time as well as the current Date, it will realise that the property that you have bound to has changed, because the current time of the control has also changed. This will fire all the bindings again to notify that the property has changed.
The event will also force the focus property again and will try to Invalidate the control to get the current value again, based on your binding.

The result is an infinite loop or a stackoverflow exception.

This rarely happens, but is the result of the binding. This especially happens when the binding property NotifyOnSourceUpdated = true and UpdateSourceTrigger= OnPropertyChanged.

In my case I had to create a multi-binding and the properties were just firing all over the place.

The datepicker wants a DateTime? (nullable date time), because it accepts a text value, and a text value can be an invalid date. Normally we bind to a DateTime object because we want a definite value. The binding mentioned above will then cause constant conversion and the propertychanged event to fire repeatedly.

Luckily the solution was easy for me: Bind to a DateTime? and cast the value to a DateTime.

Because a DateTime? can take in a null value if the conversion failed, you don’t have to worry about an invalid value Invalidating the control again.

e.g.

private DateTime? dtValueDate;

public DateTime? ValueDate
{
get
{
if (dtValueDate == null)
{
return CurrentPaymentObject.ValueDate;
}
return dtValueDate;
}
set
{
dtValueDate = value;
if (value != null)
{
CurrentPaymentObject.ValueDate = (DateTime)value;
}
}
}

Thursday, December 30, 2010

Usher Stole OMG from Homer Simpson?

R&B star Usher has found himself in the middle of an bizarre plagiarism claim -- with people saying he's ripped off a song by Homer Simpson. Below is the YouTube video. It actually does sound the same. I can't help but laugh, Homer is a musical genius. :-P

Tuesday, December 28, 2010

Alone at work

It's Christmas week and there is only three of us at the office. What a bunch of dumbasses. :-) My friends already phoned me to let me know they are sleeping in, playing play station and eating take away. And me? Work work work. Guess I've got one thing to say: Unlucky!

Hope you are all enjoying the holidays.



Friday, December 24, 2010

Today's Funny

Books for Christmas??

Have you ever gotten a present you don't really want? This 3 year old expresses it very well.

Friday, December 10, 2010

Rounding up (Ceiling) Days and Months in a DateTimeRange C#

This is something I required for billing reports and I struggled to find anything like it on the internet. So here it goes.

If you are pulling a report and you want to calculate a partial month as one month, this is how you would calculate it:

private Int32 GetMonthCountFromDateTimeRange(DateTimeRange oDateTimeRange)
        {
            DateTime endDate = oDateTimeRange.Stop ?? DateTime.Now;
            int numMonths = (endDate.Month - oDateTimeRange.Start.Value.Month) +
            (12 * (endDate.Year - oDateTimeRange.Start.Value.Year));
            TimeSpan tsDifference = endDate - oDateTimeRange.Start.Value;
            if (tsDifference.TotalDays > 0)
            {
                return numMonths + 1;
            }
            else
            {
                return numMonths;
            }
        }

If you are pulling a report and you want to calculate a partial day as one day, this is how you would calculate it

private Int32 GetDayCountFromDateTimeRange(DateTimeRange oDateTimeRange)
        {
            DateTime endDate = oDateTimeRange.Stop ?? DateTime.Now;
            TimeSpan tsDifference = endDate - oDateTimeRange.Start.Value;
           
            return Convert.ToInt32(Math.Ceiling(tsDifference.TotalDays));
        }

Hope this helps.

M