title: Algorithm / pseudo-code to create paging links?
body: <p>Can someome provide code or pseudo-code for how the paging links on StackOverflow are generated?</p>
  
  <p>I keep racking my brain but can't think of a decent way to build the dynamic links that always show the 2 pages around the current, plus the first and last.</p>
  
  <p>Example: <code>1 ... 5 6 7 ... 593</code></p>