Skip to content

Instantly share code, notes, and snippets.

@showell
showell / fib_rounding.py
Created April 24, 2023 12:59
Show rounding errors in Fibonacci series
import math
ROOT5 = math.sqrt(5)
PHI = (1 + ROOT5) / 2
def closed_fib(n):
v = (PHI**n) / ROOT5
return int(v)
@showell
showell / foo.md
Last active November 10, 2019 18:26
Elm values and functions

If you're coming from a language like or JavaScript (JS) or Python, you may used to be a mental model where functions (or lambdas) can actually have zero parameters. In those languages nothing gets evaluated until you invoke the functions.

zero parameters

Here's JS:

@showell
showell / foo.md
Last active November 10, 2019 18:17

If you're coming from a language like or JavaScript (JS) or Python, you may used to be a mental model where functions (or lambdas) can actually have zero parameters. In those languages nothing gets evaluated until you invoke the functions.

zero parameters

Here's JS:

@showell
showell / foo.txt
Created November 10, 2019 18:07
Elm functions vs. Elm values
If you're coming from a language like or JavaScript (JS) or Python, you may
used to be a mental model where functions (or lambdas) can actually have
zero parameters. In those languages nothing gets evaluated until you
invoke the functions.
## zero parameters
Here's JS:
~~~ js
@showell
showell / .bashrc
Created November 22, 2017 17:14
bashrc
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac
syntax on
set ai et sw=4 ts=4 softtabstop=4
set number
set backspace=indent,eol,start
set wildmenu
set wildmode=longest:full,full
autocmd BufWritePre *.py :%s/\s\+$//e
@showell
showell / towers.arr
Created May 21, 2016 17:12
towers of hanoi in pyret
fun hanoi(num-disks :: Number%(num-is-integer)) -> List:
doc: "Solve the Towers of Hanoi puzzle"
# our pegs are labeled 1, 2, and 3
# our disks are labeled 1 to num-disks, where disk 1 is
# the smallest disk
fun _hanoi(n, from-peg, target-peg):
if n == 0:
[list:]
else:
# The way Hanoi works is that you recursively move all
@showell
showell / combos.arr
Last active May 21, 2016 00:42
generating list combinations in pyret
# This program is inspired by the following webpage:
#
# https://rosettacode.org/wiki/Combinations
fun combos(lst :: List, size :: Number) -> List:
# return all subsets of lst of a certain size,
# maintaining the original ordering of the list
# Let's handle a bunch of degenerate cases up front
# to be defensive...
fun is-balanced-int-list(lst :: List, start_sum :: Number) -> Boolean:
doc:
"returns true iff the running sum of a list of "
"integers stays nonnegative and finishes at zero."
# Perhaps overly abstracting a bit, we model the balanced
# parentheses problem in terms of a list of integers and
# their running sum.
#
# For the concrete case of balancing parentheses, this effectively
@showell
showell / gist:7793101
Created December 4, 2013 18:42
Python program to extract data structures from handlebars templates
#!/usr/bin/env python
import sys
import re
import json
def debug(obj):
print(json.dumps(obj, indent=4))
def parse_file(fn):
text = open(fn).read()