Skip to content

Instantly share code, notes, and snippets.

View mvaldesdeleon's full-sized avatar

Martín Valdés de León mvaldesdeleon

View GitHub Profile
newtype Position = (Integer, Integer)
data Replacement = {
rStart :: Position,
rEnd :: Position,
rText :: [Char]
}
data Intersect = BEFORE | INSIDE | AFTER
replace :: [Replacement] -> [Char] -> State Position [Char]
replace _ [] = return []
@mvaldesdeleon
mvaldesdeleon / furvo.js
Created November 25, 2022 16:51
Just some world cup simulations...
let currentScores = {
'arg': 0,
'mex': 1,
'pol': 1,
'ara': 3
}
function updateScores(scores, {home, away, result}) {
scores = {...scores}
type Score = Int
type Rank = Int
climbingLeaderboard :: [Score] -> [Score] -> [Rank]
climbingLeaderboard scores alice = let scoreRank = denseRank scores
aliceDesc = reverse alice
in reverse (rankSeries scoreRank aliceDesc)
denseRank :: [Score] -> [(Rank, Score)]
denseRank scores = go scores 1
@mvaldesdeleon
mvaldesdeleon / building-with-types.ts
Created August 2, 2020 00:20
Building with Types, draft
// Building with Types
// Lets imagine we have two types, for example Number and String.
// In which ways could we combine them, just one of each, to create a different type?
// How could we do this?
// Well... we could create an object:
type Person = {name: string, age: number};
@mvaldesdeleon
mvaldesdeleon / types-as-sets.ts
Created August 1, 2020 18:32
Types as Sets, draft
// Types as Sets, containing Values
// Union and Intersection Types can be thought as unions and intersections of the underlying Sets
// Type Compatibility can be thought of a subset relationship between the underlying Sets
//
// Usual Set concepts apply, such as:
// cardinality (the number of possible values of a given type)
// ø (empty set)
// unions, intersections, subsets, supersets, sums, products
//
// Lets look at some types...
@mvaldesdeleon
mvaldesdeleon / .aws_config
Created November 28, 2019 20:20
"credential_source=Ec2InstanceMetadata" workaround
[profile target-account]
role_arn = arn:aws:iam::123456789012:role/RoleInTargetAccount
source_profile = instance-role
region = eu-central-1
set nocompatible
set noswapfile
set number
set cursorline
set encoding=utf-8
syntax enable
filetype plugin indent on
set tabstop=4
set shiftwidth=4
data Player = Player
{ _name :: String
, _hitPoints :: Integer
, _attackPoints :: Integer
}
type Game = [Player]
playerTurn :: Player -> State Game ()
playerTurn p = do
result = foo . bar . baz $ value
result1 = foo $ bar $ baz $ value
result2 = foo $ bar . baz $ value
result3 = foo (bar . baz $ value)
result4 = (foo . bar) (baz value)
data Position = Position
{ _x :: Integer
, _y :: Integer
} deriving (Show, Eq)
-- We want to sort by Y first, and then by X, so we need a custom Ord instance
instance Ord Position where
Position x0 y0 <= Position x1 y1 =
if y0 /= y1
then y0 <= y1