Things I Always Forget


Last Updated: 6/26/2012

Anonymous Delegates

    delegate(Person p1, Person p2) {
        if (p1 == null) return p2 == null ? 0 : -1;
        if (p2 == null) return 1;
        return string.Compare(p1.Name, p2.Name);

(which of course is functionally identical to the lambda syntax:
myPeopleEnumerable.Sort((p1, p2) => {...

IEnumerable / IEnumator

Allows foreach.
        public interface IEnumerable { IEnumator GetEnumerator };
        public interface IEnumerator {
            object Current {get;}
            bool MoveNext();    // We start at at index '-1', so this should be called before accessing Current for the first time
            void Reset();       // Reset index to '-1'
AsParallel(), Cast() & TypeOf() are extension methods to IEnumerable and not part of the base interface.




Last Updated: 8/16/2011


Cheat sheet:

Class name orders in HTML class attributes don't matter classes are always applied in the order they appear in the stylesheet.

Vendor Prefixes

Specify the non-vender prefix version last.

Show URLs in Print Copies

    @media print { 
        a[hred]:after { content: " ( attr(href) ) "; } 

Styles for Mobile devices

(Or other limited width devices)

    @media screen and (max-width: 480px) {



Last Updated: 8/15/2011

Horizontal <ul> & <ol>

To get horizontal ('menu' style) lists, set <li> to inline block:

li {display:inline-block}

HTML5 span does not have width

Height and width for inline elements like <span> was depreciated in HTML4 and are ignored in (standards compliant) HTML5.

Exact meaning of display style values

Stops browsers like the IPhone browser from displaying the 'whole page / zoomed out' view, and tells them to wrap to their actual width

            <meta name="viewport" content="width=device-width" />

Regular Expressions

Last Updated: 8/12/2011


By default RegEx matches are Greedy: RegEx.Match("abbcbbc","a.*c") returns "abbcbbc". Use trailing ? for non-greedy matches. i.e. RegEx.Match("abbcbbc","a.*?c") returns "abbc".

Named Groups

Named groups (RegEx.Match("The year is 2011", "a(?'year'\d{4})")) are named via a leading ? and single-quoted name.


Named groups in the match can be referenced in the replace using the ${name} syntax.  See below for example (which is code from my old site that rebased images so that Word Docs (saved as filtered HTML) could be displayed without manual editing)

Back References

Matches for a previous part of the RegEx expression can be the search can be reference in later part for the expression using the \index syntax. For example, the end of the following expression (</h\1>) looks fora closing header tag that is at the same level as the opening header tag found from the front of the expression (<h(?'level'\d))

Regex headerRegex = new Regex(@"<h(?'level'\d)(?'attr'.*?)>(?'heading'.*?)</h\1>", 
     RegexOptions.Compiled | 
     RegexOptions.IgnoreCase | 
body = imageRegex.Replace(body, "<img ${pre}src=\"Content/Notes/${source}\"${post}>");


A minus sign after the inline option(s) turns them back off (e.g. ?is-)


There are static helper methods on the C# base class now for match and for replace (i.e. don't have to new up a class instance for a one-off Regex).

Replace operations can take a MatchEvaluator instance in order to programmatically control the replacement value for each match found.

Big O

Last Updated: 2010

O(n) = upper bound version of f(n)
Ω(n) = lower bound version of f(n)
θ(n) = tight bound version of f(n) [tight bound = when lower and upper bounds are of the same magnitude, so not every function can be described this way]

"Everything is small compared with the dominant term", so O(n^^3) + O(n^^2) + O(1000n) = O(n^^3)
Multiplication is just repeated addition, so 3x O(n^^3) = O(n^^3)^^3) = O(n^^3)

n! >> 2^n >> n^3 >> n^2 >> n log n >> n >> log n >> 1

Expression (fast to slow) Typically a function of type Example in an n-element universe
O(1)Constprint n
O(lg n)LogarithmicBinary search
O(n)LinearFind max value
O(n log n)SuperlinearBubble sort
n2QuadraticLooking at pairs of elements
n3CubicLooking at triplets of elements
2nExponentialEnumerating all subsets of n elements
n!FactorialPermutations of elements


Launch Javascript Debugger Programmatically


jQuery CDN

Checkbox Indeterminate State

Indeterminate state checkbox

Can only be set via Javascript (not HTML) and is visual only (checkbox still only has two states when read)


Capture input as you type

Bind to the key up event (binding to onkeypress generates a graphical glitch on IE where the page briefly redraws (and lays out) without the linked control present when typing the first few characters).

    <h1 id="myH1">Hello</h1>
    <input type="text" onkeyup="document.getElementById('myH1').innerText = this.value;" />

float:left Column Fix

Gets me every time. By default, a normal div following a float left div wraps around the floating div (see first figure below). Setting the overflow attribute on the normal div to anything but the default of visible (e.g. to auto) prevents this wrapping and gives the desired column effect (see second figure below).

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor ...

Figure 1 - With over flow:visible (default)

Figure 2 - With overflow:auto


Last Updated: 2010


Common Terms


Troublesome Acronyms

Last Updated: 8/16/2011


Last Updated: 6/26/2012





x = l * cosine a
y = l * sine a