Skip to content

Instantly share code, notes, and snippets.

View hassanRsiddiqi's full-sized avatar
🏠
Working from home

Hassan Raza hassanRsiddiqi

🏠
Working from home
View GitHub Profile
@hassanRsiddiqi
hassanRsiddiqi / stream_csv.ex
Created November 1, 2020 09:18 — forked from avdgaag/stream_csv.ex
Streaming CSV straight out of the database to the client using Elixir, Phoenix, Ecto and PostgreSQL.
def index(conn, _params) do
conn = conn
|> put_resp_content_type("text/csv")
|> put_resp_header("content-disposition", "attachment; filename=export.csv")
|> send_cunked(200)
Repo.transaction fn ->
Ecto.Adapters.SQL.stream(Repo, "COPY expensive_report TO STDOUT CSV HEADER")
|> Stream.map(&(chunk(conn, &1.rows)))
|> Stream.run
@hassanRsiddiqi
hassanRsiddiqi / Calculator By Elixir Process.ex
Last active December 1, 2021 13:31
This snippet is for learning Process in Elixir, with this snippet you can calculator basic arithmetic operation.
defmodule Cal do
def start do
spawn(fn -> loop(0) end)
end
def view(server_pid) do
send(server_pid, {:view, self()})
receive do
{:response, value} ->
@hassanRsiddiqi
hassanRsiddiqi / todoList.ex
Created December 23, 2020 07:01
TodoList in Elixir using GenServer.
defmodule TodoList do
use GenServer
@moduledoc """
A TodoList add, list, find, update & remove.
"""
def start do
{:ok, state} = GenServer.start_link(__MODULE__, [])
state
end
@hassanRsiddiqi
hassanRsiddiqi / elixir-list.ex
Created December 31, 2020 15:55
Convert string into List.
you can use ~W or ~w to convert strings into list.
~w"""
...> the
...> cat
...> sat
...> """
# ["the", "cat", "sat"]
str = "This is Test String" # "This is Test String"
~w<#{str}> # ["This", "is", "Test", "String"]