Skip to content

Instantly share code, notes, and snippets.

View rozap's full-sized avatar

Chris Duranti rozap

View GitHub Profile
defmodule Foo do
defp make_guard(:any), do: true
defp make_guard(token) do
quote do
head == token
end
end
defp table_action("create"), do: table_create("authors")
defp table_action("destroy"), do: table_drop("authors")
def authors(cd) do
#Connect to the database.
conn = RethinkDB.connect([host: "10.0.0.30", port: 28015])
q = table_action(cd) |> run(conn)
def authors(cd) do
#Connect to the database.
conn = RethinkDB.connect([host: "10.0.0.30", port: 28015])
q = case cd do
"create" -> table_create("authors")
"destroy" -> table_drop("authors")
end
|> run(conn)
@rozap
rozap / gist:5f23fbb9b12e4c6cf9b9
Created July 22, 2015 00:23
tracking how long i spend waiting for sbt
#!/bin/bash
timestamp() {
date +%s%3N
}
watch_dir=$1
echo "Watching $watch_dir ..."
<kml:kml xmlns:kml="http://earth.google.com/kml/2.1">
<kml:Document id="featureCollection">
<Folder id="???">
<Placemark id="fid-7adab59e_14f666dec01_-7f70">
<ExtendedData>
<SchemaData>
<SimpleData name="an_int">1</SimpleData>
<SimpleData name="a_string">1</SimpleData>
<SimpleData name="a_float">1.1</SimpleData>
</SchemaData>
def(at(<<var!(head) :: binary - size(2), rest :: binary>>, ptr, meta) when ptr >= 8 and ptr <= 9) do
new_posn = ptr + 2
case({:meta, {:header_length, head}}) do
{:halt, _} = halt ->
halt
{:meta, {key, val}} ->
{rest, new_posn, Dict.put(meta, key, val), []}
result ->
{rest, new_posn, meta, [result]}
end
@rozap
rozap / wat
Created December 3, 2015 05:49
00:47:26.460 [error] GenServer #PID<0.276.0> terminating
** (Poison.EncodeError) unable to encode value: {nil, "user"}
(poison) lib/poison/encoder.ex:339: Poison.Encoder.Any.encode/2
(poison) lib/poison/encoder.ex:213: anonymous fn/4 in Poison.Encoder.Map.encode/3
(poison) lib/poison/encoder.ex:214: Poison.Encoder.Map."-encode/3-lists^foldl/2-0-"/3
(poison) lib/poison/encoder.ex:214: Poison.Encoder.Map.encode/3
(poison) lib/poison/encoder.ex:213: anonymous fn/4 in Poison.Encoder.Map.encode/3
(poison) lib/poison/encoder.ex:214: Poison.Encoder.Map."-encode/3-lists^foldl/2-0-"/3
(poison) lib/poison/encoder.ex:214: Poison.Encoder.Map.encode/3
(poison) lib/poison/encoder.ex:213: anonymous fn/4 in Poison.Encoder.Map.encode/3
@rozap
rozap / wtf.md
Last active December 3, 2015 05:52
defimpl Poison.Encoder, for: Usic.User do
  @attributes ~W(id email inserted_at updated_at)a

  def encode(song, _options) do
    song
    |> Map.take(@attributes)
    |> Poison.encode!
  end
end
defmodule KVStore do
use GenServer
# This executes within the supervisor or whoever starts the KVStore
def start_link do
# First arg is the callback module (this module)
# The name arg registers the process globally as `KVStore`, essentially making it a singleton
GenServer.start_link(KVStore, [], name: KVStore)
end
foo bar
1 2