Skip to content

Instantly share code, notes, and snippets.

View pragdave's full-sized avatar
🖍️
Alternating between Haskell and PDP-11 assembler

Dave Thomas pragdave

🖍️
Alternating between Haskell and PDP-11 assembler
View GitHub Profile
@pragdave
pragdave / hanoi.tsx
Created February 20, 2023 18:54
Looking for feedback on my first Motion Canvas attempt
import {makeScene2D} from '@motion-canvas/2d/lib/scenes';
import {Rect, View2D} from '@motion-canvas/2d/lib/components';
import {createRef, Reference} from '@motion-canvas/core/lib/utils';
import { Color, Vector2 } from '@motion-canvas/core/lib/types';
const PoleLong = 201
const PoleShort = 25
const PoleBase = 150
const DiskCount = 5
const MinDiskWidth = 50
import Data.List (sort, intersperse, union)
import Data.Function ( (&) )
import System.Random (Random(randomRIO))
(|>) = (&) -- 'cos I'm too old to switch...
pickRandomWord :: [ String ] -> IO String
pickRandomWord words = do
rand <- randomRIO (0, length words - 1)
return (words !! rand)
@pragdave
pragdave / clapperboard.js
Created April 18, 2020 23:00
Trivial JS function to help sync sound and screen when recording a browser based screencast
export function clapperBoard() {
let audio = new AudioContext()
let beep = audio.createOscillator()
let flash = document.createElement("div")
beep.frequency.value = 440 * 5
beep.connect(audio.destination)
flash.classList.add("clapperboard")
beep.start()

Wow! Fantastic conference. I'm sure at the end we'll have a nice summary, so I'm not going gush too much.

But I must admit, I always enjoy these conferences, so thank you to everybody involved.

How many people have seen me speak at a previous elixir event? Oh, a fair number. «How many have heard me speak» twice?

All right, so the ones that have seen me speak are kind of nervous right now.

// swap the clauses in the following sentence
// the result will be "the world is your oyster, if you can program"
str1 = "if you can program, the world is your oyster"
// replace three or more trailing identical digits in a number wih just one
// digit and three dots, so 0.456666 becomes 0.456... and 124.3333 becomes
// 124.3... Numbers such as 124.33 and 124.35553 are left unchanged
str2a = "0.456666"
str2b = "124.3333"
str1 = "replace multiple spaces in this string with a single space"
str2 = "remove the decimal point and fractional parts of 3.14159 and 99.999."
str3 = "if words are 4 or more characters surrounded by spaces, replace words in this sentence with a single W"
str4 = "like str3 but now words must be between 4 and 6 characters"
str0 = "Does this string contain the word 'cat'?"
str1 = "what is the offset of the character X in this string?"
str2 = "Replace the first space in this string with a plus sign"
str3 = "Replace all spaces with plus signs in this string"
str4 = "What is the position of the first occurrence of two adjacent vowels in this string?"
str5 = "Delete ALL the Upper Case letters in this string"
ascending([]).
ascending([_]).
ascending([H | [ S | T ]]) :-
H < S,
ascending([S | T]),
!.
valid([P1, P2, P3]) :-
ascending(P1),
ascending(P2),
@pragdave
pragdave / anagram.fs
Last active December 13, 2019 18:03
/// <summary>
/// Builds a map where the keys are word signatures and
/// each value is the list of words that share that signature.
/// The signature of a word is simply a string containing
/// the word's letters, sorted. Thus "dog" and "god" will
/// both have the signature "dgo", and the entry in the map
/// with that key will be those two words.
///
/// This let's us quickly find anagrams
/// </summary>
@pragdave
pragdave / send_more_money.sql
Created September 23, 2019 18:43
naive implementation of the cryptoarithmetic puzzle SEND + MORE = MONEY
-- Solve SEND + MORE = MONEY
select S.i, E.i, N.i, D.i, M.i, O.i, R.i, Y.i
from digits S, digits E, digits N, digits D,
digits M, digits O, digits R, digits Y
where S.i != 0
and M.i = 1
and (S.i + M.i)*1000 + (E.i + O.i)*100 + (N.i + R.i)*10 + D.i + E.i
= M.i*10000 + O.i*1000 + N.i*100 + E.i*10 + Y.i
and S.i not in ( E.i, N.i, D.i, M.i, O.i, R.i, Y.i)