Jotting down stuffs
Coding
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 >
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 >
Outgoing link tracking bug in Google Analyticator 6.0.2
Jan 12th
I am currently using the Google Analyticator. It’s one of my favorite WordPress plugins. What it does is to make it easy to implement Google Analytic’s tracking code into a WordPress blog.
Analyticator also made it easy to track outgoing links. By outgoing links, it means any link that go to some other website with a different domain name than the current one. Somehow when I checked my Analytics account, I noticed that there were links within the same domain being tracked as outgoing. Something wrong somewhere.
SyntaxHighlighter in WordPress.com
Jan 9th
First of all, Happy New Year 2010!
As per one of my 2010 new year resolution to try start blogging (see my About page), I was planning to write something I found related to WordPress and Google Analytics.
But then I was already stuck on my way to write the should-be-first post. I wanted to post up some JavaScript code. I knew this popular Alex Gorbatchev’s SyntaxHighlighter. But WordPress does not allow plugins in their hosted blogs, obviously for security purposes.
I googled and found this blog: Syntax Highlighting in WordPress.com hosted blogs. Cool! Just what I was looking for. Reading on I found out that the SyntaxHighlighter was already integrated into WordPress.com hosted blogs. Here’s the page that explain just exactly how to do it: Posting Source Code.
document.write('And here is the result of posting source code.');