An anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once
For example:
Create a new project using mix new anagram then let's write some test cases:
defmodule AnagramTest do
use ExUnit.Case
test "calculates anagram" do
assert Anagram.anagram?("restful", "fluster") == true
assert Anagram.anagram?("funeral", "realfun") == true
assert Anagram.anagram?("adultery", "truelady") == true
assert Anagram.anagram?("customers", "storescum") == true
assert Anagram.anagram?("fortyfive", "overfifty") == true
assert Anagram.anagram?("fiftyfive", "overfifty") == false
assert Anagram.anagram?("funeral", "real fun") == false
end
end
Now we have to write the code:
defmodule Anagram do
def anagram?(a, b) do
charlist(a) == charlist(b)
end
def charlist(w) do
w |> String.trim() |> String.downcase() |> String.graphemes() |> Enum.sort()
end
end
Run the tests mix test:
Compiling 1 file (.ex)
Generated anagram app
.
Finished in 0.1 seconds
1 test, 0 failures
Randomized with seed 752850
Done, now you have an anagram calculator!
Simple ones javascript const [a, b, ...c] = [10, 20, 100,200] // a= 10, b=20, c=[100,200] const { first, second } = { first: 1, second: 2 } // first = 1, second = 2
Crazier one javascript const resp = { data: { message: 'hello', random: 'xxx', test:'hehe' } } const { data, data: { message, ...rest } = resp // data = { message: 'hello' }, message = 'hello' // rest = { random: 'xxx', test: 'hehe' }
$ git diff develop feature/one-signal --diff-filter=M --name-only -- *.rb | egrep -v 'db|config|spec' | xargs rubocop
You might be using dig to find out A/CNAME/MX etc records of a domain from DNS servers. But if you just want to get a quick overview, use host:
$ host oozou.com
oozou.com has address 52.89.55.136
oozou.com has address 35.165.206.160
oozou.com has address 34.212.209.65
oozou.com mail is handled by 1 aspmx.l.google.com.
oozou.com mail is handled by 5 alt1.aspmx.l.google.com.
oozou.com mail is handled by 5 alt2.aspmx.l.google.com.
oozou.com mail is handled by 10 aspmx2.googlemail.com.
oozou.com mail is handled by 10 aspmx3.googlemail.com.
If you want to attach a file you generated on disk or downloaded from a user-submitted URL, you can do it like this.
@model.image.attach(
io: File.open('/path/to/file'),
filename: 'file.pdf',
# content type is optional
content_type: 'application/pdf'
)
lst() {
if [ "$1" != "" ] # or better, if [ -n "$1" ]
then
ls -R $1 | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'
else
ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'
fi
}
sh source ~/.zshrc
sh lst spec
sh lst
bash spec/ ├── controllers/ │ └── users/ ├── models/ └── views/
css spec |--controllers | |--users |--models |--views
sh sudo apt-get install tree
sh brew install tree
sh tree spec
sudo scutil --set HostName "New Name"
sudo scutil --set LocalHostName "New Name"
sudo scutil --set ComputerName "New Name"
dscacheutil -flushcache
Ever wanted to shorten a git command? You can go with shell alilas for sure but you have to always include context so that you don't forget what each ailas stands for but you can define your own commands in git using aliases.
git config --global alias.
For example; I'm too lazy to type git status so I want to shorten this to git s
git config --global alias.s status
And here we go now you can just type git s and get the status of current repository.
Open term (or equivalent) and paste the following:
aws s3 cp source.file s3://bucket/path/dest.file --acl public-read
Options for --acl parameters are: