Skip to content

Instantly share code, notes, and snippets.

@antonycourtney
antonycourtney / goodreads-cleanup.sql
Last active January 15, 2023 23:01
Parquet cleaning example in DuckDb SQL
-- This should all work with the DuckDb shell CLI, available from https://duckdb.org/docs/installation/index
-- (Select the CLI tab)
-- first create a view on the Parquet file:
CREATE VIEW books AS SELECT * from './goodreads_books.parquet';
-- take a look at the schema:
PRAGMA table_info(books);
-- Fix up one of the columns (book_id), converting it from VARCHAR to INTEGER (int32):
@antonycourtney
antonycourtney / fruit-reflections-2008.md
Last active November 6, 2017 05:41
Reflections on why Fruit (A prototype Functional Reactive UI Toolkit for Haskell) never took off (2008)
@antonycourtney
antonycourtney / flow-lambda-bug.js
Created March 31, 2017 02:10
Flow data flow analysis loses info under a lambda
/* @flow */
/* Paste this into https://flow.org/try/ to see the bug: */
const f = (lut: ?{[key: string]: number}): number => {
// This correctly notices that we're doing a null check on lut:
const testKey = 'fizz'
const y = (lut != null) ? lut[testKey] : 0
@antonycourtney
antonycourtney / Timer.js
Created January 4, 2017 18:11
Example of maintaining Timer state for use in React
/* @flow */
import * as Immutable from 'immutable'
/**
* A timer object for use in OneRef-based immutable state
*
*/
export type TimerUpdater = (f: (ts: Timer) => Timer) => void
@antonycourtney
antonycourtney / interp.lhs
Last active May 5, 2016 19:25
My own notes and exercises written while reading Wadler's wonderful "Monads for Functional Programming" in 1998
A really simple interpreter to use while learning about monads. Based on
the paper "Monads for Functional Programming" by Phil Wadler.
the type of terms:
> data Term = Con Int
> | Div Term Term
> deriving Show
@antonycourtney
antonycourtney / FunPix.hs
Created March 4, 2016 23:47
Layout thought of as an attribute grammar, encoded in Haskell
--
-- Some experiments with a Picture type based on an attribute-grammar
-- model of Layout
module FunPic where
import Haven
-- A type for representing the dimensions of a rectangle, as (width,height)
type Dimension = (Double,Double)
@antonycourtney
antonycourtney / DiamondExample.md
Last active May 6, 2024 05:21
A real world example of recombinant / diamond wiring and feedback with RxJS

A realistic RxJS app with diamond wiring

Consider the following user interface (inspired by Strava) for looking at time-series charts of network data:

esnet-estes-charts

Notes on this interface and my Rx implementation of it:

  • Each chart (stacked vertically) charts a different metric (latency, packet loss and throughput) but over the same time period.
  • As the user moves the mouse left and right on any chart, the vertical line (called the tracker) moves to track the mouse position on all charts. The number displayed in the gray box on the right is the value underneath the tracker for that metric.
@antonycourtney
antonycourtney / Example1.elm
Last active November 8, 2015 06:00
Animaxe Example 1 in Elm
import Color exposing (..)
import Graphics.Collage exposing (..)
import Graphics.Element exposing (..)
import List exposing (..)
import Signal exposing (..)
import Time exposing (..)
import Array
-- a square of the given width and color:
square : Float -> Color -> Form
@antonycourtney
antonycourtney / invokeLater.js
Last active October 19, 2015 03:11
invokeLater for oneref
function invokeLater(f) {
window.setTimeout(f, 0);
}
@antonycourtney
antonycourtney / scrollAction.js
Created October 15, 2015 06:32
scroll action in oneref-flux-challenge
export function scroll(scrollAmount,updater) {
updater((prevState) => {
const {nextState, oldRequests} = prevState.scrollAdjust(scrollAmount);
oldRequests.forEach((req) => req.abort()); // cancel old requests
// Need invokeLater since we're within updater
invokeLater(() => fillView(nextState,updater));
return nextState;
});
}