Skip to content

Instantly share code, notes, and snippets.

View ZacharyGodfrey's full-sized avatar

Zachary Godfrey ZacharyGodfrey

View GitHub Profile
@ZacharyGodfrey
ZacharyGodfrey / Component.js
Last active December 15, 2017 14:21
Uses Mustache and jQuery to create declarative components
// Requires Mustache and jQuery
window.component = (function () {
var collection = {};
return function (arg) {
switch (typeof arg) {
case "string":
return collection[arg] || null;
case "object":
@ZacharyGodfrey
ZacharyGodfrey / Range.js
Last active June 10, 2019 20:40
Showing the evolution of my range function.
/*
The range function must take a start integer and end integer
and generate an array of the consecutive integers between them (inclusively).
Example 1: range(1, 5) == [1, 2, 3, 4, 5];
Example 2: range(2, -2) == [2, 1, 0, -1, -2];
Example 3: range(4, 4) == [4];
*/
// Method #1: an imperative approach with a loop and mutation
function range(start, end){
@ZacharyGodfrey
ZacharyGodfrey / 00-complete-fizzbuzz.js
Last active September 28, 2019 13:31
Javascript implementation of FizzBuzz.
const range = (start, end) => {
switch (true) {
case start > end: return range(end, start).reverse();
default: return Array.from({ length: end - start + 1 }, (_, index) => start + index);
}
};
const toFizzBuzz = (number) => {
const isFizz = number % 3 == 0;
const isBuzz = number % 5 == 0;
@ZacharyGodfrey
ZacharyGodfrey / Extensions.cs
Last active July 17, 2019 15:36
C# extension methods.
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
namespace Experimentation
{
public static class Extensions
{
#region IEnumerable Extensions
@ZacharyGodfrey
ZacharyGodfrey / LoremIpsum.txt
Created October 27, 2016 17:15
Placeholder text.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin porttitor scelerisque lacus, ornare fermentum odio bibendum ac. Duis eget vulputate elit, dignissim tincidunt eros. In pretium dictum ipsum, et tempor velit. Aliquam tincidunt purus augue, placerat egestas neque iaculis quis. Aliquam a diam rhoncus neque semper accumsan. Morbi laoreet non mi auctor tristique. Praesent tincidunt, dolor ac posuere consectetur, enim enim viverra eros, eu dictum libero est eu massa. Vestibulum congue metus non erat sagittis varius. Nam consequat dui enim. Mauris augue eros, ultricies vitae eleifend et, mollis ultricies neque. Quisque elementum ante et est scelerisque, at condimentum ipsum ornare.
@ZacharyGodfrey
ZacharyGodfrey / EventListener.js
Last active December 21, 2017 17:56
Javascript pub/sub.
function eventManager(){
var set = {};
return function(e){
return {
listen(cb) {
if (typeof e !== "string" || typeof cb !== "function") return this;
set[e] = (set[e] || []).concat(cb);
return this;
},
emit(data) {