Skip to content

Instantly share code, notes, and snippets.

View imranismail's full-sized avatar

Imran Ismail imranismail

View GitHub Profile
@imranismail
imranismail / readme.md
Last active April 23, 2017 12:16
Tips on Elixir that you might not know of

Elixir Tips and Tricks That You Might Not Know Of

SaaS/Multitenant Migrations with Ecto

defmodule App.Team do
  use App, :schema

  ...
@imranismail
imranismail / conn.js
Last active March 29, 2017 02:32
Functional Example in JS
function new = () => ({
_struct: "Conn",
host: null,
path: null,
port: null,
scheme: null,
params: {},
requestHeaders: [],
responseHeaders: [],
responseBody: {},
@imranismail
imranismail / queue.ex
Created April 10, 2017 08:24
Elixir Wrapper for Erlang Queue module
defmodule Queue do
def insert(queue, item), do: :queue.in(item, queue)
def insert_last(queue, item), do: :queue.in_r(item, queue)
def member?(queue, item), do: :queue.member(item, queue)
def filter(queue, fun), do: :queue.filter(fun, queue)
def split(queue, n) do
@imranismail
imranismail / queue.ex
Last active April 3, 2021 21:12
Process native queue with backpressure using Erlang's :queue and Elixir's GenStage spawning a Process for each job in queue
# Elixir :queue wrapper with modified behavior for empty queues to mimic Enumerable module in Elixir
defmodule Queue do
def insert(queue, item), do: :queue.in(item, queue)
def insert_last(queue, item), do: :queue.in_r(item, queue)
def member?(queue, item), do: :queue.member(item, queue)
def filter(queue, fun), do: :queue.filter(fun, queue)
@imranismail
imranismail / add-block-storage.md
Last active September 20, 2017 06:45
Kubernetes 1.6.1 on Digital Ocean Ubuntu 16.04

Attach Block Storage

Attach block storage to droplet.

50G for starters

Configure Volume

sudo mkfs.ext4 -F /dev/disk/by-id/ sudo mkdir -p /mnt/; sudo mount -o discard,defaults /dev/disk/by-id/ /mnt/; echo /dev/disk/by-id/ /mnt/ ext4 defaults,nofail,discard 0 0 | sudo tee -a /etc/fstab

@imranismail
imranismail / README.md
Last active May 8, 2017 04:55
React with Phoenix

Using React with Phoenix

Create a component renderer helper and pass props as [data-props=""]

defmodule Web.ComponentHelpers do
  import Phoenix.HTML.Tag, only: [content_tag: 3]

  def component(name, props \\ %{})
  def component(name, props) when is_list(props),
    do: component(name, Enum.into(props, %{}))
@imranismail
imranismail / example.ex
Last active June 18, 2017 19:48
Trying to figure out function head bindings for Elixir Macro
defmodule Aggregate do
defmacro replay(struct, aggregate, do: block) do
quote bind_quoted: [struct: struct] do
@events [struct|@events]
def __replay__(struct, unquote(aggregate)), do: unquote(block)
end
end
end
defmodule User do

Keybase proof

I hereby claim:

  • I am imranismail on github.
  • I am imranismail (https://keybase.io/imranismail) on keybase.
  • I have a public key ASDxoGttt5zk2ozJKng_1DUiRYjeAxoakXYHWFE_bsoObwo

To claim this, I am signing this object:

@imranismail
imranismail / binary_gap.ex
Created July 31, 2017 02:25
BinaryGap in Elixir
defmodule BinaryGap do
def max(number) when is_number(number) do
number
|> Integer.to_string(2)
|> calculate()
end
defp calculate(binary, count \\ -1, max \\ 0)
defp calculate("1" <> remaining, count, max) do
calculate(remaining, 0, Enum.max([max, count]))
defmodule App.ChangesetView do
use App, :view
@doc """
Traverses and translates changeset errors.
See `Ecto.Changeset.traverse_errors/2`
"""
def translate_errors(changeset) do
Ecto.Changeset.traverse_errors(changeset, &translate_error/1)
end