Date range in date range

Having spent my fair share of time mucking around with … well, time…I can tell you that I’d prefer to let someone else do the work for me. To that end, if you’re will to give it a go, I’d take a look at JodaTime Basically, what this example does it creates a series of … Read more

Creating a collapsed range from a pixel position in FF/Webkit

Here is my implementation of caretRangeFromPoint for old browsers: if (!document.caretRangeFromPoint) { document.caretRangeFromPoint = function(x, y) { var log = “”; function inRect(x, y, rect) { return x >= rect.left && x <= rect.right && y >= rect.top && y <= rect.bottom; } function inObject(x, y, object) { var rects = object.getClientRects(); for (var i … Read more

Only index needed: enumerate or (x)range?

I would use enumerate as it’s more generic – eg it will work on iterables and sequences, and the overhead for just returning a reference to an object isn’t that big a deal – while xrange(len(something)) although (to me) more easily readable as your intent – will break on objects with no support for len…

How to create range in Swift?

Updated for Swift 4 Swift ranges are more complex than NSRange, and they didn’t get any easier in Swift 3. If you want to try to understand the reasoning behind some of this complexity, read this and this. I’ll just show you how to create them and when you might use them. Closed Ranges: a…b … Read more