Skip to content

Instantly share code, notes, and snippets.

Mikal mikalv

Block or report user

Report or block mikalv

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@mikalv
mikalv / my_app.ex
Created Feb 3, 2020 — forked from alanpeabody/my_app.ex
Websockets in Elixir with Cowboy and Plug
View my_app.ex
defmodule MyApp do
use Application
def start(_type, _args) do
import Supervisor.Spec, warn: false
children = [
Plug.Adapters.Cowboy.child_spec(:http, MyApp.Router, [], [
dispatch: dispatch
])
@mikalv
mikalv / README
Created Jan 22, 2020 — forked from mremond/README
Phoenix Elixir framework with ejabberd - Tutorial
View README
Please read original blog post for reference:
http://blog.process-one.net/embedding-ejabberd-into-an-elixir-phoenix-web-application/
@mikalv
mikalv / macro_fun.exs
Created Jan 16, 2020 — forked from rcdilorenzo/macro_fun.exs
Macro fun in Elixir mimicking Ruby's attr_accessor
View macro_fun.exs
defmodule MacroExp do
defmacro attr_accessor(atom) do
getter = String.to_atom("get_#{atom}")
setter = String.to_atom("set_#{atom}")
quote do
def unquote(getter)(data) do
data |> Map.from_struct |> Map.get(unquote(atom))
end
def unquote(setter)(data, value) do
data |> Map.put(unquote(atom), value)
@mikalv
mikalv / task1.exs
Created Jan 16, 2020 — forked from moklett/task1.exs
Elixir Task - Crash Handling
View task1.exs
# This demonstrates that, when using async/await, a crash in the task will crash the caller
defmodule Tasker do
def good(message) do
IO.puts message
end
def bad(message) do
IO.puts message
raise "I'm BAD!"
end
View xpath-cheatsheet.js
// XPath CheatSheet
// To test XPath in your Chrome Debugger: $x('/html/body')
// http://www.jittuu.com/2012/2/14/Testing-XPath-In-Chrome/
// 0. XPath Examples.
// More: http://xpath.alephzarro.com/content/cheatsheet.html
'//hr[@class="edge" and position()=1]' // every first hr of 'edge' class
@mikalv
mikalv / ets_cache.ex
Created Dec 12, 2019 — forked from raorao/ets_cache.ex
Simple ETS based cache with TTL
View ets_cache.ex
defmodule RequestCache do
@moduledoc """
Simple ETS-based cache.
"""
use GenServer
@type t :: %{ttl: integer, invalidators: %{}}
@type cache_key :: any
@type cache_value :: any
@mikalv
mikalv / ets_cache.ex
Created Dec 12, 2019 — forked from raorao/ets_cache.ex
Simple ETS based cache with TTL
View ets_cache.ex
defmodule RequestCache do
@moduledoc """
Simple ETS-based cache.
"""
use GenServer
@type t :: %{ttl: integer, invalidators: %{}}
@type cache_key :: any
@type cache_value :: any
@mikalv
mikalv / Elixir_Supervision_Trees.md
Created Dec 12, 2019 — forked from gkaemmer/Elixir_Supervision_Trees.md
Quick guide to creating Elixir supervision trees from scratch
View Elixir_Supervision_Trees.md

Elixir Supervision Trees Made Easy

I started with Elixir just a couple weeks after the switch from 1.4 to 1.5, so the bulk of online resources were out of date (or at least resulted in deprecation warnings). This guide is for defining Elixir 1.5 supervised modules.

It's not actually terribly complicated. It's just sometimes unclear from examples what's implemented by the language and what you actually have to implement yourself.

Say we want a supervision tree like this (where each atom is a process):

    :a
    / \
@mikalv
mikalv / utility.erl
Created Dec 5, 2019 — forked from binarytemple/utility.erl
Erlang decompiler I found on the web, works for Elixir beam files too
View utility.erl
%% Author: PCHAPIER
%% Created: 25 mai 2010
-module(utility).
%%
%% Include files
%%
%%
%% Exported Functions
@mikalv
mikalv / brew-list.sh
Created Dec 1, 2019 — forked from eguven/brew-list.sh
List all packages installed using Homebrew and their sizes
View brew-list.sh
brew list -f1 | xargs -n1 -P8 -I {} \
sh -c "brew info {} | egrep '[0-9]* files, ' | sed 's/^.*[0-9]* files, \(.*\)).*$/{} \1/'" | \
sort -h -r -k2 - | column -t
You can’t perform that action at this time.