Shamsul Amry's Brain Dump
Jotting down stuffs
Jotting down stuffs
Apr 27th
I haven’t blogged for quite some time, had been dead busy with work. However I got this email from StableHost, the hosting provider that I am using for this blog. And since it is a very-limited-time-and-registrations offer, I thought of sharing it along with you.
Mar 21st
Building on the previous code, the CountFactor method would be a good candidate to be executed in parallel. It is doing the heavy calculation of finding the number of factor a number has, and it has no dependency on any other external factor.
Previously, when there is no PLINQ, we would have to do multithreading manually, and I would have probably came up with something like this: Read on to see the PLINQ code that managed to almost halve the time >
Mar 19th
This is my first time doing F#. Also my first time doing functional programming at all. The F# code is based on the Brute-Force Method 3 that I came up with. Only managed to get about 3960 ms, that’s about 10 times the execution time of my C# code. I don’t think F# is meant to be slow, so probably it’s me not doing it the right way.
Check out my code. I'll be grateful if you can help me out with this F# >
Mar 14th
Two days ago I had been looking at re-playing with Project Euler problems, after I solved a few of them last time (quite some time ago). I looked at the problem list, and decided to try solve the top-most unsolved problem I have: Problem 12. I managed to come up with a brute-force code that calculated the answer in about 403 ms on an Intel Core2 Duo T9600 @ 2.80GHz machine.
The sequence of triangle numbers is generated by adding the natural numbers. So the 7th triangle number would be 1 + 2 + 3 + 4 + 5 + 6 + 7 = 28. The first ten terms would be:
1, 3, 6, 10, 15, 21, 28, 36, 45, 55, …
Given the example, I guess the mathematical function explanation of the triangle numbers would be something along this line: f(n) –> 1+2+3+…+n where n=1, 2, 3, …
We are then required to come up with something to find the first triangle number to have over 500 divisors. In clearer words, we are required to find the first triangle number to have 501 divisors, within one minute, complying to the Project Euler’s one-minute rule:
I’ve written my program but should it take days to get to the answer?
Absolutely not! Each problem has been designed according to a “one-minute rule”, which means that although it may take several hours to design a successful algorithm with more difficult problems, an efficient implementation will allow a solution to be obtained on a modestly powered computer in less than one minute.
Spoiler alert! Read on to know my solution to this problem >
Mar 8th
In a recent software development project, I was required to be able to read PGP encrypted content, do something, and write PGP encrypted result. The project allowed calling of PGP (or GPG) command line to do the encryption and decryption needed. However that did not feel right to me. Googled a bit and then I found the Bouncy Castle C# Crypto APIs, that among everything else, included support for PGP without having any external dependency.
The compiled assembly for the Bouncy Castle APIs can be downloaded from the website, however it was compiled for the .NET 1.1 runtime version. You can easily download the source code instead and compile it for the other .NET versions if you want to. I managed to compile the source code for the .NET 2.0 runtime version without any changes to the original source code.
The bigger issue at using the Bouncy Castle APIs is that it does not seem to have any proper documentation for it. Read on to get the code for the .NET Stream >
Feb 22nd
Balik Kelantan konon nak bercuti. Nak dijadikan cerita hari Selasa (16 Feb 2010), round nak cari klinik panel Great Eastern / Compumed (company punya panel provider) di Kota Bharu sebab nak check ada bengkak tetiba tumbuh. Pusing punya pusing, susah betul nak cari klinik panel yang buka. Rasanya lagi banyak klinik yang tutup daripada yang buka, sempena cuti Raya Cina.
Sebab susah dan dah malas punya pasal, terus redah Hospital Pakar Perdana. Dah sampai hospital, nasib baik hospital buka (takkan hospital pun cuti Raya Cina ye tak). Jumpa doktor. Doktor kata abscess, kena masuk wad untuk buat pembedahan kecik nak buang benda tu. Second time kena masuk wad seumur hidup setakat ni, first time masuk wad hospital swasta. Tak tau prosedur apa kena buat. Jakun.
Sambung baca lagi. Tips yang mungkin berguna (atau tidak) di hujung entry >
Feb 12th
Done:
To do:
Jan 31st
I am using the Mystique theme for this WordPress blog. It is a nice theme, however there is an issue that needs fixing – The Twitter widget in the default theme layout somehow defaults to WordPress’s Twitter account, and there’s no setting for that. The Twitter username is hardcoded into the theme code.
In this article, I will post the changes I did to the original theme in order to fix the Twitter issue. At the end of the article, I will provide a link to a zip file which you can download, extract to the Mystique’s theme directory and overwrite the original theme files.
Before that, disclaimers:
With that said, use this hack at your own risk. I will appreciate any feedback if you do try out this hack.
Read on to see the details of the hack and to download the zip file >
Jan 29th
It’s Saturday morning, and I’m back at setting up the blog.
Jan 24th
Somehow I can’t bring myself to use shamsulamry.wordpress.com that long. Simply cannot. Bought ShamsulAmry.com, will be taking a bit time to setup this one.
And I noticed the syntax highlighting stuff is not working anymore and there’s no existing syntax highlighting plug-in that could make it just work like before. So it will be either I need to edit the existing posts, or challenge myself to learn how to write my first WordPress plug-in that would make it simply work like before.