Skip to content

Instantly share code, notes, and snippets.

defmodule Thinger do
end
defmodule Thinger.Fubar do
defstruct :queue, :some_module, :some_other_thing
use GenServer
def init(:ok) do
@tehprofessor
tehprofessor / karabiner-fix.sh
Created July 4, 2019 18:03
Karabiner Elements "Fix-It" for Catalina Beta
#!/bin/sh
KARABINER_ELEMENTS_PATH="/Applications/Karabiner-Elements.app"
echo "Killing Karabiner & associated processes"
sudo pkill -f Karabiner -9 # Kills the main Karabiner UI
sudo pkill -f karabiner -9 # Kills the background processes
echo "Starting Karabiner-Elements... It may be up to a minute after opening Karabiner-Elements before your custom keys activate."
open $KARABINER_ELEMENTS_PATH # Open it back up!
@tehprofessor
tehprofessor / mapify.ex
Last active January 27, 2020 13:27
Elixir example for HN post
defmodule Mapify
# This function uses a little trick matching on `%_{}` which matches only if data is a struct
def to_map(%_{} = data) do
container = Map.from_struct(data)
# Elixir will destructure a map into a two-item tuple {key, value}.
for {k, value} <- container, into: container, do: {k, to_map(value)}
end
# This matches `anything` it's the "catch all" for our `to_map` function
@tehprofessor
tehprofessor / iex-autocomplete.md
Created January 23, 2020 01:27
iex autocomplete issue/question

Issue

When you try to autocomplete a module but have incorrectly capitalized it, it outputs an error to the console, e.g.

iex(2)> EFfDB.
17:09:28.708 [error] Loading of _build/dev/lib/eff_db/ebin/Elixir.EFfDB.beam failed: :badfile

When the module doesn't exist, no error is logged to the console. The issue isn't with IEx it's only manifesting there,