Skip to content

Instantly share code, notes, and snippets.

@gregberns
gregberns / gist:7441424
Created November 13, 2013 00:31
NancyFX Error handling. The OnError, does not return anything in the message body. What am I doing wrong??
public class Bootstrapper : DefaultNancyBootstrapper
{
protected override void RequestStartup(TinyIoCContainer requestContainer, IPipelines pipelines, NancyContext context)
{
pipelines.OnError += (ctx, ex) =>
{
return ErrorResponse.FromException(ex);
};
base.RequestStartup(requestContainer, pipelines, context);
@gregberns
gregberns / gist:8109218
Last active January 1, 2016 07:08
Basic object structure for Support System
Public Class Thread
Public Posts as List(of Post)
Property Subject as String
Property Status as int
Property Product as String
Property Priority as int
Property CallType as int
Property AssignedToUser as User
@gregberns
gregberns / Platform
Last active August 29, 2015 14:13
Platform Persistence
public class Platform
{
public string Name { get; set; }
public string Server { get; set; }
public int Port { get; set; }
public string Username { get; set }
public string Password { get; set; }
}
@gregberns
gregberns / gist:fbece9d6a8fa9dfe30c6
Created July 16, 2015 03:37
Code to Compile and Run .Net 'Scripts' At Runtime
Imports System.Reflection
Imports System.CodeDom.Compiler
Imports IBE.Scripting
Module Module1
Sub Main()
Dim vbScript = <a>
@gregberns
gregberns / Multiple Versions Of FizzBuzz
Last active March 13, 2016 23:15
FizzBuzz actually can get quite interesting
function FizzBuzz(i, end) {
if (i > end) return;
if (i % 3) {
console.log('fizz')
}
if (i % 5) {
console.log('buzz')
}

Programming Problems

Below are several programming problems. Try and solve them without Googling the answers.

Factorial

Create a function(s) that takes an integer and returns its factorial.

Example: Takes 3, returns (1 * 2 * 3) or 6

@gregberns
gregberns / diamond.re
Last active October 2, 2017 04:54
Diamond Kata
module Diamond = {
let inc_char c => char_of_int (int_of_char c + 1);
let rec range_rec l a b => a == b ? l @ [a] : range_rec (l @ [a]) (inc_char a) b;
let range a b => range_rec [] a b;
let rec replicate a s i => i < 1 ? a : replicate (a ^ s) s (i - 1);
let addSpaces i => replicate "" " " i;
let line p j c => {
let cs = Char.escaped c;
addSpaces p ^ cs ^ (j < 1 ? "" : addSpaces j ^ cs)
};
/*output is a concatenated string for testing, but feel free to reformat as needed*/
/*campaignID:experimentId:variationId:audienceId:"audience conditions"*/
/*e.g. 7807482864:7807902575:7806347946:6536242902:"and,or,or,{"value":"iphone","type":"device","name":null,"match":null}",7807482864:7807902575:7806347946:9436482444:"and,or,or,{"value":"00:00_23:59_friday","type":"time_and_day","name":null,"match":null}"*/
/*this code only includes audiences for which the visitor actually qualified*/
var state = window.optimizely.get && window.optimizely.get('state');
var data = window.optimizely.get && window.optimizely.get('data');
(function getCurrentActiveAll(e) {
if ('undefined' !== typeof window.optimizely) {
//# Dispatch Event
// An event is sent when something happens - the user clicks a button, or a websocket receives a new message.
// The UI can dispatch
// Event has: name and data
function onButtonClick() {
let queryText = document.getElementById('queryText').value
console.log('queryText', queryText)
dispatchEvent({ name: 'START_SEARCH' , payload: queryText });
function parseQueryString(queryString) {
Array.prototype.fapply = function(fn) { return fn(this); };
return (queryString[0] === '?' ? queryString.substr(1) : '')
.split('&')
.fapply(i => (i.length && !i[0]) ? [] : i)
.map(i => i.length ? i.split('=') : [])
.reduce((a, i) => {
a[i[0]] = i[1];
return a;
}, {});