Skip to content

Instantly share code, notes, and snippets.

View glebec's full-sized avatar
🥃
Slàinte

Gabriel Lebec glebec

🥃
Slàinte
View GitHub Profile
@glebec
glebec / Main.hs
Created January 29, 2024 04:48
Red-Green vs Red-Red
module Main where
{-
This is a simulation of a problem posed by Daniel Litt in a tweet:
https://twitter.com/littmath/status/1751648838501224790
> You are given an urn containing 100 balls; n of them are red, and
> 100-n are green, where n is chosen uniformly at random in [0, 100].
> You take a random ball out of the urn—it’s red—and discard it. The
> next ball you pick (out of the 99 remaining) is:
@glebec
glebec / lambda-talk-qa.md
Created October 18, 2019 17:27
Smartly.io DevTalks - Lambda Calculus post-talk Q&A

Lambda Calculus Q&A

These are my responses to some of the questions asked at the end of my Lambda Calculus talk, held on 2019-10-15 at Smartly.io's DevTalks in Helsinki. I've grouped similar questions together.

Books and Resources

  • What's the one encompassing book you would recommend to read on this very interesting topic?
  • Can you recommend a book (or books) that cover some of the history you shared in more detail?
  • So what IS the book to read to get into understanding all of this?
@glebec
glebec / absurd-haskell.hs
Last active July 28, 2019 17:48
Absurdity
module Absurd where
import Data.Void
-- Void is an empty type; there are values of type Void.
-- Example with incomplete pattern matching, which we should avoid on principle, and which
-- we can configure the compiler to yell about:
missingCase :: Either Void x -> x
missingCase eVR = case eVR of

Thunks

Needs Statement

Thunks are a popular way to avoid directly causing side effects in our actions, action creators, or components, thus allowing us to keep the rest of our application pure (easier to test, reason about, re-use). Thunks are the simplest way to deal with AJAX requests in a redux application.

Objectives

High-Level

  • Students will understand the need to isolate side-effects to a particular stage of the redux cycle.
@glebec
glebec / scott-encoding.js
Last active August 16, 2019 20:07
Scott Encoding
/**
* -- Haskell `Maybe` type:
* data Maybe a = Nothing | Just a
*/
// JS Scott-Encoding-inspired `Maybe` definition
// (NB, true Scott encoding uses closures rather than a record – see gist comment)
const Maybe = {
Nothing: whatToDoInEachCase => {
@glebec
glebec / lenses.js
Last active January 25, 2019 23:06
Lenses in JS
/**
* Van Laarhoven Lenses in JavaScript
* by Gabriel Lebec (https://github.com/glebec)
*
* Based on https://www.codewars.com/kata/lensmaker
* See also https://github.com/ekmett/lens/wiki/History-of-Lenses
*/
/**
* Composition and Combinators
@glebec
glebec / monadic-parser.js
Last active June 2, 2021 10:22
Monadic Parser demo
/**
* Minimal demo of parser combinators, possibly as a target for recent
* JS web dev graduates to implement as an exercise.
*
* Huge credit to Hutton, Meijer, and Swierstra for their papers
* on the subject.
*/
class Parser {
@glebec
glebec / travis-build-from-dev.md
Created March 1, 2018 05:36
Fast Travis deployment with build from dev dependencies

Fast Travis Build & Heroku Deployment

Below is a sample .travis.yml which:

  • Uses dist: trusty + sudo: false to enable fast Docker containers
  • Uses npm ci to install quickly before testing
  • Builds from modules in devDependencies
  • Includes the build in the deployment
  • Omits node_modules (smaller tarball & no Heroku warning)
@glebec
glebec / books.md
Last active December 6, 2021 04:09 — forked from joedotjs/gist:2807153d0d6dcdfde00d
Books and Resources
@glebec
glebec / debugging.md
Last active May 31, 2023 21:18
Debugging

Debugging JavaScript Applications

A practical distillation for Fullstack Academy students

Faults in computer problems were theorized as far back as 1843, when Ada Lovelace noted of Babbage's Analytical Engine, "Granted that the actual mechanism is unerring in its processes, the cards may give it wrong orders." Almost 160 years later, NIST reported that software errors cost the US $59 billion annually. Clearly, some of the cards are wrong. However, unlike Grace Hopper's famous moth, most of the time the culprit is ourselves.

Debugging is a sanitization procedure consisting of:

  • Preventing bugs in the first place, through good practices and assistive tooling.
  • Detecting bugs when they first arise, through proper error handling and testing.