ConcurrentDictionary.GetOrAdd() facts

In any combination of any number of threads running for any values with the same key:

  • It is guaranteed that only one item will be added
    • and this will be the only call to which true is returned.
  • It is not guaranteed that the delegate overload will only execute the delegate once
    • because the class uses optimistic concurrency control.
    • The implicit assumption is that it’s rare for multiple concurrent calls to occur in reality, so more efficient to compute anyway, then replace or throw away as appropriate.
    • If the delegate is expensive or has unwanted side effects, a Lazy<> can be used instead.



Enable MySQL server query logging

  1. View current state of variables:
    SHOW VARIABLES LIKE "general_log%";
  2. Set log location:
    SET GLOBAL general_log_file = 'C:/Temp/QueryLog.log';
  3. Enable logging:
    SET GLOBAL general_log = 'ON';
  4. Disable logging again (for improved database performance and disk usage):
    SET GLOBAL general_log = 'OFF';

Python’s enumerate

enumerate(sequence, start=0)
  • Takes as input a sequence (string, unicode string, list, tuple, bytearray, buffer or xrange) or iterable, and an arbitrary start index
  • Returns an iterator which provides tuples containing the count and value
  • Useful to generate the index corresponding to each element:
for i, animal in enumerate(["cat", "dog", "mouse"], 1):
    print("Animal #{} is a {}".format(i, animal))
PEP 279 — The enumerate() built-in function
enumerate(sequence, start=0)

User Control vs Custom Control

Custom Control

  • Extends or creates an entirely custom, usually complex, control
  • Derives from Control or any of its subclasses
  • Usually has a pluggable interface
  • Usually defined in C# with a style inside the theme resource dictionary
  • Includes implementation and usually default template interface and style, but expected to be changed/skinned on by consumer

 User Control

CSS Positioning


  • Doesn’t participate in document flow (0 height, 0 width)
  • Fixed position on screen, even after scrolling
  • Actually a special case of absolute, but relative to the viewport


  • Doesn’t participate in document flow (0 height, 0 width)
  • Fixed position on initial screen layout, can be scrolled away
  • Will be relative to the closest parent who has a position of absolute, fixed or relative (or the window if none)


  • Maintains height and width in original position
  • Positioned according to itself (e.g. top: 10px is 10px from the top of the original position, not the container)


  • Default behaviour of elements
  • Laid out according to normal flow (i.e. “not positioned”)
  • Position properties (top, bottom, left, right) don’t have any effect


  • Inherits positioning from its (direct) parent element

Javascript Object Literal

  • Comma separated list of name-value pairs surrounded by curly braces
  • Encapsulates data in an object
var person = {
    name : "Jim", 
    age: 100
  • Can contain array literals, functions or nested object literals
  • Empty objects can also be created with
var empty = { };

which is identical to var empty = new Object()

  • Usually accessed using dot notation (, but can also be accessed with bracket notation (person[‘name’])
  • Bracket notation must be used to accessfor non-standard identifier names (e.g. ‘!’, ‘’)

Static vs dynamic resources


  • Always loaded on window/page load (even if not used)
  • Only ever loaded once
  • No forward referencing – must be declared above where it is used


  • Not loaded on window/page load (can improve start up time)
  • Reloaded each time the resource is changed (overhead to watch for changes)
  • Can only be used to set dependency properties