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 eventManager(){ | |
| var set = {}; | |
| return function(e){ | |
| return { | |
| listen(cb) { | |
| if (typeof e !== "string" || typeof cb !== "function") return this; | |
| set[e] = (set[e] || []).concat(cb); | |
| return this; | |
| }, | |
| emit(data) { |
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
| Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin porttitor scelerisque lacus, ornare fermentum odio bibendum ac. Duis eget vulputate elit, dignissim tincidunt eros. In pretium dictum ipsum, et tempor velit. Aliquam tincidunt purus augue, placerat egestas neque iaculis quis. Aliquam a diam rhoncus neque semper accumsan. Morbi laoreet non mi auctor tristique. Praesent tincidunt, dolor ac posuere consectetur, enim enim viverra eros, eu dictum libero est eu massa. Vestibulum congue metus non erat sagittis varius. Nam consequat dui enim. Mauris augue eros, ultricies vitae eleifend et, mollis ultricies neque. Quisque elementum ante et est scelerisque, at condimentum ipsum ornare. |
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
| using Newtonsoft.Json; | |
| using System; | |
| using System.Collections.Generic; | |
| using System.IO; | |
| namespace Experimentation | |
| { | |
| public static class Extensions | |
| { | |
| #region IEnumerable Extensions |
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
| const range = (start, end) => { | |
| switch (true) { | |
| case start > end: return range(end, start).reverse(); | |
| default: return Array.from({ length: end - start + 1 }, (_, index) => start + index); | |
| } | |
| }; | |
| const toFizzBuzz = (number) => { | |
| const isFizz = number % 3 == 0; | |
| const isBuzz = number % 5 == 0; |
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
| /* | |
| The range function must take a start integer and end integer | |
| and generate an array of the consecutive integers between them (inclusively). | |
| Example 1: range(1, 5) == [1, 2, 3, 4, 5]; | |
| Example 2: range(2, -2) == [2, 1, 0, -1, -2]; | |
| Example 3: range(4, 4) == [4]; | |
| */ | |
| // Method #1: an imperative approach with a loop and mutation | |
| function range(start, end){ |
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
| // Requires Mustache and jQuery | |
| window.component = (function () { | |
| var collection = {}; | |
| return function (arg) { | |
| switch (typeof arg) { | |
| case "string": | |
| return collection[arg] || null; | |
| case "object": |
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
| // Factory Function pattern of object creation | |
| function newUser(id, first, last){ | |
| // Validation of inputs happens in only one place - the constructor | |
| if (typeof id !== "number") throw new Error("Invalid ID"); | |
| if (typeof first !== "string") throw new Error("Invalid FirstName"); | |
| if (typeof last !== "string") throw new Error("Invalid LastName"); | |
| return { | |
| // Getters return the values used to create the object | |
| get ID(){ return 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
| private T TryCatchWrap<T>(Func<T> action, T defaultValue) | |
| { | |
| try | |
| { | |
| return action(); | |
| } | |
| catch (Exception e) | |
| { | |
| // Log the exception somewhere | |
| return defaultValue; |
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
| // Runs <fn> immediately if not run in the last <ms> milliseconds | |
| // Skips execution of <fn> otherwise | |
| function debounce(fn, ms) { | |
| var lastRun = 0; | |
| return function () { | |
| var now = new Date().getTime(); | |
| if (now - ms >= lastRun) { | |
| lastRun = now; |
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
| // On the first tab, we need to hijack any links that would open in a new tab | |
| // and open them with JavaScript so that we can store a reference to the newly opened tab | |
| // Vanilla JavaScript | |
| Array.from(document.querySelectorAll("a[target='_blank']")).forEach(function(a){ | |
| a.addEventListener("click", function(e){ | |
| e.preventDefault(); | |
| e.stopPropagation(); | |
| window.newTabReference = window.open(a.attributes.href, "_blank"); |
OlderNewer