Skip to content

Instantly share code, notes, and snippets.

View DForshner's full-sized avatar

David Forshner DForshner

View GitHub Profile
@DForshner
DForshner / SimpleLookupTable.js
Created January 16, 2014 16:14
Lookup Table - Replaces a series of if/else statements or a case statement.
var lookup = {
A: { Source: "CAN", Destination: "USD" },
B: { Source: "CAN", Destination: "USD" },
C: { Source: "CAN", Destination: "USD" },
D: { Source: "CAN", Destination: "USD" },
E: { Source: "USD", Destination: "CAD" },
F: { Source: "USD", Destination: "CAD" },
};
var key = "A";
@DForshner
DForshner / EventEmitterPattern.js
Created January 16, 2014 16:12
Event Emitter Pattern - Decouples event emitters from event receivers.
var EventDispatcher = {
listeners: {},
register: function(eventName, callback) {
if (typeof this.listeners[eventName] == 'undefined') {
this.listeners[eventName] = [];
}
this.listeners[eventName].push(callback);
},
{
// --------------------------------------------------------------------
// JSHint Configuration, Strict Edition
// --------------------------------------------------------------------
//
// This is a options template for [JSHint][1], using [JSHint example][2]
// and [Ory Band's example][3] as basis and setting config values to
// be most strict:
//
// * set all enforcing options to true
@DForshner
DForshner / MarkDownSyntax.md
Last active January 2, 2016 02:39
Testing markdown syntax

Stuff

  • Step 1
  • Step 2
  • Step 3 - Profit
@DForshner
DForshner / VisuallyIndicatingIntersectionOfTwoDateArraysInDropDown.css
Created December 20, 2013 22:52
Populates a drop down list with all dates from one array and visually indicates which dates are common with another array that contains a subset of those dates. http://jsfiddle.net/DForshner/gR86a/
@import url('http://getbootstrap.com/dist/css/bootstrap.css');
.page-header {
padding: 15px;
background-color: rgb(0, 175, 0);
color: #111;
}
@DForshner
DForshner / JqueryDeferredQueues.css
Last active December 19, 2020 18:24
jQuery Deferred Queues - Queuing up work items to execute in sequence or parallel. http://jsfiddle.net/DForshner/B46q5/
ul {
list-style-type: disc;
margin:0 0 0 2em;
}
li {
margin:0 0 .5em;
}
body {
font-family:"Verdana";
font-size: 9pt;
@DForshner
DForshner / LINQJoinMethodStyle.cs
Created November 13, 2013 19:08
LINQ Join() using method style.
public class F
{
public string Field1 { get; set; }
public string Field2 { get; set; }
}
public class P
{
public string Field1 { get; set; }
public string Field2 { get; set; }
@DForshner
DForshner / jQueryParallelSequentialPromises.css
Last active May 7, 2018 05:20
jQuery - Parallel and Sequential Promises
ul {
list-style-type: disc;
margin:0 0 0 2em;
}
li {
margin:0 0 .5em;
}
body {
font-family: "Verdana";
@DForshner
DForshner / RoundNumericObjectProperties.js
Created October 22, 2013 00:18
A QUnit test with some code that loops over object properties and rounds any numeric properties to 2 decimal places. TODO: Return a cloned copy of the obj instead of mutating it.
test("When round object properties expect numbers to be rounded to 2 places.", function () {
// If property belongs to the object, is numeric, and is not null change to 2 decimal places.
// TODO: Return a cloned copy of the object () instead of mutating it.
var roundProperties = function (obj) {
for (var prop in obj) {
if ((!obj.hasOwnProperty(prop)) || (isNaN(obj[prop])) || (obj[prop] === null))
continue;
obj[prop] = obj[prop].toFixed(2);
-- Get the last day of the current month.
SELECT
DATEADD(s,-1,
DATEADD(mm,
DATEDIFF(m,0,'2012/08/31') -- Get # of months since '1753-01-01'
+1,0) -- Get the date by adding # of months + 1
) -- Remove one second so date rolls back to the last second of the original month
-- Get the last day of the previous month.
SELECT