Skip to content

Instantly share code, notes, and snippets.

@gregberns
gregberns / Optimizely_RemoveListener.js
Last active February 7, 2018 17:57
Optimizely - Remove Listener
var token = Number(new Date());
window["optimizely"] = window["optimizely"] || [];
window["optimizely"].push({
type: "addListener",
filter: {
type: "lifecycle",
name: "pageDeactivated"
},
token: token,
// Add the pageActivated function as a handler.
@gregberns
gregberns / UniDirectionalDataFlow.js
Last active February 12, 2018 00:59
Demo Uni-directional Data Flow
//# Introduction
//The following is a generalized architecture based on the Elm architecture
// and the many subsequent derivations of it.
//The essential idea of the Elm architecture is that a User Interface has a
// 'uni-directional' data flow, which means data flows in a single directions.
//Here's a simple example:
// Button Click Event -> Handle Event -> Make Http Call -> Update State -> Update View
//Events occur which causes the system('services') to react to them. The system
// then sends commands to the state of the system to transition from 'State A' to 'State B'.
@gregberns
gregberns / UniDir-IncorrectImpl-First.js
Last active March 13, 2018 06:48
UniDirectional Data Flow With React
//# Introduction
//The following is a generalized architecture based on the Elm architecture
// and the many subsequent derivations of it.
//The essential idea of the Elm architecture is that a User Interface has a
// 'uni-directional' data flow, which means data flows in a single directions.
//Here's a simple example:
// Button Click Event -> Handle Event -> Make Http Call -> Update State -> Update View
//Events occur which causes the system('services') to react to them. The system
// then sends commands to the state of the system to transition from 'State A' to 'State B'.
@gregberns
gregberns / VSCode Setup.md
Last active June 26, 2018 20:27
How to set up VSCode with helpful features

VSCode

Linting TS Files

Install 'TSLint' plugin

Run this command:

npm install -g tslint typescript
@gregberns
gregberns / buildFeaturePreview-final.js
Created May 18, 2018 07:11
Refactor Spectacular - List to String
buildFeaturePreview(vehicle: IVehicle): string {
let mpg = this.shouldShowMpg(vehicle) ? `${vehicle.MPGCity} / ${vehicle.MPGHighway} MPG` : null;
let features = vehicle.HighlightedFeatures.map(feature => feature.description);
return [mpg,
...features]
.filter(isDefinedAndNotNull)
.join(', ')
'...';
}
@gregberns
gregberns / diamond.hs
Created May 20, 2018 17:45
Diamond Kata in Haskell - First Attempt
import Data.Traversable
main =
traverse print (genAll 'J')
-- [_,_,A,_,_]
-- [_,B,_,B,_]
-- [C,_,_,_,C]
-- [_,B,_,B,_]
-- [_,_,A,_,_]
@gregberns
gregberns / mapFilterReduceOnObject.js
Created June 7, 2018 18:29
Implementation of Map, Filter, and Reduce on an Object to iterate through its keys
let map = (f, o) => {
//o must be an object
let keys = Object.keys(o);
let ret = {};
for (let i = 0; i <= keys.length - 1; i++) {
let key = keys[i];
let val = o[key];
ret[key] = f(val, key);
}
return ret;
@gregberns
gregberns / Cabal 2.2.0.0 Fails
Last active August 27, 2018 06:59
Cabal Install fails
Download `cabal-install-2.2.0.0-x86_64-apple-darwin-sierra.tar.gz`
Extract
Run:
Gregs-MacBook-Pro:downloads huck$ ./cabal --version
cabal-install version 2.2.0.0
compiled using version 2.2.0.1 of the Cabal library
Gregs-MacBook-Pro:downloads huck$ ./cabal install Cabal cabal-install
Warning: Parsing the index cache failed (Unknown encoding for constructor).
Trying to regenerate the index cache...
@gregberns
gregberns / FunctionDeclaration.cs
Created September 17, 2018 15:35
C# Lambda Cheat Sheet
//Local Declaration
Func<string> returnsString = () => "";
Func<int, int> takesIntReturnsInt = i => i * 2;
//Class-Level Declaration
//Generic Params
@gregberns
gregberns / haskell-course.hs
Created October 2, 2018 05:35
Intro Syntax for Haskell
{-# OPTIONS_GHC -fwarn-incomplete-patterns -Werror #-}
-- Show
-- p1 =
-- ...
-- method(f,f)
-- ...
-- p2 =
-- ...