Skip to content

Instantly share code, notes, and snippets.

#!/bin/zsh
# macOS Server Optimization Script
# Disables unnecessary background processes and services for server use
# Based on community research and tested configurations
# WARNING: This script makes significant changes to your macOS system
# Please read through and understand each section before running
# Test in a non-production environment first
@gregberns
gregberns / setup.sh
Last active August 9, 2025 05:33
MacOS Setup
#!/bin/bash
# Improved Mac Setup Script - Idempotent and Modular
# This script sets up a new Mac development environment with proper error handling
# and idempotency checks.
#
# # Download
# curl ~~Get gist raw url~~ > setup.sh
# chmod +x ~/setup.sh
# ~/setup.sh
@gregberns
gregberns / mcp-server.md
Last active May 16, 2025 06:10
MCP Servers - What the hell are they??

MCP Servers

What the hell is an MCP server?

What do they have to do with LLMs?

Why would I want to use one and why is everyone talking about them?

Story

@gregberns
gregberns / gist:1d089693da82830d708a7d1f1c814de1
Created February 10, 2025 16:26
Postgres Global string search
-- This function will do a global search through a Postgres database.
CREATE OR REPLACE FUNCTION search_columns(
needle text,
haystack_tables name[] default '{}',
haystack_schema name[] default '{}'
)
RETURNS table(schemaname text, tablename text, columnname text, rowctid text)
AS $$
begin
@gregberns
gregberns / sql
Last active January 29, 2025 20:12
ERD: Postgres SQL to MermaidJs
-- This will query your Postgres DB, and generate MermaidJs formatted ERD
SELECT 'erDiagram'
UNION ALL
SELECT
format(E'%s { %s\n}',
c.relname,
string_agg(
format(E'\n %s %s',
REPLACE(
@gregberns
gregberns / Problem.md
Last active March 31, 2022 12:34
FP Refactor

Rewrite this function to be as succinct as possible! (Hint: One function needed and an In-Fix Operator)

(a, b) => doStuff(_ => a, b)
@gregberns
gregberns / Yoneda.md
Created November 29, 2021 07:47
Introduction to Yoneda and Coyoneda

Introduction to Yoneda and Coyoneda

Yoneda (and its duel Coyoneda) is well known in the Category Theory field and has been ported over to functional languages such as Haskell. Each have their uses - sometimes in similar scenarios, also in very different ways.

This will be a newbie's explanation of the concept, using Haskell to illustrate, without any Category Theory.

From what I've read, the Yonedas are not 'daily-drivers' (not used everyday), but rather can be pulled out when the time is right.

Uses: Both Yoneda's can be used to help speed up a program where there are many fmap with long lists or big trees involved. Coyoneda can be used if you want to create an 'interface' and build up calculations, then pass those calculations to an 'executor' to run them.

@gregberns
gregberns / StoreCompose.hs
Created July 19, 2021 06:05
Store Compose
compose ::
Lens b c ->
Lens a b ->
Lens a c
compose (Lens g) (Lens f) =
Lens
( \a ->
let Store s2 g2 = f a
Store s3 g3 = g g2
in Store (s2 . s3) g3
@gregberns
gregberns / BinaryTreeComonad.hs
Created July 6, 2021 00:44
Comonadic Binary Tree in Haskell
data BinaryTree3 v a
= Node3 v a (BinaryTree3 v a) (BinaryTree3 v a)
| Leaf3 v a
deriving (Show)
-- Node3 (Node3 0 False (Node3 1 False (Leaf3 3 False) (Leaf3 4 False)) (Leaf3 2 True)) False
-- (Node3 (Node3 1 False (Leaf3 3 False) (Leaf3 4 False)) False
-- (Leaf3 (Leaf3 3 False) False)
-- (Leaf3 (Leaf3 4 False) False))
-- (Leaf3 (Leaf3 2 True) True)
@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