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
@elbow-jason
elbow-jason / poller.ex
Created January 8, 2017 00:25
A GenServer Poller
defmodule Poller do
use GenServer
def start_link do
# this starts the genserver (for supervision)
GenServer.start_link(__MODULE__, [], name: __MODULE__)
end
def init(_) do
set_timer
def defines_function?(module, name, arity) do
defines_function?(module, name, arity)
end
def defines_function?(module, {name, arity}) do
try do
module.__info__(:functions)
|> Enum.member?({name, arity})
rescue
UndefinedFunctionError ->
# this rescues the call to module.__info__(:functions)
export function promiseResolved(value : any) {
return new Promise((resolve, reject) => {
resolve(value)
})
}
defimpl Poison.Encoder, for: Ecto.Association.NotLoaded do
def encode(_struct, _options) do
"null"
end
end
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]
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
/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
@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 ->
@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 / 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}}