Skip to content

Instantly share code, notes, and snippets.

View Arrow7000's full-sized avatar
👨‍💻
thinking about types

Aron Adler Arrow7000

👨‍💻
thinking about types
View GitHub Profile
@VictorTaelin
VictorTaelin / hoc_historical_overview.md
Last active July 25, 2024 04:09
Higher Order Company: Complete Historical Overview - WIP

Higher-Order Company: Complete Historical Overview

This document is a complete historical overview of the Higher Order Company. If you want to learn anything about our background, a good way to do so is to feed this Gist into an AI (like Sonnet-3.5) and ask it any question!

My Search for a Perfect Language

It all started around 2015. I was an ambitious 21-year-old CS student who, somehow, had been programming for the last 10 years, and I had a clear goal:

I want to become the greatest programmer alive

Examples

[@import stdlib.http.v1];

(x => y => (x_plus_y: x + y) => );

((A, x))
(f: () -> (A: *, x: A)) =>
  (A, x) = (f ());
type AsyncOptionBuilder() =
member __.Return (value: 'T) : Async<Option<'T>> =
async { return Some value }
member __.ReturnFrom
(asyncResult: Async<Option<_>>)
: Async<Option<_>> =
asyncResult
@apieceofbart
apieceofbart / test.js
Last active July 16, 2024 06:22
Async testing with jest fake timers and promises
PLEASE CHECK THIS REPO WITH THE EXAMPLES THAT YOU CAN RUN:
https://github.com/apieceofbart/async-testing-with-jest-fake-timers-and-promises
// Let's say you have a function that does some async operation inside setTimeout (think of polling for data)
function runInterval(callback, interval = 1000) {
setInterval(async () => {
const results = await Promise.resolve(42) // this might fetch some data from server
callback(results)
}, interval)
@willfrew
willfrew / tuples.ts
Created August 15, 2018 12:53
Fun with tuple types in Typescript 3.0
type Head<T extends unknown[]> = T[0];
type FnWithArgs<T extends unknown[]> = (...args: T) => void;
type TailArgs<T> = T extends (x: unknown, ...args: infer T) => unknown ? T : never;
type Tail<T extends unknown[]> = TailArgs<FnWithArgs<T>>;
// Lol
type Decr<T extends number> =
T extends 10 ? 9 :
T extends 9 ? 8 :
@kekyo
kekyo / option.fs
Created July 3, 2017 23:51
F# option computation expression
[<Struct>]
type OptionalBuilder =
member __.Bind(opt, binder) =
match opt with
| Some value -> binder value
| None -> None
member __.Return(value) =
Some value
let optional = OptionalBuilder()
@gusty
gusty / polyvariadic.fsx
Last active July 20, 2023 15:19
Polyvariadic functions in F#
// Unfortunatelly it stopped working in F# 4.1 after this PR https://github.com/Microsoft/visualfsharp/pull/1650
// Will ask to revert it
type FoldArgs<'t> = FoldArgs of ('t -> 't -> 't)
let inline foldArgs f (x:'t) (y:'t) :'rest = (FoldArgs f $ Unchecked.defaultof<'rest>) x y
type FoldArgs<'t> with
static member inline ($) (FoldArgs f, _:'t-> 'rest) = fun (a:'t) -> f a >> foldArgs f
static member ($) (FoldArgs f, _:'t ) = f
@spyesx
spyesx / string-to-slug.js
Last active March 15, 2024 12:05
String to slug in JS (wordpress sanitize_title)
var string_to_slug = function (str)
{
str = str.replace(/^\s+|\s+$/g, ''); // trim
str = str.toLowerCase();
// remove accents, swap ñ for n, etc
var from = "àáäâèéëêìíïîòóöôùúüûñçěščřžýúůďťň·/_,:;";
var to = "aaaaeeeeiiiioooouuuuncescrzyuudtn------";
for (var i=0, l=from.length ; i<l ; i++)
@tracker1
tracker1 / .bashrc
Created July 23, 2014 23:05
Git Bash Shell startup for automatic ssh-agent running
SSH_ENV=$HOME/.ssh/environment
# start the ssh-agent
function start_agent {
echo "Initializing new SSH agent..."
# spawn ssh-agent
/usr/bin/ssh-agent | sed 's/^echo/#echo/' > "${SSH_ENV}"
echo succeeded
chmod 600 "${SSH_ENV}"
. "${SSH_ENV}" > /dev/null
@staltz
staltz / introrx.md
Last active July 27, 2024 04:59
The introduction to Reactive Programming you've been missing