Skip to content

Instantly share code, notes, and snippets.

@gregberns
gregberns / ListZipper.hs
Created July 3, 2021 05:56
ListZipper duplicate
-- duplicate $ ListZipper (2:.1:.Nil) 3 (4:.5:.Nil)
-- [[1] >2< [3,4,5],[] >1< [2,3,4,5]] >[2,1] >3< [4,5]< [[3,2,1] >4< [5],[4,3,2,1] >5< []]
-- data ListZipper a = ListZipper [a] a [a]
duplicate :: ListZipper a -> ListZipper (ListZipper a)
duplicate z@(ListZipper l i r) =
let moveLeft (x :. xs) i rs = ListZipper xs x (i :. rs) :. moveLeft xs x (i :. rs)
moveLeft Nil _ _ = Nil
moveRight ls i (x :. xs) = ListZipper (i :. ls) x xs :. moveRight (i :. ls) x xs
moveRight _ _ Nil = Nil
@gregberns
gregberns / main.hs
Created July 2, 2021 06:42
How to make a Foldable Instance with multiple parameters
-- This code doesn't work...
-- How can you make a multi-parameter data type be Foldable?
-- foldMap over `a` so it can be converted to a Monoid
data BinaryTree3 a v
= Node3 a (BinaryTree3 a v) (BinaryTree3 a v)
| Leaf3 a v
deriving (Show)
instance Foldable (BinaryTree3 a) where
@gregberns
gregberns / main.ml
Created May 12, 2021 18:05
OCaml AST - ToString and Evaluation
(*
Below is OCaml code that defines an AST (based on an ML style language) and does two things:
* Takes the AST and prints it as a string
* Evaluates the AST expressions down where possible
Tests cover most of the functionality and some glaring edge cases
Note: I couldn't figure out how importing libraries worked (ounit), so I just wrote a custom assert function
Run it:
@gregberns
gregberns / Gists.md
Created March 10, 2021 16:47 — forked from BoQsc/Gists.md
How to search my own Gists
@gregberns
gregberns / wait-for-file.sh
Last active November 11, 2020 17:44
wait-for-file.sh
#!/bin/sh
# Wait for a file to exist
# Modeled off this script
# https://gist.github.com/gregberns/7e1254209860632f7a1bf9aa7c7638ee
TIMEOUT=15
QUIET=0
echoerr() {
@gregberns
gregberns / wait-for-port.sh
Last active November 3, 2020 13:25
wait-for-port.sh
#!/bin/sh
TIMEOUT=15
QUIET=0
echoerr() {
if [ "$QUIET" -ne 1 ]; then printf "%s\n" "$*" 1>&2; fi
}
usage() {
@gregberns
gregberns / README.md
Last active November 12, 2020 19:23
Git: Windows switch CRLF to LF

Git: Windows switch CRLF to LF

When working on Windows with Docker, Linux, etc, your files should be standardized to LF. This command only needs to be run once:

git config --global core.autocrlf input

Source: https://stackoverflow.com/a/5834094/684966

@gregberns
gregberns / README.md
Last active September 10, 2020 23:31

Stripe Payment Example

Example of how to use Stripe.js and Node.JS libraries.

  • index.html - Client side workflow (JS)
  • index.js - Server side workflow (Node.JS)

Note: Examples are a very rough POC, so please excuse the rough style.

@gregberns
gregberns / Azure-SQL-Server-Application-Connectivity.md
Last active October 18, 2023 12:15
Azure SQL Server Application Connectivity

Tags: Azure, Managed Identity, SQL Server Access Token, Managed Service Identity, SQL Server Authentication, App Registrations

This document will outline the concepts needed to connect to a "Secure" Azure SQL Server database, both from within Azure and outside of Azure. It also provides code snippets to demonstrate what is involved.

TLDR

Today's best practice is to access SQL databases with OAuth tokens. To connect to an Azure SQL DB, you get an OAuth token, then supply it when connecting to the SQL Database. Getting the OAuth token is different whether you're accessing it in Azure or outside Azure.

Overview

Stevey's Google Platforms Rant

I was at Amazon for about six and a half years, and now I've been at Google for that long. One thing that struck me immediately about the two companies -- an impression that has been reinforced almost daily -- is that Amazon does everything wrong, and Google does everything right. Sure, it's a sweeping generalization, but a surprisingly accurate one. It's pretty crazy. There are probably a hundred or even two hundred different ways you can compare the two companies, and Google is superior in all but three of them, if I recall correctly. I actually did a spreadsheet at one point but Legal wouldn't let me show it to anyone, even though recruiting loved it.

I mean, just to give you a very brief taste: Amazon's recruiting process is fundamentally flawed by having teams hire for themselves, so their hiring bar is incredibly inconsistent across teams, despite various efforts they've made to level it out. And their operations are a mess; they don't real