Jotting down stuffs
Amry
This user hasn't shared any biographical information
Homepage: http://ShamsulAmry.com
Posts by Amry
StableHost Linux Shared Hosting – 75% Off For Life
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.
Project Euler Problem 12 – Faster brute-forcing using Parallel LINQ
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 >
Project Euler Problem 12 – First time F# version
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# >
Project Euler Problem 12 – Solution using basic C# and LINQ
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.
Understanding the problem
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 >
PGP Single Pass Sign and Encrypt .NET Stream
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 >
Kena masuk wad semalaman, nasib baik ada medical card boleh guna
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 >
Migrating to own domain, Part 3
Feb 12th
Done:
- Breadcrumbs. Hacked the theme to put in Yoast Breadcrumbs at the top of posts and pages.
- Function for sharing. Hacked the theme to put in AddToAny button in the footer part of posts.
- Snap Shots. Implemented Snap Shots™ Plugin for Wordpress.org into the blog, enabled only for external links.
- Creative Commons notice for my source codes. Used Creative Commons Configurator to put in Creative Commons notice at the end of each post. I actually intended only to mark my posts which include source codes, but it seems there’s no per-post settings for it, so all posts it is.
- Sitemap page. Installed the Dagon Design Sitemap Generator plugin for the sitemap page.
To do:
- OpenID login for comments. I tried a couple of plugins related to OpenId, but they didn’t actually work as I imagined, so I deactivated them at the moment. In my mind, I would like to have the functionality that will allow users to login using their OpenId-compatible accounts, such as GMail, or Facebook, or Tweeter etc. Then the avatar in the comments will use the one that they use as their profile picture. Something like that.
- Subscribe to comments. Already installed the Subcribe to Comments plugin, but have not completed the integration into the current theme yet.
Fixing the Mystique theme Twitter settings issue
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:
- I am not a WordPress expert. This is my first time hacking away a WordPress theme. I mostly did quick tries-n-errors when implementing this hack.
- This hack is not in any way endorsed by the original creator of the Mystique theme.
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 >
Migrating to own domain, Part 2
Jan 29th
It’s Saturday morning, and I’m back at setting up the blog.
- Looking for new themes to try out. The previous theme I set for few days: Inanis Glass, based on Windows Vista layout looked geeky. Nothing wrong with that but the theme felt “heavy” to load.
- Trying out the Mystique theme. Looks fine. Felt lighter. But how do I set the Twitter widget to show mine instead of Wordpress’s? Can’t seem to find in the settings. Tried to drag the widget to the sidebar, but then the original sidebar layout disappears. Will look at it later. Update Jan 31, 2010: See Fixing the Mystique theme Twitter issue.
- Learnt about Wordpress’s shortcodes from the Mystique theme’s blog. I see. So it is shortcodes I’m looking for to make the sourcecode tags appear like it was in WordPress.com.
- Looking for a SyntaxHighlighter sourcecode shortcode as seen on WordPress.com. The shortcode API seemed to already be there since WordPress 2.5. Now it is already 2.9. There should already be existing plugins implementing the sourcecode shortcode. Better search first before reinventing the wheel unnecessarily. Searched. Found: SyntaxHighlighter Evolved. Nice!
- Looking for an external link handler. What I want is some sort of plugin that will allow me to handle external links differently, like displaying an icon next to that link, sort of like that. Found: External Link.
Migrating to own domain
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.