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
defimpl Poison.Encoder, for: Ecto.Association.NotLoaded do
def encode(_struct, _options) do
"null"
end
end
export function promiseResolved(value : any) {
return new Promise((resolve, reject) => {
resolve(value)
})
}
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)
@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
@elbow-jason
elbow-jason / _service.md
Last active October 2, 2016 03:35 — forked from naholyr/_service.md
Sample /etc/init.d script

Sample service script for debianoids

Look at LSB init scripts for more information.

Usage

Copy to /etc/init.d:

# replace "$YOUR_SERVICE_NAME" with your service's name (whenever it's not enough obvious)
defmodule Something do
defstruct [
material: nil
]
def get_material(%Something{material: material}) when material |> is_function do
material.()
end
def get_material(%Something{material: material}) do
query = from workout in Workout,
where: workout.id == ^id,
left_join: group in assoc(workout, :workout_set_groups),
left_join: set in assoc(group, :workout_sets),
join: excercise in assoc(group, :excercise),
preload: [workout_set_groups: {group, excercise: excercise, workout_sets: set}]
# don't attempt to sign in nil credentials at all
def create(conn, %{"session" => %{"login" => nil }}), do: nil
def create(conn, %{"session" => %{"password" => nil }}), do: nil
def create(conn, %{"session" => session_params}) do
member = Repo.one(
from w in Member,
where: w.email == ^session_params["login"]
or w.username == ^session_params["login"]
)
def get_floor(instructions) do #snake_cased
# original
# list = String.codepoints(instructions)
# calculateFloor(list)
# here we can use the `|>` (read "pipe") operator like so
instructions
|> String.codepoints
|> calulate_floor
@elbow-jason
elbow-jason / .go
Created November 11, 2015 17:18
fibber
package main
import (
"math/big"
"os"
"strconv"
)
func Fib(n int) *big.Int {
switch n {