sloppycode.net
Ads and stats
20th July 2008

I've added some google ads to the site underneath the right navigation in a vein hope of generating some cash towards the hosting. They're quite unobtrusive and the same colour as the site so it's not really a huge eye-sore or masses of popups or pop-unders. As the images below show, a lot of you use Firefox which probably means you have ABP installed. Somehow gmail manages to work around ABP and show mail adverts. It's funny that Google's main revenue is adverts, but they're pushing a browser that is made to block them so easily. Anyway if you're feeling curious, click that big red ABP toolbar button in Firefox and make it green for sloppycode.net, you might find an advert of interest! (of course I'm not trying to break the google T+C by suggesting you click them, just admire the layout)

abp.gif 

I'm guessing 99% of the audience for the site are developers so it's no surprise most are running at 1280 resolution, fellow LCD users with giant carbon footprints. What's surprising is how few use 800 now, this resolution was roughly 80% back in 2002/2003. This means I can extend the width of the site which I designed for between 800 and 1024 pixels.

resolutions.gif

browers.gif

Small update
14th July 2008
Here's a reference page and article I've spent a few hours writing up and making vaguely readable:

C# design patterns
UML class diagram cheat sheet

I also got my first batch of spam for the little private experiment I was doing with spam email (see the honey trap below). It wasn't exactly the opening of floodgates of spam, there were only 5. They all came from Holland and Germany, promising the usual lifestyle enhancements (larger dick, viagra).

Summer collection

1st June 2008

It's that time again! A summer update is here - I've written up a lot of stuff I had on google docs into (hopefully) readable articles around .NET and C#. Four in total, plus the System.IO one which I've added in there.

C#/.NET performance and architecture
Some common issues with C# and .NET architecture and performance, such as abstract vs interfaces, boxing, equals().

Type visibility
A small reference sheet/article about type visibility in C#.

Inside .NET assemblies
"Under the hood" look at metadata tables, assemblies and the architecture of .NET/CLI.

.NET Formatting strings
A reference and look at .NET formatting strings including DateTime, numerical (including rounding and significant figures) and creating your own with IFormattable.

The articles are annotations and my own exploration of C#.NET based on 3 excellent books I've been reading over the past months:

Inside NET IL Assembler
CLR Via C#: Applied .NET Framework 2.0 Programming
C# in Depth

These were coupled with tools like reflector and Microsoft Shared Source CLI on koders.com and on disk.


I've added in a commenting system via js-kit.com. It's a bit slow but works, so feel free to spam away. I'm hoping google releases Friend connect soon so I can replace the js-kit one and have a more meaningful community.

Over the coming months I'm going to write up some of my design patterns notes into articles (5 or so), something on bit shifting in c#, a small piece on friendly URL generators and a few personal projects.

New for Spring
29th March 2008

Don't worry, no more bad photos from Flickr, just an update to the site with new content. I've added five new bits and pieces:

Ascii and Unicode lookup table
A copy of the Windows charmap application in Javascript, but with HTML codes and special characters to save asciitable.com some bandwidth charges by me.

System.IO article
This is my "under the hood" look at all the classes in System.IO, along with lots of example code and reams of details about ASCII/UT8/Unicode/UT32 encoding in .NET.

XML documentation cheat sheet
Some commonly used .NET/C# XML documentation snippets if you're into that kind of thing, including a .snippet file.

.NET Regular Expression tester
A tool for testing regular expressions quickly, geared towards developers who use the .NET implementation although it should work with preg and ereg. Includes detailed error messages in the output and also does replacements.

.NET XPath tester
Another testing tool for trying out XPath queries on an XML source. Includes detailed error messages and the results syntax highlighted.

Multi-line search and replace
A very basic tool for doing quick multi-line search and replaces. I haven't found a tool that can do these yet except Dreamweaver - not Notepad++,Metapad, Visual Studio (there's a visual studio macro for doing it but I couldn't get it working).

Update: a small page to track where my email spam to this site originates from (an idea copied from the HoneyNet).

More from flickr
17th Dec 2007

At night on a beach in UAE (close to Dubai).

Photo of a United Arab Emirates beach at night

Regexs referencing strings: A leaky memory story in Statmagic
26th Nov 2007

I've been spending the last few months working on and off on a pet project I originally started writing in 2002 in PHP. I called the project Statmagic for some reason and the name has stuck. It's nothing groundbreaking just another web log file analyser. It's now in C# not PHP (and from the tests I ran could never be in PHP as its string handling was so slow). It's travelled through every version of .NET from 1.0 upwards, and is now enjoying 3.5's LINQ features with db4o, making aggregation so much simpler.

It's very close to completion now, the last few days I've been working on a memory leak that meant every single text log file it was reading was being kept in memory as a String. Not a huge problem most of the time as my intention is it'll be run daily on a small set of log files (it runs well on 360 log files, it just takes around 20 minutes per 120 files). I'm testing it with 120 files of 6mb at once and it managed to gobble up 1.2gb of memory as it kept going.

I tried out ANTS with it and narrowed it down to the fact a string was causing the problem (which I guessed was the case anyway), but couldn't find out where. I also tried out MemProfiler which gave me the answer to the lost memory but at the time I didn't realise it. So I scrapped the expensive tools and did the bodge it method of commenting out each method call until the problem was solved.

The main log reader in the application has a buffer of 16mb to read in textfiles with a StreamReader. I hadn't wrapped this in a using clause to dispose it which was adding to memory usage but wasn't the main problem.

Through trial and error I eventually found the problem was actually the logreader initialising 2 member variable Regex classes e.g. _regex1 and _regex2 in its constructor, and using them inside the main parsing method. For a reference issue which I'll admit I didn't entirely understand, these regexs were keeping hold of each 6mb log file.

My reasoning for doing this with the 2 regexes was that compiling them both once at start would speed things up. It didn't at all, and infact Regex reg = new Regex(..) created inside the method that loops through Matches, instead of using _myRegex solved the strings refusing to be GC'd. The parsing method usually goes through the entire text file, raising an event via a method called OnLineMatched each time it matches a line in the log file. So in the stack there are a lot of references being held onto via the event.

My guess would be that because the eventargs in this event was referencing a value from the regex's Match.Groups.value, it was in turn referencing the _myRegex object, which then had a reference to the 6mb string. The LogReader class itself was also not being destroyed from what I could tell.

MemProfiler was actually telling me this but I didn't realise it at the time.

Postcode/Zipcode webpage to google maps in C#
21st Nov 2007

I got my hands dirty with Google maps api for the first time yesterday. I'd used maplets but not much with the services or customising the control. I decided to write something that would take a webpage, usually some search results, grab the HTML and retrieve all postcodes (zipcodes).

From there, it plots them all onto a googlemaps control with markers. A lot of sites don't have this facility, or just show each result on a map on separate page which is why I wrote it. The api is nice and clean to use and seems to be incredibly well thought out, particularly for latency and performance. They even let you have 1 query per second which seems nice of them.

If you have a store locator or some search results with post/zip codes and want to plot them then you might want to try the example out.

The code and the example can be found here

Autumn leaves
15th Nov 2007

Something to brighten the frontpage up with, some leaves I took this morning with a Nikon D50.

 

Umbraco issues
14th Nov 2007

Being a site full of nerdy code, there's a big requirement for posting inline code. For some reason the default editor in Umbraco, Tiny MCE, strips your newlines from the pre tags when you update. I found this out when I was actually doing an Umbraco page for the site.

Anyway the short version is it's a config setting that's required in Tiny MCE - remove_linebreaks : false. Because Umbraco hardcodes its settings for Tiny MCE (except the commands and allowed tags), I had to hack the source about. The result is at (also fixes a Macro problem in firefox):

http://www.sloppycode.net/media/43259/tinymce.zip

Put that in your bin folder and no more pre problems. The umbraco page has more stuff on it.

Snipper release
6th Nov 2007

The snippet editor tool I've been working on, Snipper (as in Flipper faster than lightening) is now released on Codeplex. Grab it here.

Skype and port 19403
14th Oct 2007

Something tells me all those IPs below aren't owned by Skype. It can't help with all the echo and problems I already get with the Skypeout line.

skypeport.jpg

Site back up and running
1st Oct 2007

After 9 months of an empty holding page, the site is finally back and spreading itself around the internet again. The site was 90% converted to Umbraco back in January 2007, but then I had to put it aside to concentrate on things like truth tables, java.util, boundary errors, proof, recursion, efficiency etc. etc. It's amazing how much you can forget from 9 months without daily C# and SQL. The knowledges wasn't forgotten, it just needed a quick slap in the chops for it to re-surface again.

The site is now properly content managed instead of before when a few custom asp.net/winforms apps ran the show. No more stagnant content I hope, or glaring errors. Lots of the rubbish was removed from the site (leaving me with not much) but the ASP, FSO references are still there and still seem to be used a lot by unlucky souls doing legacy work or something.

The comment system has been removed from all the references. I added it back in 2003 to try to emulate the PHP community's comments on their docs. That failed miserably, probably from this not being an official site, with most comments being requests by people to do their code for them, people using it as a forum or non-english. There were a minority of good examples which were lost unfortunately, going through the entire FSO and ASP references to prune the comments was too much work for old technologies.

The taglines are backup again and performing quickly. They came from a lot of text files back in 2003 but haven't been tidied up much. There have been a number of sites like tagsgalore which have emerged since I made the system. I rarely use unix anymore but the unix cheat sheet is still there, if you want to add anything to it drop me an email via the contact page.

Finally, if you have any ideas why this site isn't showing at 100% in Firefox (or Safari) I would like to know. I have done plenty of 100% height sites before, with exactly the same code, but it's FF is being stubborn. I have a feeling it's the doctype which I'll experiment with, although it seems if this fixes it for FF, IE will then break.

Hope you find the site useful.

› Home
› C#
› Snippets
› Articles
› Tools
› Taglines
› ASP
› Dictionary Object
› FSO
› Unix cheat sheet
› Gaming
› CSS
› Yak
› Umbraco
› About
› Contact
› Privacy
› Projects
› Search