Skip to content

Instantly share code, notes, and snippets.

View gfarrell's full-sized avatar
👾

Gideon Farrell gfarrell

👾
View GitHub Profile
@gfarrell
gfarrell / Htmx.hs
Created February 27, 2024 21:50
Playing with HTMX
{-# LANGUAGE ExtendedDefaultRules #-}
{- cabal:
build-depends: base, wai, warp, lucid, http-types, text, bytestring
-}
{-# LANGUAGE OverloadedStrings #-}
import Data.ByteString (ByteString)
import Data.Text (Text, intercalate)
import Data.Text.Encoding (decodeUtf8)
import Lucid (Attribute, Html, ToHtml (toHtml), renderBS)
@gfarrell
gfarrell / FunDeps.hs
Last active March 2, 2023 22:12
Explaining functional dependencies in Haskell
{- stack script --resolver lts-20.5 -}
-- @FunctionalDependencies@ is a useful extension allowing us to resolve the
-- ambiguity inherently arising in multi-parameter typeclasses. Such typeclasses
-- can be useful, but sometimes unergonomic as it can be impossible to solve for
-- certain type variables.
--
-- For a multiparam typeclass @X@ over two parameters @a@, @b@, there is a
-- potentially infinite combination of @a@s and @b@s. This means that if I
-- have a member function @f :: X a b => a -> b@ then I can't know the type
@gfarrell
gfarrell / promises-as-monads.ts
Created April 18, 2022 16:17
Can we treat Promises as Monads?
// Proposition: Promise is equivalent to a loosely typed `ExceptT e IO a` for
// javascript, and fundamentally obeying the monad laws, making it a
// helpful construction for writing computations.
// class Monad m where
// return :: a -> m a
// (>>=) :: m a -> (a -> m b) -> m b
//
// Monad laws:
// Left identity: return a >>= f ≡ f a
@gfarrell
gfarrell / results.txt
Last active June 29, 2017 15:54
Sorting performance: Strings VS. Numbers
~/sandbox > node strings-vs-ints.js 1000000 32
Sorting 1000000 numbers of magnitude 10^32
Sorting 1000000 strings of length 32
Numbers: 461
Strings: 1445
~/sandbox > node strings-vs-ints.js 1000000 32
Sorting 1000000 numbers of magnitude 10^32
Sorting 1000000 strings of length 32
Numbers: 494
Strings: 1500
@gfarrell
gfarrell / dabblet.css
Created October 4, 2013 17:33
Untitled
select {
padding: 0.5em;
}
@gfarrell
gfarrell / enum.js
Last active December 24, 2015 00:29
Create Enums in Javascript (immutable dictionaries of string:int pairings).
/* global define */
/**
* Enums in Javascript
*
* Makes an immutable dictionary with string:int pairings to emulate Enums.
* Usage example: Colours = Enum('RED', 'GREEN', 'BLUE');
*
* @author Gideon Farrell <me@gideonfarrell.co.uk>
*
*/
@gfarrell
gfarrell / dabblet.css
Created August 21, 2013 15:29
Untitled
.clear { clear: both; }
.authenticationWidget {
position: relative;
font-family: Helvetica Neue;
font-size: 0.9em;
}
h2 {
margin: 30px 0 0 10px;
1) No custom signatures
2) Spam now shows up in my inbox
3) If I archive something on my computer, mailbox doesn't have it archived; it's still in my inbox
4) No label support (I use labels to categorise EVERYTHING, and it's really important to my organisation)
... I'll add to this as I go along
@gfarrell
gfarrell / remote_backup.sh
Created October 22, 2012 17:20
Backs up database and files to given remote server via scp
#!/bin/bash
##########################################################
# Remote Backup Script
#
# FILE: remote_backup.sh
# RUN: Daily 00h00
#
# author: Gideon Farrell me@gideonfarrell.co.uk
##########################################################
$(window).on('load', function() {
var fragment = window.location.hash;
if(fragment != "") {
$('body').animate({
scrollTop: $(fragment).offset().top
});
}
});