Skip to content

Instantly share code, notes, and snippets.

@wbadart
wbadart / free_vars.py
Created February 17, 2023 16:52
Find free variables in a Python expression
"""Tools to find free variables in an expression.
>>> import ast
>>> my_expr = ast.parse("x + (lambda x, y: x + y + z)(5, 9)").body[0].value
>>> reduce_ast(my_expr, free_vars, merge_free_name_sets, state=frozenset())
{'z', 'x'}
"""
import ast
import functools
@wbadart
wbadart / tf-debug.txt
Created September 28, 2022 17:17
TF_LOG=DEBUG terraform apply -auto-approve -no-color
2022-09-28T11:16:25.185-0600 [INFO] Terraform version: 1.3.0
2022-09-28T11:16:25.185-0600 [DEBUG] using github.com/hashicorp/go-tfe v1.9.0
2022-09-28T11:16:25.185-0600 [DEBUG] using github.com/hashicorp/hcl/v2 v2.14.0
2022-09-28T11:16:25.185-0600 [DEBUG] using github.com/hashicorp/terraform-config-inspect v0.0.0-20210209133302-4fd17a0faac2
2022-09-28T11:16:25.185-0600 [DEBUG] using github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734
2022-09-28T11:16:25.185-0600 [DEBUG] using github.com/zclconf/go-cty v1.11.0
2022-09-28T11:16:25.185-0600 [INFO] Go runtime version: go1.18.5
2022-09-28T11:16:25.185-0600 [INFO] CLI args: []string{"terraform", "apply", "-auto-approve", "-no-color"}
2022-09-28T11:16:25.185-0600 [DEBUG] Attempting to open CLI config file: /Users/williambadart/.terraformrc
2022-09-28T11:16:25.185-0600 [DEBUG] File doesn't exist, but doesn't need to. Ignoring.
<!DOCTYPE html>
<!-- TODO: Main navigation links (Home, index, tags, ...) --><!-- DoNotFormat -->
<!-- DoNotFormat -->
<html lang='en'>
<head>
<meta charset='UTF-8' />
<meta name='viewport' content='width=device-width, initial-scale=1' />
<title>
#!/bin/sh
security_endpoint="query?function=TIME_SERIES_DAILY&symbol=%s&apikey=$ALPHAVANTAGE_API_KEY"
security_jsonpath='.["Time Series (Daily)"] as $res
| ($res | keys | last) as $latest
| $res[$latest] | .["4. close"]'
crypto_endpoint="query?function=CURRENCY_EXCHANGE_RATE&from_currency=%s&to_currency=USD&apikey=$ALPHAVANTAGE_API_KEY"
crypto_jsonpath='.["Realtime Currency Exchange Rate"]
| .["8. Bid Price"]'
{-# LANGUAGE LambdaCase #-}
module Lib where
import Data.Char
import Data.List.NonEmpty ( NonEmpty )
import Validation
data PasswordError
= TooShort
@wbadart
wbadart / Anamorphism.hs
Created November 12, 2020 22:32
Example of using an anamorphism (with helper catamorphism)
{-# LANGUAGE BlockArguments,DeriveFunctor,LambdaCase,ScopedTypeVariables,NoImplicitPrelude #-}
import Control.Arrow
import Prelude hiding (replicate)
newtype Fix f = In { out :: f (Fix f) }
type FAlgebra f a = f a -> a
cata :: (Functor f) => FAlgebra f a -> Fix f -> a
cata f = out >>> fmap (cata f) >>> f
@wbadart
wbadart / environment.yaml
Created April 24, 2020 15:10
Coverage bug for numba-jit'd functions
name: numbatest
channels:
- defaults
dependencies:
- _libgcc_mutex=0.1=main
- attrs=19.3.0=py_0
- blas=1.0=mkl
- ca-certificates=2020.1.1=0
- certifi=2020.4.5.1=py38_0
- coverage=5.0=py38h7b6447c_0
@wbadart
wbadart / Main.hs
Last active April 13, 2020 17:08
Probability newtype with smart constructor and unidirectional pattern example
module Main where
import Data.Probability
main :: IO ()
main = do
s <- readLn
case probability s of
-- This pattern match wouldn't work w/o PatternSynonyms
-- (you could still pattern match on the Maybe, but not on
module Graph where
import Data.Function (on)
import Data.List (deleteBy)
data Edge v id_ payload = Edge (v, v) id_ payload
deriving Show
data Graph v id_ payload = Graph [v] [Edge v id_ payload]
deriving Show
@wbadart
wbadart / Makefile
Created October 8, 2018 14:51
Comparing two recursive ways to test linked list equivalence
N=1000000
M=1000000
M2=1000001
compare: node.o compare.o main.o
$(CC) $^ -o $@
compare_tail: node.o compare_tail.o main.o
$(CC) $^ -o $@