While redoing my social follow icons I realised that there didn't seem to be any SVG version of the Stack Overflow logo on the internet. So naturally I went and put one together! I hope it's useful.
Check out the deleted questions on Stack Overflow
There are a lot of questions on Stack Overflow, probably a lot than you realise. This is understandable when you consider over 7,000 questions are being asked every day. No I'm not just talking about the 5 million odd that you can access via the questions tab (4,930,418 and counting at time of writing). There are also a ridiculous amount of deleted questions which only users with at least 10,000 reputation can see.
Most of the deleted questions are just plain awful questions that don't belong on the site. A good number of them however were deleted not because they were particularly poor quality or bad questions, but because they were off-topic and don't really belong on Stack Overflow, they also may have been too old to migrate to a site like Programmers.
Greg Hewgill created a list of old deleted questions ranked by votes, being outside Stack Overflow so people who don't have the reputation can check them out. A lot of them are great demonstrations of what not to ask on Stack Overflow now that the rules are much more rigorously defined on what is on-topic. They are a lot of fun though :) check out the list here.
Aligning and element with background-size:cover
The CSS property background-size:cover is incredibly useful but due to the nature of it resizing in different directions, it's difficult to pinpoint where a particular part of the image is on the background at any given time. Difficult but not impossible of course.
To do this you first need to understand how background-size:cover works. Basically the image will fill the screen at all times by stretching out while maintaining aspect ratio. This means that unless the window is perfectly sized to fit the image, either the image is going to be cut off at the top and bottom edges, or the left and right edges.
Given this we can calculate the scale of the image and the x or y offset to find out the actual coordinates of the target location. I've created a little example using Google's logo that positions a red dot inside the red 'o' character. Resizing the window will keep the red dot inside the 'o' no matter how you resize the window.
sticky-header.js
I wrote up a little JavaScript plugin over the weekend that has a <table>'s header scroll with the page. What sparked this little endeavour was a question asking for this functionality on Stack Overflow. Since it was fun answering the question, I thought I'd go ahead and make a more general plugin type solution that worked for multiple tables.
Similar to my sortable-table.js plugin, simply add the sticky-header class to a <table> and the functionality will be enabled.
<table class="sticky-header"> .... </table>
I've tested it in all the latest browsers and seems to work fine; Chrome, Firefox, Safari, Opera, IE10, IE9 and IE8. No IE7 because it doesn't implement querySelectorAll, the code would be a bit more icky if I used some other method, and you know, it's IE7.
Here is a demonstration on GitHub HTML preview, and be sure to check it out on GitHub!
Use Symbol Hound to search for symbols

I stumbled upon this little gem, a search engine called Symbol Hound that unlike Google, doesn't ignore symbols in fast it is actually optimised for searching with them. It only searches within Stack Overflow but that means it's very focused on programming and really if you're not finding your answer to a programming operator question on SO, it deserves to be asked.
For a long time now I've searched Google using quotes around the term for things like C# "+= operator" hoping that it would work this time. Finally searching for symbols should be a breeze :)
Converting a string to the 'best-fitting' type
I answered a pretty interesting question on Stack Overflow yesterday, creating a method that takes a string and returns the value converted to the 'best-fitting' type out of a set of types boxed in dynamic. Here is the full question:
I have been playing around with converting a string to a value type in .NET, where the resulting value type is unknown. The problem I have encountered in my code is that I need a method which accepts a string, and uses a "best fit" approach to populate the resulting value type. Should the mechanism not find a suitable match, the string is returned.
This is what I have come up with:
public static dynamic ConvertToType(string value) { Type[] types = new Type[] { typeof(System.SByte), typeof(System.Byte), typeof(System.Int16), typeof(System.UInt16), typeof(System.Int32), typeof(System.UInt32), typeof(System.Int64), typeof(System.UInt64), typeof(System.Single), typeof(System.Double), typeof(System.Decimal), typeof(System.DateTime), typeof(System.Guid) }; foreach (Type type in types) { try { return Convert.ChangeType(value, type); } catch (Exception) { continue; } } return value; }I feel that this approach is probably not best practice because it can only match against the predefined types.
Usually I have found that .NET accommodates this functionality in a better way than my implementation, so my question is: are there any better approaches to this problem and/or is this functionality implemented better in .NET?
Polymorphism, methods, interfaces and concrete types
I answered a question on Stack Overflow a couple of days ago and it sparked memories of several years ago when I was new to the industry. Something that confused me a little when starting out was around the use of interfaces. All of a sudden they started popping up in mass quantity as I started working on projects of significant size.
I wish someone had explained this to me back then. When deciding the parameters and return types of your methods, the parameters should be as abstract as possible and your return type should be as concrete as possible. The reason for this is to enable the most flexibility in your application.
Consider the example given in the SO question,
Why does
IEnumerablereturn.ToList<T>() List<T>instead ofIList<T>?
Returning a concrete List<T> that implements IList<T> only gives the method consumer more information. Given the definition of of List<T>
[SerializableAttribute] public class List<T> : IList<T>, ICollection<T>,
IList, ICollection, IReadOnlyList<T>, IReadOnlyCollection<T>,
IEnumerable<T>, IEnumerableReturning as a List<T> gives us the ability to call members on all of these interfaces in addition to on List<T> itself. For example we could only use List.BinarySearch(T) on a List<T>, as it exists in List<T> but not in IList<T>.
Likewise with parameters, the more abstract they are the more types can be passed in. If we only need to look through a collection of data in no particular order we should use the IEnumerable<T> as the parameter type instead of a regular List<T> This allows much more flexibility when consuming the method, we could pass in a List<T> or a SortedSet<T> or a HashSet<T> etc. as they all implement the IEnumerable<T> interface.
In general to maximize the flexibility of our methods, we should take the most abstract types as parameters (only the things we're going to use) and return the least abstract type possible (to allow a more functional return object).