This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * (If a number is used, it must be > -1!) | |
| */ | |
| type DSNode = number | string; | |
| class DisjointSet { | |
| protected readonly parents: Map<DSNode, DSNode | number> = new Map(); | |
| protected count = 0; | |
| protected findRoot(node: DSNode): DSNode { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // ### How to Handle Timezones Correctly! ### | |
| // Time is a presentation issue. Always store date/time as UTC, then convert it | |
| // to the user's timezone post retrieval and prior to output. | |
| // | |
| // Take a calendar application, for example. If Bob wants to play video games at | |
| // 13:00 on 2011/09/01 and Bob lives in London, which would be in BST (UTC+1), | |
| // then this should be saved in UTC (i.e. less an hour). Then, if Jerry lives in | |
| // New York and wants to play the same game with Bob at the same time, the date | |
| // would be retrieved from the database and converted to Jerry's timezone, which |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * @author Sam Christy <sam_christy@hotmail.co.uk> | |
| * @licence GNU GPL | |
| */ | |
| var cs1 = { | |
| r : Math.floor(Math.random() * 256), | |
| g : Math.floor(Math.random() * 256), | |
| b : Math.floor(Math.random() * 256) | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function shuffle(a){ | |
| var j, temp; | |
| for(i = a.length-1; i > 1; i--){ | |
| j = Math.floor(Math.random() * (i + 1)); | |
| temp = a[i]; | |
| a[i] = a[j]; | |
| a[j] = temp; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Array.prototype.unique = function(){ | |
| var map = {}; | |
| for(var i = 0; i < this.length; i++) | |
| map[this[i]] = this[i]; | |
| this.length = 0; | |
| for(var key in map) | |
| this.push(map[key]); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Searches the specified range of a sorted array for a given value; if the | |
| * wanted value is found, its index is returned. -1 is returned if the item | |
| * is not found. If no range is specified, the entire array will be searched. | |
| * Please note: the array that this method is invoked on must be sorted in | |
| * ascending order! | |
| * @param {int|float|string} wanted The value to be searched for. | |
| * @param {int} [first] The start of the search range. | |
| * @param {int} [last] The end of the search range. | |
| * @return {int} The index of the element if found, otherwise -1. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ///////////////////////////////////////////////////////////////////////// | |
| /// Title: Stopwatch Class | |
| /// Author: Sam Christy | |
| /// Date: 26/11/2011 | |
| /// Licence: GNU GPL | |
| /// | |
| /// This class is a simple, high-resolution stopwatch for timing the | |
| /// execution of C++ programs in a Windows eviroment. This class | |
| /// emulates the Stopwatch class of the .NET framework and uses the | |
| /// Windows API to time events. Its precision is much greater than any |