Skip to content

Instantly share code, notes, and snippets.

@BennyHallett
BennyHallett / scheduler.ex
Created November 1, 2014 00:03
Tournament Scheduling in Elixir
defmodule Scheduler do
require Integer
@doc """
Generate a number of teams (3 or more)
"""
def generate_teams(number) when number < 3, do: IO.puts "Need to specify at least 3 teams"
def generate_teams(number) do
team_names
@BennyHallett
BennyHallett / caesar.ex
Last active August 29, 2015 14:08
Caesar Cipher in Elixir
defmodule Caesar do
@doc """
Encode a file with a Caesar Cipher.
Shift value must be between 0 and 25. Works best with only aplha characters. Spaces will be left as spaces.
Usage:
$ iex caesar.ex
iex> Caesar.encode_file("/path/to/file", 13)
@BennyHallett
BennyHallett / identicon.exs
Created October 18, 2014 00:20
ANSI Identicons in Elixir
defmodule Identicon do
def make(username) do
username
|> encode
|> draw
end
defp encode(username) do
:crypto.md5(username)
@BennyHallett
BennyHallett / Dockerfile
Created October 11, 2014 13:55
Simple Dockerfile for use with a Phoenix app
FROM trenpixster/elixir:1.0.1
COPY . /phoenix_app
ENV MIX_ENV prod
WORKDIR /phoenix_app
RUN mix do deps.get, compile
EXPOSE 4000
CMD ["mix", "phoenix.start"]
@BennyHallett
BennyHallett / INSTRUCTIONS.md
Created October 10, 2014 06:23
Digital Pet written in Elixir

Instuctions

Run the file with:

$ iex digipet.ex

The create a pet via:

iex> pet = DigiPet.new "Franklin"
@BennyHallett
BennyHallett / terrain.exs
Created August 30, 2014 04:48
Unfinished Terrain Generator
defmodule Terrain do
def generate do
size = 65 # or 129, 513, 1025 (2^x + 1)
initial_state(size)
|> diamond { 0, 0 }, { size-1, size-1 }
end
defp diamond(current, { x1, y1 }, { x2, y2 }) when x2 == x1 + 2 and y2 == y1 + 2 do
current
defmodule FizzBuzz do
@doc """
Given a range, returns an array of values conforming to the FizzBuzz pattern.
## Example
FizzBuzz.calculate 1..15
-> 1 2 Fizz 4 Buzz Fizz 7 8 Fizz Buzz 11 Fizz 13 14 FizzBuzz
"""
def calculate(range) do