Quickly Find Day of the Week – C#

Hi all!

This is just a random post to show off something new I found. I don’t claim credit for this algorithm and if you’re curious as to how it works then this Wikipedia article may be of interest to you. This post has a good explanation of why the algorithm works in the first place.

Given a date the following function would give a string donating the weekday on which a given date will fall:

public string FastDayOfTheWeek(int year, int month, int day)
{
    string[] days = new string[] { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };

    if (month < 3)
    {
        --year;
    }

    int weekday = (year + (year / 4) - (year / 100) + (year / 400) + (int)("032504514624"[month - 1] - 48) + day) % 7;

    return days[weekday];
}

If you run the function for the 1st of March 2020 it will give a Sunday. This is the correct answer. This function works backwards and forwards in time as far as I can tell.

Another interesting thing about the given formula is that it could easily be memorised and may make for a nice mathematical party trick.

Hopefully someone out there will find this useful and or interesting.

Learning Japanese – Some Thoughts

For a long time I have been planning to learn Japanese and I have attempted to do so on and off for a little over a year.

My main drive for this has been my love for the Japanese culture and more specifically my interest in anime.

In my various failed attempts to learn the language I have learned a few things that I was ignorant of during my initial attempts:

  • In order to get a good grasp on the spoken language it is very helpful to learn the written forms first.
  • Learning the written forms of Japanese is more complex than one would initially expect as Japanese has at least three written forms that are used interchangeably.
  • The written forms of Japanese are very unlike English and the sentence structure is completely different.

To this end I have decided to write a program that will help me learn the basics Japanese characters – starting with Katakana and Hiragana. I may or may not attempt Kanji after I have some success with the other two.

The program will break down the written forms into categorized subsets, giving options to choose which of the written forms and subsets to use. It will display a random character and prompt the user to enter it’s Romanji variant.

I have other plans for the tool later but I need to start somewhere!

Setting up a local web server with WAMP

Hi everyone.

This is something I recently had to do so I figured I’d share this with anyone else out there that may want to know. For a long time I’ve wanted to setup a local web server to build and test sites locally without the need to continually upload the files (and as a plus of course, local files are easier to back up). After some research and playing this is the process I eventually came up with to get the optimal configuration for what I need.

Firstly it was a choice between XAMPP and WAMP. I ended up choosing WAMP because I didn’t need Perl. Other than that they seemed about equal.

After downloading the EXE I installed it (obviously) and copied the files to the www folder (which is located in C:\wamp\www\ by default). I noticed a few problems right away however. .htaccess rewrites didn’t work as the module was enabled. To re-enable it I clicked on the icon in the task bar, clicked on “Apache”, then “Apache modules” and selected “rewrite_module”. I then had to restart the server by clicking on the icon once again and selecting “restart all services”.

That fixed most of the rewrites not not all of them worked. It turned out this was because I needed to add a virtual host for the project. Luckily this also wasn’t difficult to achieve.

First you need to pick a name for the virtual host, I picked tnda because that was the name of my project. That name will be used in my examples here. After picking the name you must then open the following file: “C:\Windows\System32\drivers\etc\hosts” in your favorite text editor. At the bottom of the file you need to add a line like this, substituting tnda with your chosen project name. Note that this name CANNOT include spaces!

127.0.0.1 tnda

After doing that, save and close the file.

Next we need to modify the Apache virtual hosts file. This one is also luckily pretty simple. In the default WAMP install it should be located here:”C:\wamp\bin\apache\Apache2.2.21\conf\extra\httpd-vhosts.conf”. Of course the Apache version may vary depending on when you installed the program. Open this program in your favorite text editor and at the bottom of the file you need to add this. Substitute the path here “c:/wamp/www/tnda” with the path to the folder in which your project lies. You also need to replace the server name (TNDA here) with the name chosen in your hosts file above.

DocumentRoot "c:/wamp/www/tnda"
ServerName tdna

Options Indexes FollowSymLinks
AllowOverride All
Order Allow,Deny
Allow from all

Save and close the file. Now you again need to restart Apache. You will now find that you can use full mod-rewrite rules on that project and as a plus you’ll be able to use http://projectname to access the resources quickly locally when the server is active.

I hope this helps people simplify the process.

CSIT – Round 2

Hi everyone.

It has been a while since I last posted. Unfortunately my recent work with CCC has kept me busy and away from my personal projects. However as I currently have some spare time I have decided to revive the old CSIT project and revisit the idea.

I will be starting work on the project in short order (probably tomorrow or later next week). The project will probably still be called CSIT (Complete System Information Tool-kit) and will be similar to the old ideas for CSIT but not identical.

I am currently working on the plans for the design and core code ideas. The project will be based around C++, ASM, C# and WPF.

US – The Worlds Copyright Police – Update

This is a follow-up to the article I posted earlier this year.

The US have now started seizing domain names, against the wishes of their own people and the rest of the world. They need to be taught a lesson, that they are not gods and do not control the fate of the internet. The WORLD Wide Web should remain as such, a global system. Allowing one country to selectively control and censor it would make the internet far less useful and would become a politician weapon.

This needs to stop, right now. For the moment they have started taking control over torrent site domain names, which can be easily corrected by using the hosts file – which I will describe in a later post.

To anyone living in the US who may be reading, if you value freedom on the internet please protest to whomever you think can help.

You can read the full article on torrent freak here.

The US – The Worlds Copyright Police?

I have just been reading a rather interesting article on TorrentFreak about a new law that the US government hopes to pass, for which I quote the title of the post on TorrentFreak.

United States lawmakers have proposed new legislation today that would allow the Department of Justice to take over domain names of websites that promote copyright infringement. The proposed bill would allow for court orders against domestic as well as foreign sites, which could potentially shutter many torrent sites including The Pirate Bay.

What the hell does the US think they are doing? Until now no political body has owned the rights to control the internet on that level, for whatever reason, and suddenly the US comes along and decides they have that right? How is it that the US feels they have the right to decide to impose their laws in other countries? Copyright law does not apply everywhere and it varies greatly from country to country… I fail to see how they can claim to remove a copyright infringing website from a country that may have a different idea of copyright violations.

Someone really needs to slap some sense into the US, they are starting to cross lines that are better left alone. Leave the internet free of political influence or beware the consequences.

Found a Prime!

I’m quite happy to have found my first prime as part of PrimeGrid!

I got the following e-mail this morning:

Congratulations! Our records indicate that a computer registered by you has
found a unique prime number. This computer is running BOINC, is attached to
the PrimeGrid project, and is assigned to the Sophie Germain Prime Search. What makes
this prime unique is that it’s large enough to enter the Top 5000 List in Chris Caldwell’s
The Largest Known Primes Database.

Since you have auto-reporting selected, the following prime was submitted on your
behalf:

Added 94172 : 7318825406445*2^666666-1 (200701 digits)

On other news I will soon be starting work on an online recycling database for CCC. Keep checking for updates on that.

Localization using WPF and C#

For anyone who is interested I have posted a tutorial on building a localizable application using C# and WPF here for anyone who is interested. I will hopefully post a copy here in time but for the moment I see no need to duplicate the content.

If you have any comments, suggestions or improvements please let me know!

Thoughts on Localization with WPF

Hi everyone!

I just thought I would stop by and share some thoughts with you on localization with WPF. I have spent the last few hours working on making CSIT localization before I add to much content to make it worth while. This is the first time I have ever made the effort to make an application localizable and I must say that it was not as painful as I thought it would be.

Eventually I decided to use a simple XML file and bound elements to it using data binding and XPath. Some things could not be bound to however and I had to implement a class that would read strings from the file and load them so they can be used later in the processing functions.

So far however it seems to be working just fine. And as proof here is a screenshot of the current CSIT interface that uses the new localization system.

The current CSIT Interface (v3)

Hopefully I will be posting more on this shortly. Once I am sure that the code works as intended I will try to release the code for others to use.

Firefox, YouTube and WebM – The Experiment

Hi everyone

I have just spent a little while playing with the new WebM and HTML5 experimental support in Mozilla Firefox and I mus say. I am quite impressed. The 760p video samples I have seen are truly quite impressive. I would suggest that anyone capable should get their hands on a browser with experimental support and give it a shot themselves.

But for those of you who are not so daring – here are a few screen shot of what a video looks like in 720p with the new experimental features. For those who are a little more daring, see the information at the bottom of this page about where you can find the experimental Firefox builds.

WebM Sample 1 (720p)
WebM Sample 2 (720p)
WebM Sample 3 (720p)

Firefox Experimental Builds

  1. First you will need to go and get yourself a Firefox nightly build, or a nightly of your favourite browser. If you use Windows then you can get a build here. For Mac you can get a build here and for Linux you can get it from here.
  2. Install the nightly build. Note that if you are already using Firefox you may wish to read this before you install it!
  3. Load the the video here and try out the different resolution settings and enjoy!