compiled by learn.co community
This file contains 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
default: &default | |
adapter: postgresql | |
pool: 5 | |
timeout: 5000 | |
encoding: unicode | |
development: | |
<<: *default | |
database: app_name_development |
- https://learn.co/curriculum/tracks/17595/lessons/17604
- https://learn.co/lessons/hs-cli-cultural-piece
ruby -e 'C=`stty size`.scan(/\d+/)[1].to_i;S=["2743".to_i(16)].pack("U*");a={};puts "\033[2J";loop{a[rand(C)]=0;a.each{|x,o|;a[x]+=1;print "\033[#{o};#{x}H \033[#{a[x]};#{x}H#{S} \033[0;0H"};$stdout.flush;sleep 0.1}'
Open your Mac Terminal and run the following commands.
Hint: you can run the commands by copying and pasting them into your terminal, then hitting the Enter/Return key.
ruby -e 'C=`stty size`.scan(/\d+/)[1].to_i;S=["2743".to_i(16)].pack("U*");a={};puts "\033[2J";loop{a[rand(C)]=0;a.each{|x,o|;a[x]+=1;print "\033[#{o};#{x}H \033[#{a[x]};#{x}H#{S} \033[0;0H"};$stdout.flush;sleep 0.1}'
This file contains 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
export const displayName = (user) => { | |
if (user.firstName.length > 0) { | |
if (user.lastName.length > 0) { | |
return `${user.firstName} ${user.lastName}`.trim(); | |
} else { | |
return `${user.firstName}`.trim(); | |
} | |
} else if (user.username.length > 0) { | |
return user.username; | |
} else { |
This file contains 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
def display_name(user) | |
if user.first_name.length > 0 | |
if user.last_name.length > 0 | |
"#{user.first_name} #{user.last_name}".strip | |
else | |
"#{user.first_name}".strip | |
end | |
elsif user.username.length > 0 | |
user.username | |
else |
This file contains 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 Account do | |
def display_name(%{first: first, last: last}) do | |
String.trim("#{first} #{last}") | |
end | |
def display_name(%{username: username}), do: "#{username}" | |
def display_name(_), do: "New User" | |
end |
This file contains 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 Account do | |
# Unwieldy nil checks | |
def display_name(%{first: nil, last: nil, username: nil}) do | |
display_name(%{}) | |
end | |
def display_name(%{first: nil, last: nil, username: username}) do | |
display_name(%{username: username}) | |
end | |
def display_name(%{first: nil, last: nil}), do: display_name(%{}) |
This file contains 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 Account do | |
def display_name(%{first: first, last: last}) when not is_nil(first) do | |
String.trim("#{first} #{last}") | |
end | |
def display_name(%{username: username}) when not is_nil(username) do | |
"#{username}" | |
end | |
def display_name(_), do: "New User" | |
end |
This file contains 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
# Not recommended: macros | |
defmodule Account.Guards do | |
defmacro is_private(first_name, email) do | |
quote do | |
not(is_nil(unquote(first_name))) and | |
not(unquote(email) == unquote(first_name)) | |
end | |
end | |
end |
OlderNewer