Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule LoggerHandler do | |
use GenEvent | |
# Callbacks | |
def handle_event({:log, x}, messages) do | |
{:ok, [x|messages]} | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def f(:ok), do: :ok | |
def f(:bien), do: :ok | |
def f(:guay), do: :ok | |
def f(_), do: :mal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def f(x) when x in [:ok, :bien, :guay] do | |
:ok | |
end | |
def f(_) do | |
:mal | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
OlderNewer