Skip to content

Instantly share code, notes, and snippets.

View elbow-jason's full-sized avatar
🏠
Working from home

Jason Goldberger elbow-jason

🏠
Working from home
View GitHub Profile
defmodule Bmgr.Transaction.SearchQuery do
import Ecto.Query
alias Bmgr.{Transaction}
@filters [:account, :status]
def build(filter_params) do
do_filter(Transaction, @filters, filter_params)
end
defmodule LookupExample do
def lookup(ip) do
ip
|> Geolix.lookup
|> parse_lookup
end
def parse_lookup(%{city: %{name: city_name}, country: %{iso_code: iso_code}, postal: %{code: postal_code}}) do
{city_name, iso_code, postal_code}
defmodule Breadpacket do
use GenServer
def start_link(%{packet_state: state, packet_name: name}) do
GenServer.start_link(__MODULE__, state, name: name)
end
def init(state) do
{:ok, state}
@elbow-jason
elbow-jason / matcher.exs
Created February 11, 2018 18:50
match a collection using pattern matching
defmodule Matcher do
defmacro match_any?(pattern, collection) do
quote do
Enum.any?(unquote(collection), fn item ->
case item do
unquote(pattern) -> true
_ -> false
end
end)
end
@elbow-jason
elbow-jason / token_refresher_genserver.ex
Created February 10, 2018 18:09
A token refreshing simulated GenServer
defmodule MyTokenRefresher do
use GenServer
def start_link(_) do
GenServer.start_link(__MODULE__, nil, name: __MODULE__)
end
def init(_) do
async_fetch_token()
{:ok, %{token: nil}}
@elbow-jason
elbow-jason / benchmarks.txt
Created February 8, 2018 05:37
Black Jack Thing
iex(11)> :timer.tc(fn -> Outcomes.run end)
Dealer showing 0 partitions = 417334
Dealer showing 1 partitions = 560954
Dealer showing 2 partitions = 658854
Dealer showing 3 partitions = 679464
Dealer showing 4 partitions = 680299
Dealer showing 5 partitions = 680305
Dealer showing 6 partitions = 680305
Dealer showing 7 partitions = 680305
Dealer showing 8 partitions = 680305
@elbow-jason
elbow-jason / thing.ex
Created November 24, 2017 17:34
insert changeset
now = DateTime.utc_now()
entries =
boxes
|> Enum.map(fn
%_{} = box ->
Map.from_struct(box)
%{} = attrs ->
attrs
end)
|> Enum.reduce([], fn attrs, acc ->
/data/bin $ cat /data/var/db/pkgin/pkg_install-err.log
---Oct 03 15:50:22: installing perl-5.24.1...
---Oct 03 15:50:22: installing libpaper-1.1.24...
---Oct 03 15:50:23: installing ghostscript-fonts-8.11nb3...
---Oct 03 15:50:23: installing expat-2.2.0...
---Oct 03 15:50:23: installing ghostscript-gpl-9.06nb8...
/bin/chown: changing ownership of '/data/etc/fontconfig': Operation not permitted
/bin/chgrp: changing group of '/data/etc/fontconfig': Operation not permitted
---Oct 03 15:50:24: installing libxcb-1.12nb1...
pkg_add: package `libxcb-1.12nb1' was already installed as dependency, now marked as installed manually
root@turfbytes-dgraph-01:~# dgraph --bindall
Dgraph version : v0.8.0
Commit SHA-1 : 7c419b3f
Commit timestamp : 2017-07-21 14:13:34 +1000
Branch : HEAD
2017/07/23 11:21:53 read p/000003.sst: invalid argument
github.com/dgraph-io/badger/y.Wrap
export interface FormFieldParams {
form: any
field: string
}
const applySetterAndGetter = <T extends Function>(component: T, params: FormFieldParams): T => {
let options = {
get: () => {
return params.form.payload()[params.field]