Skip to content

Instantly share code, notes, and snippets.

defmodule Meh do
def main do
"foo"
|> (&foo(&2, &1)).("yoyo")
end
def hard_coded do
"foo"
|> (&foo("quux", &1)).()
end
# (arity 0)
root@deleteme:~/foo# bin/foo rpc Foo bar
RPC to 'foo@127.0.0.1' failed: {'EXIT',
{undef,
[{'Foo',bar,[],[]},
{rpc,'-handle_call_call/6-fun-0-',5,
[{file,"rpc.erl"},{line,205}]}]}}
root@deleteme:~/foo# bin/foo rpc Elixir.Foo bar
yeah!
# this creates an incorrect query b/c it joins account, account_user and user_api_key to client
# as it is piped through
query = DemoApp.Client
|> join(:inner, [c], b0 in assoc(c, :account))
|> join(:inner, [b0], b1 in assoc(b0, :account_user))
|> join(:inner, [b1], b2 in assoc(b1, :user_api_key))
|> where([b1, b0], b1.id == ^user_id and b0.id == ^account_id)
|> preload([b0, b1, b2], [account: {b0, account_user: {b1, user_api_key: b2}}])
|> select([c, b0, b1, b2], {c, b0, b1, b2})
~/C/S/p/router_bug_faster > time mix compile
Compiled src/dict.erl
Compiled src/erl_lint.erl
Compiled lib/router_bug.ex
Compiled web/controllers/page_controller.ex
Compiled lib/router_bug/endpoint.ex
Compiled web/view.ex
Compiled web/views/error_view.ex
Compiled web/views/layout_view.ex
Compiled web/views/page_view.ex
@brweber2
brweber2 / router.ex
Last active August 29, 2015 14:15
Phoenix lib/router.ex with 5 minute compilation time.
defmodule DemoBe.Router do
use Phoenix.Router
pipeline :browser do
plug :accepts, ~w(html)
plug :fetch_session
plug :fetch_flash
plug :protect_from_forgery
end
@brweber2
brweber2 / gen_fsm_example.ex
Last active August 29, 2015 14:13
gen_fsm example
defmodule Exflow do
@behaviour :gen_fsm
def start_link(code) do
IO.puts "starting fsm"
:gen_fsm.start_link({:local, Exflow}, Exflow, :lists.reverse(code), [])
end
def button(digit) do
Host *.foo.com
User <name>
IdentityFile ~/.ssh/foo_rsa
Host *
IdentitiesOnly yes
@brweber2
brweber2 / yahoo stock
Last active December 24, 2015 16:39
grab csv file with stock data from yahoo
{
"metadata": {
"name": "Scratchpad"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
From order-update@amazon.com Fri May 11 05:33:29 2012
X-Apparently-To: <SNIP-SNIP>@yahoo.com via 98.138.227.207; Fri, 11 May 2012 11:33:29 -0700
Return-Path: <fom_bonn@hilton.com>
Received-SPF: fail (domain of hilton.com does not designate 69.15.141.195 as permitted sender)
@brweber2
brweber2 / gist:2649948
Created May 10, 2012 00:09 — forked from djKianoosh/gist:2648751
Some Clojure functions to help read IIS log files into maps
(defn comment? [s]
(.startsWith s "#"))
(defn not-comment? [s]
(not (comment? s))) ; you could also do (-> s comment? not), just showing alternatives, but what you had originally is just fine.
(defn remove-comments [file-contents]
(filter not-comment? file-contents))
(defn nil-if-hyphen [s]