Author Archives: Jerome

About Jerome

I am a senior C# developer in Johannesburg, South Africa. I am also a recovering addict, who spent nearly eight years using methamphetamine. I write on my recovery blog about my lessons learned and sometimes give advice to others who have made similar mistakes, often from my viewpoint as an atheist, and I also write some C# programming articles on my programming blog.

Sample code to send email via gmail in c#

For some time, I’ve had a block of code that I copied and pasted all over the place, to send emails via gmail. It didn’t add an attachment, but I needed to do so today. So rather than copy and … Continue reading

Posted in Programming | Tagged , | Leave a comment

Beware of calling Contains in the Where predicate on IQueryable<T> in LINQ to SQL if your collection has more than 2100 items

Recently I ran into a problem I’d never seen before – the 2100 parameter limit in the SQL that’s generated when you call Contains in the IQueryable<T>.Where predicate in LINQ to SQL. To make matters worse, this happened when filtering … Continue reading

Posted in Programming | Tagged , | Leave a comment

How to load a cursor from embedded resources in C#

Last night, being the last night my son was staying with his cousins, I was bored and spent some time looking at some old code. I don’t know if anyone else still uses Windows Forms applications, but in case you … Continue reading

Posted in Programming | Tagged , , | Leave a comment

A pet hate and anti-pattern: A method returning a bool that can never return false, but can throw an Exception.

Recently I came across some code that, while syntactically correct, does something that always gets to me. Let’s illustrate it with an example: using System; namespace Example { public class AntiPatterns { public bool NeverReturnsFalse() { try { // Do … Continue reading

Posted in Programming | Tagged | Leave a comment

Beware of WCF POST service methods that receive JSON that contain DateTime values

I ran into a weird problem today… I have a third party that returns some data to our endpoint in JSON format. I created my endpoint, posted JSON to it, and all seemed well. But when the third party posted … Continue reading

Posted in Programming | Tagged , , , | Leave a comment

T-SQL to get the counts of records within age ranges

This post is written just in case future me has to do this again… I was emailed a spread sheet containing thousands of birth dates by my boss, and asked to return a segregation based on the number of them … Continue reading

Posted in Database | Tagged | Leave a comment

How to convert a string to ASCII in c#

This is one of those cases where smart-ass developers will tell you that you should not be converting strings to ASCII, because reasons… However, if you’re sending a file to a host-to-host banking system, or sending text to an external … Continue reading

Posted in General, Programming | Tagged | Leave a comment

How to save a simple tabular Excel file from C# using EPPlus

An application I wrote was exporting a couple of different sets of objects as CSV files, but the people using it wanted Excel files. Although Microsoft designed C# and everybody involved assumed that such formats are native to dot Net, … Continue reading

Posted in Export XLSX file | Tagged | Leave a comment

A SQL helper class that allows executing a query or running a stored procedure, with or without dynamic parameters

A while back I wrote about my extension method to copy a non-generic collection to an array. A commenter pointed out that it isn’t really necessary. Oh well… here is some code that uses it… (If you use this code, … Continue reading

Posted in Database, SQL | Tagged , | 1 Comment

Who else modified QBASIC’s NIBBLES to run on Windows 95?

I just read a blog post by Raymond Chen. It’s a  historical post about getting an old MS-DOS game to run on Windows 95… But what really got my attention was one of the comments, where the commenter mentioned a … Continue reading

Posted in General | Tagged | Leave a comment

I hate SQL. One way of doing a subquery in a JOIN statement

I really do. I’m writing this mostly for myself because I never remember this shit. I wrote this query  now but I know that I won’t remember how to do this in future, so here is the public note to … Continue reading

Posted in Database, SQL | Tagged | 1 Comment

When cleanup fails and tells me that I need to run cleanup

Huh? Normally I wouldn’t write a post like this because I don’t have a solution. But this one is just too funny in its own stupid way. Yesterday I needed to commit a simple change to a project, and we … Continue reading

Posted in Programming, Work | Tagged | Leave a comment

Convert a non-generic collection to an array – my most useful extension method ever…

Funny how things work out… I wrote one of my most simple extension methods years ago, one that converts a non-generic collection to an array (because arrays implement IEnumerable<T> on which I can call Linq extension methods). Lately I find … Continue reading

Posted in Programming | Tagged , , | 2 Comments

How to get the row index in the client side code of a DataItemTemplate in an ASPxGridView column

This was pissing me off for far too long today. I also have a DataItemTemplate with an ASPxHyperlink control in one of my columns of an ASPxGridView. When the user clicks the hyperlink, I need to call a JavaScript function … Continue reading

Posted in Programming | Tagged , , , | 2 Comments

How to insert multiple literals explicitly into a table, only if they don’t already exist

It might seem silly, but recently I needed to insert some values into a new table I added to a system, but only if those values didn’t already exist, and I did not know how. (Yes, it’s a new table … Continue reading

Posted in SQL | Tagged , | Leave a comment

How to add to the Windows recent documents in C#

I realize that I haven’t written anything here for ages… so I looked through my old code for something simple but useful, and found this. If ever you need to add a file to the Windows recent document list, this … Continue reading

Posted in Programming | Tagged , | Leave a comment

Spammers need better targeting algorithms

I don’t check this blog’s stats much; my other blog is the one I focus more on these days. Since I just published something here, I decided to clean up the spam. Why would you auto-spam a programming blog, in … Continue reading

Posted in General | Tagged | 2 Comments

How to ensure that a number is always round up to the nearest integer

Yes, this is silly. I never used Math.Ceiling before; so I never even knew what it was for. In my use case, I’m sending SMS messages via a third party WCF service. It works well, but in my own WCF … Continue reading

Posted in Programming | Tagged , | Leave a comment

Mailto links with subject and body

This is most probably not news to anybody besides myself, but regardless, I didn’t know that you can create email links including both the subject and body… I was writing something on my other blog and needed to include some … Continue reading

Posted in HTML | Tagged | Leave a comment

How to convert Unicode text to plain ASCII

Let’s say you have a string that was input by somebody out of your control… Maybe it got to you via a call to your web service from a remote client, indirectly via somebody else’s software. And you need to … Continue reading

Posted in Programming | Tagged , | Leave a comment

A minor pet peeve: “Send us the XML!”

I still haven’t gotten around to writing my pet peeves post, but in the meantime, here’s a really short one… A single, work-related pet peeve. Send us the XML so that we can try to find the problem! This has … Continue reading

Posted in Uncategorized | Tagged | Leave a comment

How to encode or decode a base64 string

This is an absolutely trivial programming task, but one that annoyed me enough to have to write some code to do… I use Filezilla for FTP uploads/downloads at work, but never remember my passwords for FTP sites. Nor do I … Continue reading

Posted in Programming | Tagged | Leave a comment

The curious case of the generic complimentary comment. I hate SPAM!

I published this on my other blog yesterday. But it is related to programming in a way, so now it’s published here too. Recently I received this comment to one of my posts: Hello! I’ve been reading your site for … Continue reading

Posted in Programming | Tagged | Leave a comment

Experimental new C++ operator joke

This is fucking hilarious… Raymond Chen introduced some “new C++ tadpole operators” on his blog. It’s a joke, one that I didn’t get immediately, but what makes it even funnier is that many commenters also didn’t get it. They’re upset … Continue reading

Posted in Programming | Tagged , | Leave a comment

Do NOT cache SSL certificates on the client side – How to post XML asynchronously and read the response using HttpClient in c#

I had one hell of a day yesterday. The evening before, I’d renewed the certificate on a WCF service of ours, because the old one was about to expire. After renewing it, I tested the service to confirm that I … Continue reading

Posted in Programming | Tagged , , , , | Leave a comment

Link to: Emulating double dispatch with c#

“Link to” in the title indicates that I am writing about something that somebody else wrote, somebody a lot smarter than myself. Eric Lippert wrote a great post on emulating double dispatch in c#. Actually this is part 3 of … Continue reading

Posted in Programming | Tagged | Leave a comment

My recovery blog is no longer accessible to the public, and never will be again

My recovery blog is no longer going to be publically accessible. I will eventually delete it, but need to retrieve the data from it first. I will be starting another blog, with a somewhat different focus: On recovery, atheism and … Continue reading

Posted in Uncategorized | Tagged | Leave a comment

I hate you, Windows Update!

I have a deadline today, and as of last night, this computer froze midway when rebooting after a Windows Update. Now my SQL Server doesn’t start any more. This error is in the event log: Cannot recover the master database. … Continue reading

Posted in Work | Tagged | Leave a comment

Failed to establish a backside connection

We get this error occasionally when using a bank’s web service for AVS-R. (Real-time bank account validation.) Maybe I’m weird but I laugh every time I see that error. I read it as “Cannot find anus.”

Posted in Programming, Work | Tagged | Leave a comment

Two ways to change the default backup directory for SQL Server

This has driven me nuts for years. I always change the default data directory in SQL Server Management Studio. That’s easy to do and the feature to do so is easily discoverable. Just right-click the server instance in the Object … Continue reading

Posted in Database, Work | Tagged , | Leave a comment

Zipping a directory and including relative directory paths is non-intuitive with DotNetZip

I recently had to write some code to auto-update an application via an FTP server. It uses home-grown code since ClickOnce is too limiting, and is written in a Windows Forms .NET 3.5 Visual Studio 2010 project. It also had … Continue reading

Posted in Programming | Tagged , | Leave a comment

How to implement IDisposable properly

Every so often I write a class with disposable members, so it needs to implement IDisposable. I always copy and paste from one of my other classes, so I figured it would be useful to share the pattern of IDisposable … Continue reading

Posted in Programming | Tagged , | Leave a comment

SA Mobile Drug Testing… Located somewhere in the tropical Atlantic ocean off the Gulf of Guinea?

This is what happens when you let clueless developers build a website… I was searching for local drug testing options when I found this… Surprising that their top two results for drug testing in Johannesburg are in Cape Town and … Continue reading

Posted in Programming | Tagged | Leave a comment

So funny: I never thought of Bobby Tables this way

I just found this in a comment to Raymond Chen’s latest blog post. I hadn’t seen it before and it’s too funny not to share.

Posted in Programming | Tagged | Leave a comment

A pattern for implementing the == operator in C#

I’ve been neglecting this blog for a while because I have very little time to write here… Every now and then I need to implement the == operator on one of my classes; typically because I want to compare two … Continue reading

Posted in Programming | Tagged , , | Leave a comment

Stupid Firefox is pissing me off

Every time I navigate to any page that uses flash (on either my home or work computer thanks to Firefox sync) I get this: So I went to look at my plugins. I get this: OK, so click the Update … Continue reading

Posted in Uncategorized | Tagged , | Leave a comment

A nice way of handling timesheets

I mentioned a while back that I have started using Toggl for my time sheets… What I did this month, which was the first month I sent the Toggl-based report to my boss, was export a detailed report, then remove … Continue reading

Posted in Programming, Work | Tagged , , | Leave a comment

An asynchronous implementation of File.WriteAllLines

This is an example that (optionally) uses an extension method I wrote about back in April 2013. See the original post here. Last time around the post was about the caveats involved when working with streams. This time, I’m going … Continue reading

Posted in Programming | Tagged | Leave a comment

Feeling like an imposter again

Sheesh… I read a few programming blogs, but one of them always ends up making me feel really stupid. Eric Lippert, I hate you! … OK, maybe I don’t, but the guy writes the most beautiful, concise code I have … Continue reading

Posted in General, Programming | Tagged | Leave a comment

Thank you, Word auto recovery. Gosh, which one shall I use?

Perplexing… My notebook crashed on Friday, and I just returned to this Word document now. Word conveniently saved two versions of the document for me, including the original draft, apparently written some 370 years before I was born, and 51 … Continue reading

Posted in General, Programming | Tagged , | Leave a comment

I finally found a good timesheet system

Not that I ever looked for one before, but never mind. One thing I have never been able to get right is timesheets. Never. This has caused some problems for me at work… Lately I have to submit my timesheets … Continue reading

Posted in Work | Tagged | Leave a comment

Memory gates checking failed because the free memory (n bytes) is less than 5% of total memory.

Ever had this horrendous error? WebHost failed to process a request. Sender Information: System.ServiceModel.ServiceHostingEnvironment+HostingManager/45653674 Exception: System.ServiceModel.ServiceActivationException: The service ‘/YourServiceName.svc’ cannot be activated due to an exception during compilation. The exception message is: Memory gates checking failed because the free memory … Continue reading

Posted in Programming, Work | Tagged , , | Leave a comment

How to force (hack?) kendo-ui grid to display the correct date

We have some grids displaying the data from SQL queries, including dates. But for whatever reason, the time zone is being applied to the date twice. For example, the date is today, at 12PM, and we are using GMT-2, here … Continue reading

Posted in Programming | Tagged , | 5 Comments

Bootstrap’s modal jQuery dialog doesn’t have to be dismissed when the user clicks elsewhere

We have a Node server running, developed using the express framework and a few other components, all new to me. I’m no Node expert… actually I hate it, and estimate it takes me more than five times longer to develop … Continue reading

Posted in Programming | Tagged , | Leave a comment

A simple c# ASP.Net Pin-pad user control

This is just a work-in-progress, but it does the job, and should be enough to get you started on adding a PIN option to your web site. It’s inspired by this entry on StackOverflow. The concept is: Besides your normal … Continue reading

Posted in Programming | Tagged | Leave a comment

Turning off those stupid Windows Live Calendar notifications

I’ve got to admit, for a computer programmer, it is pretty dumb that I didn’t know this, but I see I was not alone… What I’m talking about is those annoying birthday reminders that have been driving me nuts for … Continue reading

Posted in General | Tagged | Leave a comment

Idiots should never troubleshoot anything

A few days ago, my Firefox browser at work started some annoying behaviour… It seemingly randomly gave me “The connection was reset” error messages. So I did the natural thing… instead of thinking about it, I Googled the error to … Continue reading

Posted in General | Tagged , | Leave a comment

How to call HttpClient.PostAsync with a query string

This has to be one of the most non-discoverable APIs ever, and annoyed the hell out of me earler today. Hence my posting it here so that others may not have to struggle over something so trivial. All I want … Continue reading

Posted in Programming | Tagged | 7 Comments

Dumb searches: EnumWindowProc eats CPU

I normally don’t do these types of post on this blog. I assume the searcher arrived here because of this post where I called that API function years ago… Well well… You are enumerating all the Windows on the machine … Continue reading

Posted in Programming | Tagged | Leave a comment

1366×768 is not a resolution you should be using (or targeting), and some ASPxDashboadViewer hackery

Just a rant today… My screen resolution on my work laptop is 1920×1080, but my boss uses 1366×768. That’s a crap resolution. Since he demos the web applications we work on, on his machine, that frequently means that we have … Continue reading

Posted in General, Programming, Work | Tagged , | Leave a comment