Skip to content

Instantly share code, notes, and snippets.

View JamieDixon's full-sized avatar

Jamie Dixon JamieDixon

View GitHub Profile
function hamming (n) {
// TODO: Program me
var hammedNumbers = [];
var startIndex = 1;
while(hammedNumbers.length < n)
{
var primeFactors = calcPrimeFactors(startIndex);
var largestPrime = primeFactors[primeFactors.length - 1];
var moveZeros = function (arr) {
var zeros = [];
var foo = arr.filter(function(value) {
var isZero = value === 0;
if(isZero) { zeros.push(0); }
return value !== 0;
})
return foo.concat(zeros);
}
var anarchy = function () {
var len = "htgnel".split("").reverse().join("");
return 'I can write numbers like, ' + ["."][len] + ", " + [".","."][len] + ", " + [".",".","."][len] + ".";
}
function once(fn) {
var isUsed = false;
return function(){
if(!isUsed)
{
isUsed = true;
var arg = Array.prototype.slice.call(arguments, 0).reverse()[0];
fn(arg);
return arg;
}
function once(fn) {
var isUsed = false;
return function(param){
if(!isUsed)
{
isUsed = true;
fn(param);
return param;
}
}
@JamieDixon
JamieDixon / gist:46dc2fe92b143fcc7a6c
Created May 8, 2014 09:15
HTML5 Validation Module
/*jslint devel: true */
/*jslint browser: true, nomen: true */
/*global jQuery, cf*/
(function IIFE($, cf) {
"use strict";
cf.FormValidation = function formValidation(formSelectors) {
var self = this;
function html5ValidationSupported() {
@JamieDixon
JamieDixon / TheBlob
Created May 20, 2014 14:22
What happens when we replace a basic mock with its real implementation
var theBlobMock = new Mock<ITheBlob>();
VS
var theBlob = new TheBlob(
new SCP(new S(), new AP(new SP(new S(), new AL(new S()))), new SCS()),
new S(),
new CP(new S()),
new MP(new S()),
new AP(new SP(new S(), new AL(new S()))),
@JamieDixon
JamieDixon / gist:6cf0cdf1dcdf3aa62909
Created June 18, 2014 15:54
Custrom Binder for Module
protected override object CreateModel(ControllerContext controllerContext, ModelBindingContext bindingContext, Type modelType)
{
var moduleName = bindingContext.ValueProvider.GetValue(bindingContext.ModelName + ".ModuleName");
var moduleTypes = new Dictionary<string, Type>
{
{ "SearchDetails", typeof(SearchDetailsProfileModule) },
{ "SubscriptionType", typeof(SelectedSubscriptionsProfileModule) },
{ "PausePeriod", typeof(PausePeriodProfileModule) },
{ "UserProfile", typeof(UserDetailsProfileModule)}
window.pubSub = window.pubSub || {};
(function IFEE(pubSub) {
'use strict';
var eventStore = {}, lastId = 0;
pubSub.subscribe = function sub(topic, func) {
if (!eventStore.hasOwnProperty(topic)) {
eventStore[topic] = {}; // Was using an array but this seems better for unsub perf.
model.Countries =
(profile.Countries.GroupBy(
x => x.ContinentName,
y => y,
(key, g) =>
new
{
Key = key,
Value =
g.Select(