Skip to content

Instantly share code, notes, and snippets.

View benwilson512's full-sized avatar

Ben Wilson benwilson512

  • CargoSense
  • Falls Church, VA
View GitHub Profile
# before this:
#
# createdb preload_example
#
# You may need to amend the `Repo.start_link` call with a username and password, depending on your
# Postgres configuration.
############################
## Deps and Repo boilerplate
############################
./link-kv.exs
Resolving Hex dependencies...
Resolution completed in 0.012s
New:
jason 1.4.0
* Getting jason (Hex package)
==> jason
Compiling 10 files (.ex)
17:14:08.343 [error] GenServer Hex.Registry.Server terminating
def intervals_overlap?({%DateTime{}, _} = i1, {%DateTime{}, _} = i2) do
case {i1, i2} do
{{_left1, nil}, {_left2, nil}} ->
true
{{left1, nil}, {_left2, right2}} ->
before_inclusive?(left1, right2)
{{_left1, right1}, {left2, nil}} ->
before_inclusive?(left2, right1)
# TODO: Extract into it's own library
defmodule AbsintheSocket do
require Logger
alias Phoenix.Channels.GenSocketClient
@behaviour GenSocketClient
@control_topic "__absinthe__:control"
defdelegate fetch(term, key), to: Map
defdelegate get(term, key, default), to: Map
defmodule NonRepeating do
# convert a string into a list of chars
def find(string) when is_binary(string) do
string
|> to_charlist
|> find
end
# If we have an empty char list, nothing to do
def find(''), do: nil
# in application.ex
[
{Absinthe.Client, MyApp.Client}
]
defmodule MyApp.Client do
use Absinthe.Client
end
defmodule MyApp.AddFilteringTypes do
def run(blueprint, _) do
{:ok, blueprint}
end
end
defmodule Schema do
use Absinthe.Schema
@pipeline_modifier __MODULE__
##### With input Large | large precision #####
Name ips average deviation median 99th %
erlang 339.10 K 2.95 μs ±713.66% 3 μs 6 μs
built in 246.23 K 4.06 μs ±325.32% 4 μs 9 μs
Comparison:
erlang 339.10 K
built in 246.23 K - 1.38x slower
defmodule Raven.Util.Transaction do
use GenServer, restart: :temporary
@moduledoc """
Claim a given transaction handle
Blocks if other callers have already claimed the handle. This will return with
`:ok` if the current process wins the claim, otherwise it will return `:already_taken`
### Example Usage
[21] pry(main)> user.organization_ids = [1,2]
[2017-09-18 07:58:18] DEBUG ActiveRecord::Base : Organization Load (0.4ms) SELECT "organizations".* FROM "organizations" WHERE "organizations"."id" IN (1, 2)
[2017-09-18 07:58:18] DEBUG ActiveRecord::Base : (0.1ms) BEGIN
[2017-09-18 07:58:18] DEBUG ActiveRecord::Base : SQL (0.3ms) INSERT INTO "memberships" ("created_at", "organization_id", "updated_at", "user_id") VALUES ($1, $2, $3, $4) RETURNING "id" [["created_at", "2017-09-18 11:58:18.463433"], ["organization_id", 1], ["updated_at", "2017-09-18 11:58:18.463433"], ["user_id", 1]]
[2017-09-18 07:58:18] DEBUG ActiveRecord::Base : SQL (0.2ms) INSERT INTO "memberships" ("created_at", "organization_id", "updated_at", "user_id") VALUES ($1, $2, $3, $4) RETURNING "id" [["created_at", "2017-09-18 11:58:18.465174"], ["organization_id", 2], ["updated_at", "2017-09-18 11:58:18.465174"], ["user_id", 1]]
[2017-09-18 07:58:18] DEBUG ActiveRecord::Base : (1.1ms) COMMIT
=> [1, 2]