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
var eventTargetObjects = Object.getOwnPropertyNames(window).filter(function prop(name) { | |
// This block of code identifies constructors with high confidence using casing, enumerability and prototype property presence | |
return (name[0] === name[0].toUpperCase() && !this.propertyIsEnumerable(name) && this[name].prototype !== undefined); | |
}, window).filter(function prop(name) { | |
// This block of code determines if a constructor is like an EventTarget | |
var currentPrototype = this[name].prototype; | |
while (currentPrototype !== null) { | |
if (currentPrototype === EventTarget.prototype) { | |
return true; | |
} |
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
bool PowerOf2(unsigned long value) | |
{ | |
return (value != 0) && !(value & (value-1)); | |
} | |
int BitCount(unsigned long value) | |
{ | |
value = (value & 0x55555555) + ((value & 0xAAAAAAAA) >> 1); | |
value = (value & 0x33333333) + ((value & 0xCCCCCCCC) >> 2); | |
value = (value & 0x0F0F0F0F) + ((value & 0xF0F0F0F0) >> 4); |
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
double ChampagneTower(double water, double capacity, int row, int col); | |
double ChampagneTower(double water, double capacity, int cup) | |
{ | |
// The cup id is from left to right. We want the row and column in the triangular | |
// array which is basically the triangular root and our remainder. | |
int triangular_root = ceil((sqrt(8*cup+1)-1)/2); | |
int column = cup - ((triangular_root*(triangular_root-1))/2); | |
return ChampagneTower(water, capacity, triangular_root, column); | |
} |
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
// Assumes row/col are 1 indexed | |
int PascalsMath(int row, int col) | |
{ | |
// Enable mirroring about the central pivot of the row | |
col = min(col, row - col + 1); | |
int value = 1; | |
int numerator = row - 1; | |
int denominator = 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
// RangeBasedFor.cpp : Defines the entry point for the console application. | |
// | |
#include "stdafx.h" | |
template <typename T, T first = T::First, T last = T::Last> | |
class Enum | |
{ | |
static_assert(first <= last, "foo"); | |
public: |
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
// Utilize visibility. This will cause layout to be invalid and have to be recomputed once the element is made visible again. | |
function _clickThroughVisNested(evt) { | |
var localStyle = evt.target.style; | |
var oldVisibility = localStyle.display; | |
localStyle.visibility = "hidden"; | |
var target = document.elementFromPoint(evt.pageX, evt.pageY); | |
// Specific to my implementation. I want to only click through on certain types of elements. | |
if (target.classList.contains("achievement")) { |
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
"use strict"; | |
// IE supports duck typed classList so move it from HTMLElement to Element to support SVG. | |
// FireFox already has classList on Element so make sure not to tweak anything there. | |
// Chrome supports classList on every element, but as an instance property so no need to move anything there. | |
(function _initClassListPolyFill() { | |
if (!Element.prototype.hasOwnProperty("classList") && HTMLElement.prototype.hasOwnProperty("classList")) { | |
Object.defineProperty(Element.prototype, "classList", Object.getOwnPropertyDescriptor(HTMLElement.prototype, "classList")); | |
} |
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
var settingsPane = Windows.UI.ApplicationSettings.SettingsPane.getForCurrentView(); | |
settingsPane.addEventListener("commandsrequested", foo); | |
function foo(args) { | |
var cmdPrivacy = new Windows.UI.ApplicationSettings.SettingsCommand("privacy", "Privacy Policy", privacyPolicyInvoked); | |
args.request.applicationCommands.push(cmdPrivacy); | |
} | |
function privacyPolicyInvoked(args) { | |
switch (args.id) { |
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 () { | |
var _cachedDiv; | |
function domMeasureText(text, font) { | |
if (!_cachedDiv) { | |
_cachedDiv = document.createElement("div"); | |
_cachedDiv.style.visibility = "hidden"; | |
_cachedDiv.style.position = "absolute"; | |
document.body.appendChild(_cachedDiv); | |
} |
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
<!-- saved from url=(0014)about:internet --> | |
<!DOCTYPE HTML> | |
<script> | |
function Color(r, g, b) { | |
this.r = r; | |
this.g = g; | |
this.b = b; | |
} | |
Object.defineProperties(Color, { | |
colorFromHex: { |