Skip to content

Instantly share code, notes, and snippets.

@mjgpy3
mjgpy3 / reminder.sh
Created October 24, 2019 00:05
Reminder for bashrc
if [ $(date +%s) -ge $(date -d 2019-11-01 +%s) ];
then
notify-send "Check out this cool thing!"
fi
@mjgpy3
mjgpy3 / Bfs.hs
Created October 4, 2019 00:47
Functional Breadth-First Search in Haskell
module Main where
import qualified Data.Sequence as Seq
import qualified Data.Set as S
import qualified Data.Map.Strict as M
type Position = (Int, Int)
spotsAndPositions :: String -> (S.Set Position, M.Map Int Position)
spotsAndPositions text =
@mjgpy3
mjgpy3 / bfs.py
Created October 2, 2019 23:03
Breadth-First Search in Python
from itertools import permutations
with open('input.txt', 'r') as f:
text = f.read()
numbers = [int(c) for c in text if c in "0123456789"]
lines = [line for line in text.split('\n') if line]
positions = {}
@mjgpy3
mjgpy3 / generatingTestsFromTables.js
Created September 27, 2019 00:28
generatingTestsFromTables.js
function canAppear(enemy, environment) {
return Boolean(
(environment.isSunny && !enemy.isVampire) ||
(environment.isRainy && enemy.hasWaterResistantArmor) ||
enemy.hasntAppearedInAnHour
);
}
describe(canAppear, () => {
[
@mjgpy3
mjgpy3 / nestingDescribes.js
Created September 26, 2019 00:11
nestingDescribes.js
function canAppear(enemy, environment) {
return Boolean(
(environment.isSunny && !enemy.isVampire) ||
(environment.isRainy && enemy.hasWaterResistantArmor) ||
enemy.hasntAppearedInAnHour
);
}
describe(canAppear, () => {
let enemy = {};
@mjgpy3
mjgpy3 / dhall-lambda-output.tf
Created September 15, 2019 13:04
Dhall Terraform Output (forgot quotes on env var values)
output "function_names" {
value = [
aws_lambda_function.hello.function_name,
aws_lambda_function.goodbye.function_name
]
}
data "archive_file" "hello-zip" {
type = "zip"
source_dir = "../lambdas/hello/"
@mjgpy3
mjgpy3 / tf.dhall
Created September 15, 2019 13:01
tf.dhall
let map = https://raw.githubusercontent.com/dhall-lang/dhall-lang/master/Prelude/List/map
let concatSep = https://raw.githubusercontent.com/dhall-lang/dhall-lang/master/Prelude/Text/concatSep
let EnvVar : Type = { key : Text, value : Text }
let Lambda : Type = { name : Text, envVars : List EnvVar }
let tfEnvVar = \(envVar : EnvVar) ->
" ${envVar.key} = ${envVar.value}"
let tfLambdaFunctionName = \(lambda : Lambda) ->
@mjgpy3
mjgpy3 / IoMonadBind.md
Created June 19, 2019 00:44
Notes on IO Bind

If you look at the type of Io notice that it is a type alias of just a good old function

type Io<'a> = Effects -> 'a

This is like saying

an Io of some value 'a is just a function that takes available effects and returns back some 'a.

@mjgpy3
mjgpy3 / some.fs
Created June 8, 2019 20:35
Some Equiv F# Code
type Person = { Name: string; Age: int; FavoriteColor: string }
let pickColor i =
if i % 5 = 0 then "Brown"
else if i % 3 = 0 then "Red"
else if i % 2 = 0 then "Blue"
else "Yellow"
let people =
@mjgpy3
mjgpy3 / Linq.cs
Created June 8, 2019 20:26
Some LINQ Code
using System;
using System.Linq;
class Person {
public string Name {get;set;}
public int Age {get;set;}
public string FavoriteColor {get;set;}
}
class MainClass {