Here are commons ways to reuse logic in Elixir:
1a. Move Function to other module (guards, pattern-matching) 1b. Protocol - Polymorphism
- Behaviour Dynamic-func - with def method_name(implemetation, args)
| #!/usr/bin/env zsh | |
| curl -o commandlinetools-linux.zip https://dl.google.com/android/repository/commandlinetools-linux-11076708_latest.zip && unzip commandlinetools-linux.zip && rm commandlinetools-linux.zip |
| # Measure Bandwidth (using https://www.speedtest.net/apps/cli) | |
| #wget https://install.speedtest.net/app/cli/ookla-speedtest-1.2.0-linux-x86_64.tgz -O /tmp/speedtest.tgz | |
| wget https://install.speedtest.net/app/cli/ookla-speedtest-1.2.0-linux-aarch64.tgz -O /tmp/speedtest.tgz | |
| tar -xzvf /tmp/speedtest.tgz -C /usr/sbin/ | |
| rm -f /tmp/speedtest.tgz /usr/sbin/speedtest.* | |
| chmod +x /usr/sbin/speedtest | |
| /etc/init.d/qosify stop | |
| speedtest --format=tsv > /tmp/speedtest.tsv && | |
| BANDWIDTH_DOWN="$(($(cut -f6 /tmp/speedtest.tsv) / 125000))mbit" && |
| # Install asdf | |
| brew install coreutils git | |
| git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.12.0 | |
| cat <<EOF >> ~/.zshrc | |
| . "$HOME/.asdf/asdf.sh" | |
| # append completions to fpath | |
| fpath=(${ASDF_DIR}/completions $fpath) | |
| # initialise completions with ZSH's compinit | |
| autoload -Uz compinit && compinit | |
| EOF |
| FROM keybaseio/client:stable-slim | |
| RUN apt-get update && apt-get install -y expect | |
| COPY keybase-provision.sh /provision.sh | |
| RUN chmod +x /provision.sh | |
| CMD ["/provision.sh", "keybase", "chat", "send", "--channel", "'#general'", "stockbitcrypto", "'Hello World from bot'"] |
| package main | |
| import ( | |
| "fmt" | |
| "net/http" | |
| "time" | |
| "github.com/aws/aws-sdk-go/aws" | |
| "github.com/aws/aws-sdk-go/aws/credentials" | |
| "github.com/aws/aws-sdk-go/aws/session" |
| defmodule FlattenArray do | |
| @doc """ | |
| Accept a list and return the list flattened without nil values. | |
| ## Examples | |
| iex> FlattenArray.flatten([1, [2], 3, nil]) | |
| [1,2,3] | |
| iex> FlattenArray.flatten([nil, nil]) |
| package main | |
| import ( | |
| "bytes" | |
| "encoding" | |
| "encoding/binary" | |
| "io" | |
| "fmt" | |
| "stockbit.com/proto/ouch42" |