Mix.install([
{:kino, "~> 0.12.3"}
])
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Stack | |
class Empty < RuntimeError; end | |
def initialize | |
@items = [] | |
end | |
def empty? | |
@items.count == 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | |
"", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env elixir | |
Mix.install([ | |
{:httpoison, "~> 1.8"}, | |
{:jason, "~> 1.3"} | |
]) | |
defmodule Space do | |
def run do | |
fetch_data() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
- define tests as sequences of calls to
given_
,when_
andthen_
(unfortunatelywhen
is a reserved word) - match steps by calling
defwhen
etc with a string matching the one used in the step - interpolate values into step descriptions using {braces}
- placeholder variable names are available as methods on the magic
args
variable
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Child do | |
def task(parent) do | |
Process.sleep(:timer.seconds(2)) | |
send(parent, :finished) | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class RomanNumerals | |
NUMBERS = { | |
1000 => "M", | |
900 => "CM", | |
500 => "D", | |
400 => "CD", | |
100 => "C", | |
90 => "XC", | |
50 => "L", | |
40 => "XL", |
NewerOlder