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
grep -rh '^[[:space:]]*\(class\|module\)\b' api/app api/lib --include='*.rb' | sed 's/^[[:space:]]*//' | cut -d ' ' -f 2 | while read class; do echo "`grep -rl "\b$class\b" api/app api/lib --include="*.rb" | wc -l` $class"; done | sort -n |
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
# see here: https://superuser.com/questions/1106674/how-to-add-blank-lines-above-the-bottom-in-terminal#_=_ | |
# the n flag on echo eliminates new line, e flag interprets the exit codes | |
# echo -ne "\eD" moves down and scrolls the viewport | |
# echo -ne "\eM" moves up and scrolls the viewport if necessary | |
# "\e[B" and "\e[A" move up and down respectively constraining within the viewport | |
# for those two there are multipliers: "\e[3A" will repeat "\e[A" 3 times | |
# tput lines returns us the current number of rows in the viewport - i.e. how tall it is. | |
# this just doesnt seem to work |
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 Square do | |
defstruct [:side] | |
def area(%Square{side: side}) do | |
side * side | |
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
defmodule Circle do | |
defstruct [:radius] | |
def area(%Circle{radius: radius}) do | |
radius * radius * 3.14 | |
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
Square.area(%Square{side: 10}) | |
Circle.area(%Circle{radius: 10}) |
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 Project do | |
def total_cost(shape, cost_per_square_meter) do | |
# code goes here …. | |
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
defmodule Project do | |
def total_cost(shape, cost_per_square_meter) do | |
case shape do | |
%Square{} -> Square.area(shape) * cost_per_square_meter | |
%Circle{} -> Circle.area(shape) * cost_per_square_meter | |
end | |
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
defmodule Project do | |
def total_cost(shape = %Square{}, cost_per_square_meter) do | |
Square.area(shape) * cost_per_square_meter | |
end | |
def total_cost(shape = %Circle{}, cost_per_square_meter) do | |
Circle.area(shape) * cost_per_square_meter | |
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
defmodule Project do | |
def total_cost(shape, cost_per_square_meter) do | |
Shape.area(shape) * cost_per_square_meter | |
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
defprotocol Shape do | |
def area(shape) | |
end |
OlderNewer