defmodule MySigils do
#returns the downcasing string if option l is given then returns the list of downcase letters
def sigil_l(string,[]), do: String.Casing.downcase(string)
def sigil_l(string,[?l]), do: String.Casing.downcase(string) |> String.graphemes
#returns the upcasing string if option l is given then returns the list of downcase letters
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
setup do | |
{:ok,server_pid} = PasswordLock.start_link("foo") | |
{:ok,server: server_pid} | |
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
test "unlock success test", %{server: pid} do | |
assert :ok == PasswordLock.unlock(pid,"foo") | |
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
def init(password) do | |
{:ok, [password]} # ----------- state is stored as list of passwords | |
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
def handle_call({:unlock, password}, _from, passwords) do # ----> synchronous request | |
if password in passwords do | |
{:reply, :ok, passwords} | |
else | |
write_to_logfile password | |
{:reply, {:error,"wrongpassword"}, passwords} | |
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 HelloServer do | |
use GenServer | |
## Server API | |
def init(initial_value) do # initiating the state with the value 1 passed | |
{:ok,initial_value} | |
end | |
# add the value to the state and returns :ok | |
def handle_call({:add,value},_from,state) do |
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
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |
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
# Regular Approach | |
find = fn(x) when x>10 or x<5 or x==7 -> x end | |
# Our Hack | |
hell = fn(x) when true in [x>10,x<5,x==7] -> x 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
# IEx.configure colors: [enabled: true] | |
# IEx.configure colors: [ eval_result: [ :cyan, :bright ] ] | |
IO.puts IO.ANSI.red_background() <> IO.ANSI.white() <> " ❄❄❄ Good Luck with Elixir ❄❄❄ " <> IO.ANSI.reset | |
Application.put_env(:elixir, :ansi_enabled, true) | |
IEx.configure( | |
colors: [ | |
eval_result: [:green, :bright] , | |
eval_error: [[:red,:bright,"Bug Bug ..!!"]], | |
eval_info: [:yellow, :bright ], | |
], |
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 BugError do | |
defexception message: "BUG BUG .." # message is the default | |
end |