Skip to content

Instantly share code, notes, and snippets.

View johndkane's full-sized avatar
🎯
Focusing

John Kane johndkane

🎯
Focusing
View GitHub Profile
@johndkane
johndkane / ScalarToEnumUtility.cs
Last active September 23, 2019 22:08
Two helpful methods (one extension) to enable scalar values to be used in an enumerable context, without needing to create an intermediary collection
namespace Your_Project
{
using System.Collections.Generic;
static public class Utility
{
/// <summary>
/// Extension method yields the given value verbatim allowing it to be used in an enumerable context.
/// USAGE: 1.YieldValue()
/// EXAMPLE: listOfNumbers.Union(1.YieldValue()); // using System.Linq
@johndkane
johndkane / gist:5158296
Last active December 14, 2015 22:28
JavaScript console Polyfill / special case pattern. Basically prevents cross-browser console hell by implementing missing console and empty methods so no JS errors will occur. I found this useful and decided to post a gist. There are many versions of it in the wild; this is only one.
// Run this script before any others.
// Polyfill: provides a missing console and empty implementations for its missing methods.
(function(disable) {
if (!window.console) window.console = { };
var methods = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml", "group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];
for (var i = 0; i < methods.length; i++) {
if (disable || !console[methods[i]]) {
console[methods[i]] = function () { };
}
}