Skip to content

Instantly share code, notes, and snippets.

View cameronpresley's full-sized avatar

Cameron Presley cameronpresley

View GitHub Profile
@cameronpresley
cameronpresley / questions-of-the-day.md
Last active March 29, 2022 02:42
Questions of the Day
  1. What is your go-to snack?
  2. What's one thing you know better than anyone on the team?
  3. If your safety was guaranteed, would you rather explore deep space or the oceans?
  4. If you had to give a 10 minute presentation with zero prep time, what would you present?
  5. What's a music album that is so good that you shouldn't skip a single track?
  6. If you have a friend coming into town for the weekend and you could only guarantee doing one thing, what thing would you recommend?
  7. What is your favorite kind of pie?
  8. What is your favorite dinosaur?
  9. What animal best represents you?
  10. If you had to recommend one book to read, what book would you recommend?
@cameronpresley
cameronpresley / common-mistakes-where.cs
Last active December 13, 2020 02:20
C# Advent 2020
// Generate numbers from -10 .. 100
var numbers = Enumerable.Range(-10, 111);
// Determines all positive numbers that are divisible by 6
var positiveDivisbleBySix = numbers
.Where(x=>x > 0) // iterates through the whole list (111 comparisons, returning 100 results)
.Where(x=>x % 2 == 0) // iterates through the new list (100 comparisons, returning 50 results)
.Where(x=>x % 3 == 0); // iterates through the new list (50 comparisons, returning 16 results)
// Overall metrics: 261 comparisons over 111 total elements)
@cameronpresley
cameronpresley / example.js
Last active November 23, 2020 19:47
Lodash Example of Building a Generic Filter
const _ = require("lodash");
const items = [
{id:1, name: "fluffy", animal: "cat"},
{id: 2, name: "spot", animal: "dog"},
{id: 3, name: "clifford", animal: "dog"},
{id: 4, name: "tony", animal: "tiger"}
];
const isAnimal = (animal, item) => item.animal === animal;
@cameronpresley
cameronpresley / abstract.md
Created March 18, 2019 23:27
Learning Functional Programming Through Construction: First Principles

Learning Functional Programming Through Construction: First Principles

In the past five years, functional programming has increased dramatically in popularity which has lead to an explosion of resources in learning these concepts. But, between languages (Haskell, Elm, PureScript, F#), libraries (Ramda, fp-ts), and concepts (Monads, Monoids, Functors), it can be overwhelming in determining where to start and how to begin.

In this talk, I'm going to show you three fundamental concepts of functional programming: pure functions, immutability, and composition by not only explanation, but through building these concepts through code and application. As we explore each concept, I'll show you the advantages of following these principles, how they will improve your development experience, and how they will set the stage for more advanced ideas.

Intended for those who have experience with TypeScript or C#, by the end of this presentation, you will understand how pure functions lead to easier to test code, how imm

@cameronpresley
cameronpresley / memzip.cs
Created November 26, 2018 14:01
Zip/Unzip a compressed folder in memory
using System;
using System.IO.Compression;
using System.Text;
public class InMemoryZipCompresser
{
public byte[] Compress (string fileContents)
{
using (var ms = new MemoryStream())
{
@cameronpresley
cameronpresley / functional-fizzbuzz.cs
Created November 6, 2018 21:18
Functional FizzBuzz
Func<int, string> fizzBuzz = i =>
{
if (i % 5 == 0 && i % 3 == 0) return "FizzBuzz";
else if (i % 3 == 0) return "Fizz";
else if (i % 5 == 0) return "Buzz";
return i.ToString();
};
Func<StringBuilder, string, StringBuilder> reduce = (sb, s) => sb.AppendLine(s);
@cameronpresley
cameronpresley / chapter-6.hs
Created June 21, 2018 21:00
Chapter 6 Exercises of Haskell Book
import qualified Data.List (sort)
data Person = Person Bool
instance Show Person where
show (Person b) = show b
printPerson :: Person -> IO ()
printPerson person = putStrLn (show person)
data Mood = Blah | Woot deriving (Show, Eq)
@cameronpresley
cameronpresley / eq-instances.hs
Created June 20, 2018 18:43
Deriving Example Eq instances from Haskell Book
data TisAnInteger = TisAn Integer
instance Eq TisAnInteger where
(==) (TisAn a) (TisAn b) = a == b
data TwoIntegers = Two Integer Integer
instance Eq TwoIntegers where
(==) (Two a b) (Two c d) = (a == c) && (b == d)
data StringOrInt = TisAnInt Int | TisAString String
instance Eq StringOrInt where
public static class FunctionExtensions
{
public static Func<T2> Apply<T1, T2>(this Func<T1, T2> func, T1 input) => () => func(input);
public static Func<T2, T3> Apply<T1, T2, T3>(this Func<T1, T2, T3> func, T1 input) => x => func(input, x);
public static Func<T2, T3, T4> Apply<T1, T2, T3, T4>(this Func<T1, T2, T3, T4> func, T1 input) =>
(a, b) => func(input, a, b);
public static Action Apply<T1>(this Action<T1> action, T1 input) => () => action(input);
public static Action<T2> Apply<T1, T2>(this Action<T1, T2> action, T1 input) => a => action(input, a);
@cameronpresley
cameronpresley / Program.fs
Last active April 26, 2018 15:45
F# Lenses
// Learn more about F# at http://fsharp.org
open System
type Record = {x:int; y:int}
type Nested = {number:int; record:Record}
[<EntryPoint>]
let main argv =
let record = {x=10; y=20}
printfn "Creating a record with x=%i and y=%i" record.x record.y