Skip to content

Instantly share code, notes, and snippets.

View BrooklinJazz's full-sized avatar

Brooklin Myers BrooklinJazz

View GitHub Profile
@BrooklinJazz
BrooklinJazz / big-o.md
Last active May 17, 2022 01:42 — forked from PJUllrich/big-o.md
Big-O Time Complexities for Elixir Data Structures

Big-O Time Complexities for Elixir data structures

Map [1]

Operation Time Complexity
Access O(log n)
Search O(log n)
Insertion O(n) for <= 32 elements, O(log n) for > 32 elements [2]
Deletion O(n) for <= 32 elements, O(log n) for > 32 elements
<!-- livebook:{"autosave_interval_s":null,"persist_outputs":true} -->
# Data Types
## Basic Types
@BrooklinJazz
BrooklinJazz / function_order.ex
Last active September 12, 2021 07:09 — forked from rodrigues/function_order.ex
Sort module functions alphabetically
defmodule Aplicar.Checks.SortModuleFunctions do
use Credo.Check,
base_priority: :low,
explanations: [
check: """
Alphabetically ordered lists are more easily scannable by the read.
# preferred
def a ...
def b ...
def c ...
@BrooklinJazz
BrooklinJazz / tags.ex
Created June 19, 2021 17:53
Elixir example for module, describe, and test tags.
defmodule Example do
use ExUnit.Case
@moduletag :module_tag_name
describe "example describle" do
@describetag :describe_tag_name
@tag :test_tag_name
test "example test" do
assert true
@BrooklinJazz
BrooklinJazz / case_variables.ex
Created June 8, 2021 15:50
Elixir example of case variables
case {:ok, 5} do
{:ok, n} -> "this will match and n is 5: #{n}"
{:error, n} -> "this will not match"
end
@BrooklinJazz
BrooklinJazz / pipe.ex
Last active June 8, 2021 15:38
Elixir Pipe Example
# the first argument for string.split is the return value of String.upcase("Hello Brooklin")
# for functions with more than 1 parameter such as String.split,
# skip the first argument because it's provided implicitly by the Pipe |>
"Hello Brooklin" |> String.upcase |> String.split(" ")
@BrooklinJazz
BrooklinJazz / optional_brackets.ex
Created June 8, 2021 01:10
Elixir example with no brackets
defmodule Greeting do
def say_hello name, name2 do
"Hello #{name}, Hi #{name2}"
end
end
Greeting.say_hello "Bob", "Bill" # Hello Bob, Hi Bill
@BrooklinJazz
BrooklinJazz / use.ex
Created June 8, 2021 01:02
Elixir use example with ExUnit.Case
defmodule AssertionTest do
use ExUnit.Case, async: true
test "always pass" do
assert true
end
end
@BrooklinJazz
BrooklinJazz / import.ex
Created June 8, 2021 00:50
Elixir import example
defmodule Greeting do
# syntax: import ModuleName only: [method_name: number_of_parameters]
import IO, only: [puts: 1]
def print_greeting(name) do
puts "Hello " <> name
end
end
Greeting.print_greeting("Brooklin") # Hello Brooklin
@BrooklinJazz
BrooklinJazz / alias.ex
Last active June 8, 2021 00:29
Elixir example of alias
defmodule Me do
defmodule Info do
def name do
"Brooklin"
end
end
end
defmodule Greeting do
alias Me.Info, as: Info