Skip to content

Instantly share code, notes, and snippets.

@tdd
tdd / gitconfig.ini
Last active April 17, 2024 10:04
Nice, useful global Git configuration
# Put this in your ~/.gitconfig or ~/.config/git/config
# Windows users: "~" is your profile's home directory, e.g. C:\Users\<YourName>
[user]
name = Your Full Name
email = your@email.tld
[color]
# Enable colors in color-supporting terminals
ui = auto
[alias]
# List available aliases
@shimizukawa
shimizukawa / ext_ctags.py
Created November 30, 2012 03:38
ctags file generator for sphinx
# -*- coding: utf-8 -*-
import os
def doctree_resolved(app, doctree, docname):
filename = os.path.join(app.confdir, app.config.ctags_filename)
# load existent ctag
ctags = load_ctag(filename)
---------------------------- MODULE Deployments ----------------------------
EXTENDS TLC, Integers
CONSTANT UPDATING, CORRUPT, ABORTED
CONSTANT SKIP_UPDATE
(* --algorithm deploy
variables servers = {"s1", "s2", "s3"},
load_balancer = servers,
Note'Copyright'
Copyright (C) 2017 Xiao-Yong Jin. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

Python’s lru_cache is sensitive to order of keyword arguments

In case you were wondering, Python’s built-in LRU cache function decorator doesn’t cache function calls with the same keyword arguments written in a different order. That is, if you cache a function and then call it twice, with the same keyword arguments but written in a different order, on the second call you won’t get the cached result and the function will be re-run.

proof/example

Let’s construct an example. We’re interested in keyword arguments, so we’ll make our function only take keyword arguments (1). We want some side-effect to tell us whether it was a cache hit or miss, so we’ll print each keyword when we iterate over it (2). We want to cache a result, so we’ll return the sum of the values of the keyword arguments (3). Finally, we apply the lru_cache decorator to the function with a maxsize=None to let the cache grow unbounded. Putting all that together, we get:

@valpackett
valpackett / left-pad.mlw
Last active April 26, 2018 05:29
Left-pad verified with Why3
module LeftPad
use import int.Int
use import int.MinMax
use import string.Char as C
use import map.Map as M
use import string.String as S
use import string.Buffer as B
(* string.Buffer.contents only does the length for some reason *)
val buf2str (b: B.t) : string

The Cabal/Stack Disambiguation Guide

One of the most frequently asked Haskell beginner questions in recent years is:

"Stack or cabal?"

I will helpfully not answer this question. Instead I will hope to eliminate the confusion that many of the askers seem to have about the various different

@jackfoxy
jackfoxy / DecisionTables.fsx
Created September 18, 2020 21:20
A demo of decision tables using F# types and pattern matching
(*
Decision Table Demo
MIT License, do with this what you will
A demo of decision tables using F# types and pattern matching, inspired by https://www.hillelwayne.com/post/decision-table-patterns/
The compiler service flags problematic (incomplete) decision tables.
Requirements: