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 Trier do
require IEx
def thing do
x = 0
try do
1 / x
rescue
e in ArithmeticError ->
@elbow-jason
elbow-jason / gist:ee3461d71ef7442d39ff
Last active August 29, 2015 14:25
import example
defmodule ImportExample do
# on this line Enum is not imported, yet.
import Enum #imports are not Module-wide. they only apply below the import.
def all_funcs do
map([1,2,3], fn n -> n + 1 end) #map is from Enum
end
@elbow-jason
elbow-jason / .ex
Created September 25, 2015 20:39
query example
defp planting_operations_only do
from operation in Operation,
where: operation.operation_type == "planting",
preload: :variety
end
def crop_plan_preloads(query) do
from q in query,
preload: :crop,
preload: :fields,
@elbow-jason
elbow-jason / .ex
Last active November 11, 2015 04:38
do fib
defmodule SimpleFib do
def fib(0), do: 0
def fib(1), do: 1
def fib(n) do
do_fib(n, 2, 1, 0)
end
defp do_fib(x, x, prev, prevprev) do
prev + prevprev
end
@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 {
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
# 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"]
)
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}]
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
@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)