Skip to content

Instantly share code, notes, and snippets.

View KronicDeth's full-sized avatar

Elle Imhoff KronicDeth

View GitHub Profile
@KronicDeth
KronicDeth / api_controller.ex
Created June 4, 2016 01:54
Using Alembic.Document.from_json in a Phoenix controller
defmodule MyApp.ApiController do
alias Alembic.Document
alias Alembic.Source
alias Plug.Conn
@doc """
Convert the `params` to a JSON API Document with `action` set as the `meta` `"action"`. If there a parsing
error, the error document is rendered as json to `conn` and the modified `conn` is returned. If there is no parsing
error then `{:ok, document}` is returned.
"""
@KronicDeth
KronicDeth / client.ex
Created June 3, 2016 14:37
Destroy DAG for referencing tables until first error
@doc """
Destroys the Directed Acyclic Graph (DAG) of each module in `modules` in order as long as the previous module's
`destroy_dag(destroyed_set, context)` returned `{:ok, new_destroyed_set}`; otherwise, returns the first error.
"""
@spec destroy_dags(destroyed_set, context, modules :: [module, ...]) :: {:ok, destroyed_set} | __MODULE__.Generic.error
def destroy_dags(destroyed_set, context, modules) do
Enum.reduce_while modules, {:ok, destroyed_set}, fn {:ok, acc_destroyed_set}, referencing_module ->
case referencing_module.destroy_dag(destroyed_set, context) do
acc = {:ok, _} ->
{:cont, acc}
=ERROR REPORT==== 8-Jan-2016::13:51:59 ===
Error in process <0.628.0> with exit value:
{function_clause,[{cerl,map_arg,1,[]},
{file,list_dir,1,[]},
{dialyzer_dataflow,format_args_1,3,[]},
{dialyzer_dataflow,format_args,3,[]},
{dialyzer_dataflow,handle_apply_or_call,9,[]},
{dialyzer_dataflow,do_clause,6,[]},
{dialyzer_dataflow,handle_clauses,9,[]},
{dialyzer_dataflow,handle_case,3,[]}]}

Keybase proof

I hereby claim:

  • I am kronicdeth on github.
  • I am kronicdeth (https://keybase.io/kronicdeth) on keybase.
  • I have a public key whose fingerprint is 9C10 5D2E 8AD8 8D65 6A39 E682 5B1F B01F B333 56F8

To claim this, I am signing this object:

......
1) test HTTPS GET / (RoutingSecurelyWithPhoenixFramework.PageControllerTest)
test/controllers/page_controller_test.exs:13
** (RuntimeError) expected response with status 200, got: 301
stacktrace:
(phoenix) lib/phoenix/test/conn_test.ex:316: Phoenix.ConnTest.response/2
(phoenix) lib/phoenix/test/conn_test.ex:330: Phoenix.ConnTest.html_response/2
test/controllers/page_controller_test.exs:15
@KronicDeth
KronicDeth / work-tree-breakup.md
Created July 31, 2015 20:10
Breaking up a working tree into multiple commits

Breaking up a working tree into multiple commits

If you ever have more than one commit's worth of changes in your git work tree, and you're trying to separate the commits:

  1. git reset HEAD to unstage everything
  2. Stage pieces with git add --patch
  3. Remove everything unstaged or untracked (so new file) with git stash -k -u
  4. rake spec to ensure that staged pieces pass specs on their own
  5. git commit
  6. git stash pop to restore the stash from (2)
@KronicDeth
KronicDeth / mapt.exs
Last active August 29, 2015 14:25
Map keys and drop unmapped keys with support for nil and false as new keys
t = %{old1: :new1, old2: :new2, old4: nil, old5: false};
IO.inspect Enum.reduce(
%{old1: 1, old2: 2, old3: 3, old4: 4, old5: 5},
%{},
fn ({old_key, value}, new_map) ->
case Map.fetch(t, old_key) do
:error ->
new_map
{:ok, new_key} ->
Map.put(new_map, new_key, value)
package org.elixir_lang.psi.impl;
import com.ericsson.otp.erlang.*;
import org.elixir_lang.Macro;
public class ElixirPsiImplUtil {
private static final OtpErlangAtom UNQUOTE_SPLICING = new OtpErlangAtom("unquote_splicing");
/**
* Unwraps <code>quote_splicing</code> in stabOperation.
@KronicDeth
KronicDeth / sh.txt
Created May 15, 2015 20:28
make clean; make test in elixir-lang/elixir
> make clean
cd lib/elixir && ../../rebar clean
==> elixir (clean)
rm -rf ebin
rm -rf lib/*/ebin
rm -rf lib/elixir/test/ebin
rm -rf lib/*/tmp
rm -rf lib/mix/test/fixtures/git_repo
rm -rf lib/mix/test/fixtures/deps_on_git_repo
rm -rf lib/mix/test/fixtures/git_rebar
@KronicDeth
KronicDeth / ElixirPsiImplUtil.java
Created January 9, 2015 02:54
6-hexadecimal digits escape sequences in Elixir over JInterface
public class ElixirPsiImplUtil {
// @return -1 if codePoint cannot be parsed.
public static int codePoint(@NotNull ElixirEscapedCharacter escapedCharacter) {
ASTNode[] escapedCharacterTokens = escapedCharacter
.getNode()
.getChildren(TokenSet.create(ElixirTypes.ESCAPED_CHARACTER_TOKEN));
int parsedCodePoint = -1;
if (escapedCharacterTokens.length == 1) {
ASTNode escapedCharacterToken = escapedCharacterTokens[0];