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
case coalesce(origin.timezone, 'UTC')
when 'America/New_York' then toDateTime(s.starts_at, 'America/New_York')
when 'America/Chicago' then toDateTime(s.starts_at, 'America/Chicago')
when 'America/Denver' then toDateTime(s.starts_at, 'America/Denver')
when 'America/Detroit' then toDateTime(s.starts_at, 'America/Detroit')
when 'America/Los_Angeles' then toDateTime(s.starts_at, 'America/Los_Angeles')
when 'America/Phoenix' then toDateTime(s.starts_at, 'America/Phoenix')
when 'America/Indiana/Indianapolis' then toDateTime(s.starts_at, 'America/Indiana/Indianapolis')
when 'Europe/Berlin' then toDateTime(s.starts_at, 'Europe/Berlin')
when 'Europe/Dublin' then toDateTime(s.starts_at, 'Europe/Dublin')
# 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