Developers

Git Workflow: Branch - Rebase - Squash - Merge

So you want to make a change to your git repo while other people may also be simultaneously working on the same repo. As it takes you longer to make your changes, there is a greater chance that your local repo might already be out of date as other people have pushed their changes. In this setting, you don’t want to make your changes directly in master because otherwise you might end up creating large merge commits which makes your repo’s history convoluted and not very nice.

How to Enable and Use GCC Strict Mode Compilation

One of the great feature that many C++ programmers rarely use is GCC strict mode compilation. Enabling this lets compiler warn you about any potential issues that might often get unnoticed in build noise. Unfortunately there is little documentation, let alone quick tutorial on this subject so I thought to write this up. First, let’s clear this up: There is no official GCC mode called “strict”. I just made that term up.

Downloading All of Hacker News Posts and Comments

Introduction There are two files that contains all stories and comments posted at Hacker News from its start in 2006 to May 29, 2014 (exact dates are below). This was downloaded using simple program available I wrote Hacker News Downloader by making REST API calls to HN’s official APIs. The program used API parameters to paginate through created date of items to retrieve all posts and comments. The file contains entire sequence of JSON responses exactly as returned by API call in JSON array.

BadImageFormatException - This assembly is built by a runtime newer than the currently loaded

Strange thing happened today. I upgraded one of the internal tool to .Net 4.0 without any issues but as soon as I attempt to debug/run the binary, I’ll see this exception: System.BadImageFormatException was unhandled Message: Could not load file or assembly SomeTool.exe' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded. Normally you see this exception if the machine doesn’t have right run time installed.

A Day in SQL Tuning

Today I got in to some heavy weight TSQL tuning. This time the target was a legendary sproc that was taking 3 mins and now I’m about to call it a day when this giant SP is eating only 16 sec. Not excellent but not bad at this point. Here are some notes… Apparently resetting identity using DBCC CHECKIDENT can be expensive operation if you are also deleting all items from the table.

Test Results Windows and Exception has been thrown by the target of an invocation

Just a note… if you are getting “Exception has been thrown by the target of an invocation” message when opening Test Results window in Visual Studio 2008 then it’s most likely because you have an open solution in offline mode that was bound to some TFS instance. A bug that can waste lots of your time if you didn’t knew about it!

What to do on dreaded error CS0003: Out of memory

I’ve spent way too much of time today (again!) on this error so here’s blog post for future reminder to me! If you are generating or working with very large proxies then you might see following error: Exception: InvalidOperationException<br Message: Unable to generate a temporary class (result=1). error CS0001: Internal compiler error (0xc00000fd) error CS0003: Out of memory This error typically occurs when .Net infrastructure attempts to generate *XmlSerializers.dll on the fly.

Silencing Exceptions in a Little Better Way

Some of the most disastrous code usually takes the following form try { //some code } catch { } Silencing exceptions is almost never good but sometime the problem is minor and you don’t want want to blow up and call for an exit. However wouldn’t it be better if exceptions don’t remain silent and scream for your attention when you are debugging and behave less aggressively otherwise? How about if we can replace above code with following:

Lightweight DataTable Serialization

We all know untyped data structures like DataTable and DataSet should not be passed around but sometimes - just sometimes - you got to do it because it makes sense and because it’s the most cost effective way to meet your goals. However passing things like DataTable over WCF can kill performance because of huge serialization overhead in both space and time. So if you really had to go ahead with this crazy idea of sending DataTable over WCF then here’s the somewhat more efficient serialization technique you can use.

The Best Culture Invariant Format for DateTime

If you are looking to display how to display DateTime as text without causing confusion to users in different countries then good choices is either “o” or “r”. The “o” format is in general more preferable as it also puts timezone offset. long t = DateTime.Now.Ticks; Console.WriteLine((new DateTime(t)).ToString("o")); Console.WriteLine((new DateTime(t, DateTimeKind.Local)).ToString("o")); Console.WriteLine((new DateTime(t, DateTimeKind.Unspecified)).ToString("o")); Console.WriteLine((new DateTime(t, DateTimeKind.Utc)).ToString("o")); Prints followings when actual date time is 2009-11-08T17:16:13.7791953 PST: 2009-11-08T17:16:13.7791953 2009-11-08T17:16:13.7791953-08:00 2009-11-08T17:16:13.7791953 2009-11-08T17:16:13.

Find Path of a Command Line Tool

Many times you work on different machines, execute a command line tool but often wonder where that tool is actually installed. One way to figure this out is to look at all environment PATH variables and search them manually in same order as Windows does. But you don’t have to because luckily there is a little known built-in command called WHERE that does that for you: This is similar to Unix commands like WHICH and WHEREIS.

Selecting Random Row From SQL Server Table

It is important to make sure your automated tests covers various real-world data combinations (for instance, some columns could be null or some rows could be duplicate). For perf testing you want to reduce effects of caching by not firing same SQL over and over. In these cases, ability to select a random row for your test could come in handy and here’s neat little trick to do it: select top 1 * from table order by newid()

What’s in a name?

When you want to store the name of a person a typical design starts out by creating two fields (in database or class): Person First Name Last Name Soon you realize lot of people have middle name, especially, when name change occurs after marriages. So you go and add one more field: Person First Name Middle Name Last Name This is all good… until you encounter people in countries such as Spain and Cuba who have custom to have two last names.

Twitter Dishing Out 417 - Expectation Failed to .Net Clients

My little Twitter app was broke since past few days with error 417 - Expectation Failed. Infect most .Net apps calling Twitter APIs would be broken right now so I thought to write this up. This error is seemingly because Twitter servers have started rejecting Expect HTTP header with value “!00-Continue”. I’m not sure if this was planned event or enough warnings were issued to developers but it would be guaranteed to drive you nuts.

Why would you still get "Strong name validation failed"?

There are not many web pages mentioning this so I would just post this so it comes up in search. Having personally spent 4 hours tracking this little thing down, I would want anyone else to go through same :). So… if you are using delay signing, you will need to run the following command so you can still debug from Visual Studio.Net: sn -Vr *,[public key token] Apparently if you are using Vista 64-bit it just won’t work!

The ACM Turing Programming Contest Problem Set Archive

Here’s the list of problems used in ACM Turing programming contest. Surprisingly, like many other such contests, lots of problems are s simply a variant of shortest-path problem. The ACM ICPC Problem Set Archive

Exception Code Template For CodeRush

How CodeRush could miss this template? Anyway you can copy and paste this in CodeRush Options (Expert mode) to have your own! [System.Serializable] public class InvalidDataException { public InvalidDataException() { } public InvalidDataException(string message) : base( message ) { } public InvalidDataException (string message, System.Exception inner): base( message, inner ) { } public InvalidDataException (System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) : base(info, context) { } }

My New CodeProject Article On Equation Rendering

I just finished my new article on CodeProject. The mission on MimeTeX was started about couple of months ago when in a weekend I just got attracted to MimeTeX’s C code like a magnet ;). Now I’ve built ASP.Net handler, caching, admin etc on the top of it and its looking great! Enabling scientific content on web seems to be my new obsession. So if you take pride in delighting your users with every new release, here’s your brand new feature!

Interesting Headers

The response headers returns with Google’s logo looks like this: Content-Type: image/gif Last-Modified: Mon, 25 Apr 2005 21:06:18 GMT Expires: Sun, 17 Jan 2038 19:14:07 GMT Server: GWS/2.1 Content-Length: 8558 Date: Sat, 16 Jul 2005 01:52:05 GMT And for some gif served by IIS on Win 2003 Server looks like this: Server: Microsoft-IIS/5.0 X-Powered-By: ASP.NET Date: Sat, 16 Jul 2005 02:08:59 GMT Content-Type: image/gif Accept-Ranges: bytes Last-Modified: Fri, 04 Mar 2005 09:12:29 GMT Etag: "

Types Of Database Columns

From an excellent article on Decimal mentions survey of 1,091,916 columns in databases owned by 41 organizations to find that 41.8% of them contained numeric data and 53.7% contained char data.