Skip to content

Instantly share code, notes, and snippets.

View DForshner's full-sized avatar

David Forshner DForshner

View GitHub Profile
@DForshner
DForshner / Interesting articles.txt
Last active August 29, 2015 14:27
Interesting articles
The 7 Ways to Wash Dishes and the Case for Message-driven Reactive Systems
https://www.typesafe.com/blog/the-case-for-message-driven
How does a relational database work
http://coding-geek.com/how-databases-work/
The world beyond batch: Streaming 101
https://beta.oreilly.com/ideas/the-world-beyond-batch-streaming-101
@DForshner
DForshner / PassNullParameterToStoredProcedure.sql
Created June 19, 2015 16:45
Passing nullable parameter to stored procedure
CREATE PROCEDURE [DB].[PassNullParameterToStoredProcedure] (@Started DateTime = NULL)
AS
BEGIN
DECLARE @Data TABLE( Started DateTime NOT NULL)
INSERT INTO @Data (Started)
VALUES ('2015-01-01T00:00:00'), ('2015-01-02T00:00:00'), ('2015-01-03T00:00:00')
SELECT * FROM @Data
@DForshner
DForshner / gist:0c4084983eeaba0a485d
Created March 26, 2015 20:14
D3.js Linear Heat Map w/ Clickable Tooltips
var _numBuckets = 24;
var start = 1000;
var end = 5000;
var _width = 150;
var _height = 40;
var _margin = {
top: 1,
right: 1,
bottom: 1,
@DForshner
DForshner / helloassembly.s
Created December 18, 2014 18:39
Hello world in assembly
# ---------------------------------------------------------------
# Hello assembly!
# Compile: gcc -o helloassembly -nostdlib helloassembly.s
# Tested on Ubuntu 14 (x64)
# ---------------------------------------------------------------
.global _start
.text
_start:
@DForshner
DForshner / gist:90175edc7806af3a376d
Last active August 29, 2015 14:05
By implementing the IDisposiable interface we can use the using keyword which will call the Dispose method restoring the original value. This is not thread safe as the temporary state change will be visible to other threads.
public class CustomScope : IDisposable
{
private readonly State originalState;
public CustomScope(State state)
{
this.originalState = GlobalSingleton.State;
GlobalSingleton.State = state;
}
@DForshner
DForshner / CaptureTriggerForLogDebug.js
Created July 25, 2014 17:35
Capture event triggers for logging/debugging
var originalTrigger = App.events.trigger;
App.events.trigger = function () {
console.log("Event Triggered:");
console.log(arguments);
originalTrigger.apply(this, Array.prototype.slice.call(arguments));
};
@DForshner
DForshner / CheckArrayOfBoolsForTrue.cs
Created June 4, 2014 21:39
Returns true if there are any true values in an array.
public static class BoolExtensions
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[DebuggerStepThrough]
public static bool AnyTrue(this IEnumerable<bool> bools)
{
return bools.Aggregate((a, b) => (a || b));
}
}
@DForshner
DForshner / DisplayBits.cs
Created May 30, 2014 21:47
Some different ways to get the bit representation of a 32 bit int.
public static class Program
{
public static void Main()
{
int value = 576;
byte[] bytes = new byte[4];
bytes[0] = (byte)(value >> 24);
bytes[1] = (byte)(value >> 16);
bytes[2] = (byte)(value >> 8);
bytes[3] = (byte)value;
@DForshner
DForshner / FindIndexOfSmallestArrayElement.js
Created May 26, 2014 23:06
Find the index of the smallest array element.
// Find the index of the smallest value.
// Linear search
var findIndexOfSmallest = function(arr) {
if (!arr.length) { return -1; }
var lowIdx = 0;
for (var i = 0; i < arr.length; i++) {
if (arr[i] < arr[lowIdx]) { lowIdx = i; }
}
return lowIdx;
@DForshner
DForshner / consoleAssertDemo.js
Created April 29, 2014 19:03
How console.assert() behaves with undefined, null, and zero values.
var isNull = null;
console.log(isNull);
console.assert(isNull);
var isUndefined;
console.log(isUndefined);
console.assert(isUndefined);
var isZero = 0;
console.log(isZero);