Skip to content

Instantly share code, notes, and snippets.

View apboobalan's full-sized avatar

Boobalan AP apboobalan

View GitHub Profile

Keybase proof

I hereby claim: * I am apboobalan on github. * I am apboobalan (https://keybase.io/apboobalan) on keybase. * I have a public key ASB-iyrDuLWjant6ITMdFLdEr3hbQ9NyU2VH_8CsAgOcAwo To claim this, I am signing this object:

{   "body": {     "key": {       "eldest_kid": "01207e8b2ac3b8b5a36a7b7a21331d14b744af785b43d372536547ffc0ac02039c030a",       "host": "keybase.io",       "kid": "01207e8b2ac3b8b5a36a7b7a21331d14b744af785b43d372536547ffc0ac02039c030a",       "uid": "8f124505ff7c983056f3c82f46119919",       "username": "apboobalan"     },     "merkle_root": {       "ctime": 1580020156,       "hash": "e0d8fd66fe3baa0a6c6dcdf2e52e0bfdbdaad42673ebe062fd836a532cbcc2a77d5968d4138a6fc496c4c1c5fe7f6c2d48c55bb8f4e86abbd066a56ab29ab4f5",       "hash_meta": "578d3e9036130e30704b79838a10e6417652c9eaf7c7fd0e47479c9ea9773209",       "seqno": 14367447     },     "service": {       "entropy": "YVu0o+FLVp0GNvREKV2SFT7R",       "name": "github",       "username": "apboobalan"     },     "type":
defmodule Streamy do
def start do
start = fn -> 0 end
next = fn value -> {[value + 1], value + 1} end
stop = fn value -> value end
Stream.resource(start, next, stop)
end
end
require Integer
@apboobalan
apboobalan / RealTimePhoenixGist.md
Created September 1, 2020 07:37
Key concepts to remember from real time phoenix book.
  • Scalability triangle
    • Performance, maintenance, cost
  • WS lifecycle
    • inspect ws inside browser dev tools
    • Initial call is made using HTTP and then 101 protocol switch response is received and the connection is upgraded to ws
    • Optional heartbeat messages are used in check connection.
    • Phoenix pings server every 30 seconds.
    • Server will close connection if it doesn't receive ping within 60 seconds.
    • use wss:// for security.
    • ws doesn't follow CORS policy.
@apboobalan
apboobalan / elixir_typespec.md
Created September 4, 2020 09:21
Gist about typespecs in Elixir
  • To define type spec for a functions @spec function_name(arg_1_type, arg_2_type) :: return_type
  • To define new type@type new_type_name :: existing_type
  • To document type place @typedoc """ description """ above type definition.
  • We can create product types such as lists, tuples and maps using their own syntax with members being the types.
  • Eg. Product types
@type statuses :: [atom]

@type number_with_remark :: {number, String.t}
@apboobalan
apboobalan / string_enumerable.ex
Last active October 14, 2020 06:30
Curious case of 'in'. Add in capability to strings in Elixir.
defimpl Enumerable, for: BitString do
def count(string), do: {:ok, string |> String.length()}
def member?(string, substring), do: {:ok, string |> String.contains?(substring)}
def slice(string),
do:
{:ok, string |> String.length(),
fn start_position, end_position ->
string
@apboobalan
apboobalan / in_macro.ex
Last active October 14, 2020 04:22
Curious case of 'in'. Add syntactic sugar while writing code.
defmodule Validator do
defmacro having({:in, _, [lhs, rhs]}) when lhs |> is_binary and rhs |> is_binary,
do: rhs |> String.contains?(lhs)
defmacro having({:in, _, [_lhs, _rhs]}), do: false
end
defmodule TaskiFirst.Taski do
def async(fun) do
spawning_process = self()
spawn(fn -> spawning_process |> send(fun.()) end)
end
def await() do
receive do
result -> result
end
defmodule Taski.Taski do
def async(fun) do
spawning_process = self()
spawn(fn -> spawning_process |> send({self(), fun.()}) end)
end
def await(pid) do
receive do
{^pid, result} -> result
end