From the Polaris easter egg hunt 2025
defmodule Tesser do
defstruct [:position, :symbols, :treasure_positions]
class Stack | |
class Empty < RuntimeError; end | |
def initialize | |
@items = [] | |
end | |
def empty? | |
@items.count == 0 |
text | |
|> String.split("\n") | |
|> Enum.reduce({["{"], " "}, fn line, {output, current_indent} -> | |
case Regex.run(~r/^( +)(.*): ?(.*)/, line, capture: :all_but_first) do | |
[indent, key, ""] -> | |
close_braces = | |
if indent < current_indent do | |
Enum.map_join( | |
(String.length(current_indent) - 4)..String.length(indent)//-4, | |
"", |
#!/usr/bin/env elixir | |
Mix.install([ | |
{:httpoison, "~> 1.8"}, | |
{:jason, "~> 1.3"} | |
]) | |
defmodule Space do | |
def run do | |
fetch_data() |
defmodule MyApp.Repo do | |
require Logger | |
alias Ecto.Association.NotLoaded | |
alias Ecto.{Changeset, Schema} | |
alias MyApp.Auth.User | |
... | |
@doc """ | |
Wrapper round `Ecto.Repo.insert/2`, which logs the fields of the inserted |
A spike looking at adding basic given-when-then steps to ExUnit tests.
given_
, when_
and then_
(unfortunately when
is a reserved word)defwhen
etc with a string matching the one used in the stepargs
variabledefmodule Child do | |
def task(parent) do | |
Process.sleep(:timer.seconds(2)) | |
send(parent, :finished) | |
end | |
end |
ytd() { | |
ytd=$(find ~/Dropbox/Apps/tapiriik -name $(date +%Y)-*_Running*.tcx -print0 | xargs -0 -n1 awk '/DistanceMeters/ {a=$0} END {gsub(/\s*<[^>]*>/, "", a); print a}' | paste -sd+ - | sed 's/\(.*\)/0.000621371 * (\1)/' | bc | sed 's/\(\..\).*/\1/') | |
proj=$(echo "$ytd * 365 / $(date +%j)" | bc) | |
echo "YTD: $ytd. Projected: $proj" | |
} |