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 / true_lies.ipynb
Created July 24, 2014 01:05
A demo of the mro()
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@elbow-jason
elbow-jason / gist:a81b51370822b62a0d5a
Last active August 29, 2015 14:16
Stream is causing iex to hang for some reason...
defmodule LoggerHandler do
use GenEvent
# Callbacks
def handle_event({:log, x}, messages) do
{:ok, [x|messages]}
end
@elbow-jason
elbow-jason / gist:baee81b0e2fe8d3f8690
Last active August 29, 2015 14:17
Dynamic Functions with or without args?
defmodule DynaFuncs do
#this works - dynamic name with no args
{:ok, other_func_name} = Code.string_to_quoted(:half)
def unquote(other_func_name), do: IO.puts(1/2)
# but this doesn't work - static name with no args
def unquote(:one_third), do: IO.puts(1/3)
# and this works - static name with args
@elbow-jason
elbow-jason / mnesia.exs
Last active August 29, 2015 14:17 — forked from joshnuss/mnesia.exs
# define a record, first attribute is considered the key
defrecord User, email: "", first: "", last: ""
# encapsulates mnesia calls
defmodule Database do
def create_schema do
create_table User
end
def find(record, id) do
@elbow-jason
elbow-jason / gist:0fdea26fa4aad95e1098
Created March 31, 2015 04:32
Understanding Rust ADTs Blog Example. Copy. Paste. Compile. Run.
/*
This is an enum. In Rust, an enum is a type which can only
be in one of a finite category of states; the states with which
the enum was defined.
Each of these states may or may not "wrap" an already existent type.
For instance, a variable that is of the type FizzedEnum can be in
the one of the following states: FizzBuzz, Fizz, Buzz, or Int(isize).
In the case of Int(isize), the FizzedEnum is in a state that wraps
an integer of type isize.
@elbow-jason
elbow-jason / gist:2bd76dcdead70312e083
Created April 14, 2015 03:08
erlang 17.5 and elixir 1.0.4 issues
elbow@elbow-K55N /usr/local/lib/erlang $ iex
Erlang/OTP 17 [erts-6.4] [source] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false]
*** ERROR: Shell process terminated! (^G to start new job) ***
=INFO REPORT==== 13-Apr-2015::20:02:11 ===
application: elixir
exited: {bad_return,
{{elixir,start,[normal,[]]},
{'EXIT',
@elbow-jason
elbow-jason / install_erlang_and_elixir.sh
Last active August 29, 2015 14:19
Install Erlang 17.5 from source and Elixir from Precompiled.zip (for Mint 17.1 Rebecca)
#!/bin/bash
# This script installs Erlang 17.5 from source and Elixir 1.0.4
# from precomplized zip. Installation took approximately
# 40 minutes with a crappy computer and crappy internet connetion.
# This script should work (read: was only tested) on Mint
# Rebecca 17.1, but honestly should work on most Linux debian distros.
# INSTRUCTIONS:
# Pull this into a directory that will persist. (not tmp)
@elbow-jason
elbow-jason / Limited_possibilites.ex
Created April 26, 2015 20:11
Limited Possibilities
def f(:ok), do: :ok
def f(:bien), do: :ok
def f(:guay), do: :ok
def f(_), do: :mal
def f(x) when x in [:ok, :bien, :guay] do
:ok
end
def f(_) do
:mal
end
@elbow-jason
elbow-jason / gist:d2e01e137c46f9c495e5
Last active August 29, 2015 14:22
pattern_matching_warnings
def passwords_match?(_x, _x), do: true
def passwords_match?(_, _), do: false
# causes the following warning...
# registration.ex:61: warning: the underscored variable "_x" appears more
# than once in a match. This means the pattern will only match
# if all "_x" bind to the same value. If this is the intended behaviour,
# please remove the leading underscore from the variable name,
# otherwise give the variables different names