Skip to content

Instantly share code, notes, and snippets.

View KMahoney's full-sized avatar

Kevin Mahoney KMahoney

View GitHub Profile
@KMahoney
KMahoney / arghh.ts
Created December 8, 2023 10:11
This was an annoying bug to find
class Bar {
constructor(public foo: Foo) {}
}
class Foo {
private cachedBar: Bar | null = null;
getBar() {
if (this.cachedBar !== null) return this.cachedBar;
this.cachedBar = new Bar(this);
@KMahoney
KMahoney / consistency.cfg
Created August 28, 2023 12:42
Focustro TLA+
CONSTANTS
ClientIds = {c1, c2}
ObjectIds = {o1, o2}
PropNames = {p1, p2}
Values = {v1, v2, v3}
NULL = NULL
MaxWrites = 3
MaxNetworkFailures = 2
SPECIFICATION Spec
// An example of integrating global state with React.
// Not necessarily recommended for production applications.
import { useSyncExternalStore } from "react";
// Define the application's state as a global variable
type State = { counter: number };
let state: State = { counter: 0 };
// React needs to know when the state changes so it knows when
{
"components": {
"schemas": {
"example": {
"required": [
"example",
"example3"
],
"type": "object",
"properties": {
module Main
import Data.Vect
import Data.Fin
%default total
find : Eq x => List x -> x -> Maybe Int
find [] elem = Nothing
find (y :: xs) elem = if y == elem then (Just 0) else (map (\ n => n + 1) (find xs elem))
-- So as an example of using a log orientated approach in PostgreSQL,
-- let's write a simple blog application. We will want to be able to:
-- * Write and edit blog posts
-- * Publish revisions of posts for public viewing
-- * Delete posts
-- * Add or remove tags to posts
-- Let's start by creating a schema.
use std::env::args;
use std::io::{Error, Read};
use std::fs::File;
fn run(filename : &str) -> Result<(), Error> {
let mut f = try!(File::open(filename));
let mut s = String::new();
try!(f.read_to_string(&mut s));
println!("{}", s);
return Ok(());
fn main() {
let mut arglist = args().skip(1);
match arglist.next() {
Some(ref filename) if arglist.count() == 0 => run(filename),
_ => usage()
}
}
(def-alias Zipper
(HMap :mandatory {:focus (U nil Node) :left (Vec Node) :right (Vec Node) :path Path :counter Integer}
:complete? true))
(ann left [Zipper -> Zipper])
(defn left [zipper]
(let [prev (peek (:left zipper))]
(if (nil? prev)
zipper
{:focus prev
input {
lumberjack {
'port' => '5005'
'ssl_certificate' => '/opt/logstash/certs/lumberjack.cert'
'ssl_key' => '/opt/logstash/certs/lumberjack.key'
'ssl_key_passphrase' => 'testing'
'type' => 'gocardless'
}
}