Skip to content

Instantly share code, notes, and snippets.

View blackode's full-sized avatar
:octocat:
Pushed code so fast, even my coffee is still loading. ☕💻 #CodingFuel

Ankanna blackode

:octocat:
Pushed code so fast, even my coffee is still loading. ☕💻 #CodingFuel
View GitHub Profile
@blackode
blackode / when_cond.exs
Last active March 8, 2017 08:34
when conditions as functions
defmodule Hello do
def hello(name,age) when is_kid(age) do
IO.puts "Hello Kid #{name}"
end
def hello(name,age) when is_adult(age) do
IO.puts "Hello Mister #{name}"
end
def is_kid age do
age < 12
end
@blackode
blackode / when_macro.ex
Last active September 19, 2019 14:04
Macros in guard clauses...
defmodule MyGuards do
defmacro is_kid age do
quote do: unquote(age) < 12
end
defmacro is_adult age do
quote do: unquote(age) > 18
end
@blackode
blackode / ets_keys.ex
Last active March 27, 2017 15:25
list of keys in ets tables
defmodule EtsKeys do
def keys(table_name) do
first_key = :ets.first(table_name)
keys(table_name, first_key, [first_key])
end
def keys(_table_name, '$end_of_table', ['$end_of_table'|acc]) do
acc
end
def keys(table_name, current_key, acc) do
@blackode
blackode / postgres_guide.md
Last active May 19, 2023 07:46 — forked from tacionery/postgres_guide
install postgresql on antergos

uninstall postgresql if necessary

sudo pacman -R postgresql postgresql-libs

remove postgres files

sudo rm -rfv /var/lib/postgres
@blackode
blackode / tcp_server.ex
Created June 28, 2017 22:23
TcpServer Implementation with gen_tcp erlang module
defmodule TcpServer do
use GenServer
def start_link() do
ip = Application.get_env :tcp_server, :ip, {127,0,0,1}
port = Application.get_env :tcp_server, :port, 6666
GenServer.start_link(__MODULE__,[ip,port],[])
end
def init [ip,port] do
@blackode
blackode / default.md
Last active October 18, 2017 12:25
Json Representation
{"menu": {
  "id": "file",
  "value": "File",
  "popup": {
    "menuitem": [
      {"value": "New", "onclick": "CreateNewDoc()"},
      {"value": "Open", "onclick": "OpenDoc()"},
      {"value": "Close", "onclick": "CloseDoc()"}
 ]
@blackode
blackode / .formatter.exs
Last active June 11, 2020 17:39
Elixir codebase formatter
# project_root/.formatter.exs
[
# functions to let allow the no parens like def print value
locals_without_parens: [hello: 2, get_user: 1, addtion: *],
# files to format
inputs: ["mix.exs", "{config,lib,test}/**/*.{ex,exs}"],
@blackode
blackode / Array.ex
Last active March 1, 2018 17:19
The flatten function implementation in Elixir
# Elixir V1.6
defmodule Array do
@moduledoc """
A collective data module with some helpful functions
"""
@doc """
Flattens the given list of nested lists. By default it gives out the unique list of items by removing the duplicates
inside.
@blackode
blackode / stack.ex
Last active March 28, 2018 21:04
Stack Implementation Using Genserver
# stack.ex
defmodule Stack do
use GenServer
# server callbacks
def init(args), do: {:ok, args}
#used to handle synchronous requests
def handle_call(:get, _from, state) do
@blackode
blackode / bank.ex
Created April 3, 2018 13:44
Artilce Demonstration Project
defmodule Bank do
use GenServer
alias Bank.Cache
@moduledoc """
Documentation for Bank.
"""
# client API
def start_link(cache_pid) do
GenServer.start_link(Bank, cache_pid, name: Bank)
end