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
# Use this code and data to answer the questions. | |
defmodule Millenium.Falcon do | |
def rebel?(c = %{rebel: true}) do | |
c.type != :droid | |
end | |
def rebel?(_), do: false | |
def fill_ship(characters) 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
characters = [ | |
%{name: "Han", type: :human, rebel: true, weight: 185}, | |
%{name: "Jabba", type: :hutt, rebel: false, weight: 2200}, | |
%{name: "Chewie", type: :wookie, rebel: true, weight: 350}, | |
%{name: "r2d2", type: :droid, rebel: true, weight: 250}, | |
%{name: "Luke", type: :human, rebel: true, weight: 140}, | |
%{name: "Boba Fett", type: :human, rebel: false, weight: 175}, | |
] | |
# Note that there is more than one correct answer for all of these! |
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
# Create a variable has_seen_star_wars and set it to true. | |
has_seen_star_wars = true | |
# Write code that prints "Ready for class" if you have seen at least one Star Wars movie (has_seen_star_wars). | |
if has_seen_star_wars do | |
IO.puts "Ready for class" | |
end | |
# Flip has_seen_star_wars to false. | |
has_seen_star_wars = false |
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 WhatHappensIn_1_3 do | |
def some_func() do | |
receive do | |
{from, message} -> | |
send from, "hello #{inspect message}" | |
some_func() | |
_ -> | |
IO.puts "quittin' time" | |
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
# this is using sweet_xml | |
xml_string = File.read!("some_file.xml") | |
try do | |
Logger.info(self()) # it does not work without this ... wat? | |
{:ok, xml} = Parser.parse(xml_string) | |
process_xml(conn, xml_string, xml) | |
rescue | |
e -> | |
Logger.info("ignoring unparseable XML file: #{inspect xml_string}") | |
render(conn, "empty.json") |
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 magic(nbr) do | |
a = ~x(a1b2c3d4) | |
b = ~x(d4c3b2a1) | |
c = ~x(a1b23c4d) | |
d = ~x(4d3cb2a1) | |
case nbr do | |
^a -> %Pcap.Global.MagicNumber{ magic_number: nbr, swap_fields: false, nanoseconds: false } | |
^b -> %Pcap.Global.MagicNumber{ magic_number: nbr, swap_fields: true, nanoseconds: false } | |
^c -> %Pcap.Global.MagicNumber{ magic_number: nbr, swap_fields: false, nanoseconds: true } | |
^d -> %Pcap.Global.MagicNumber{ magic_number: nbr, swap_fields: true, nanoseconds: true } |
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 Benum do | |
defimpl Enumerable, for: BitString do | |
def count(collection) when is_binary(collection) do | |
{:ok, Enum.reduce(collection, 0, fn v, acc -> acc + 1 end)} | |
end | |
def count(collection) do | |
{:error, __MODULE__} | |
end | |
def member?(collection, value) when is_binary(collection) do | |
{:ok, Enum.any?(collection, fn v -> value == v 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
vagrant@vagrant-ubuntu-trusty-64:~/irr/irr$ mix deps.compile | |
==> gen_smtp (compile) | |
Compiling src/smtp_rfc822_parse.yrl failed: | |
ERROR: compile failed while processing /home/vagrant/irr/irr/deps/gen_smtp: rebar_abort | |
** (Mix) Could not compile dependency gen_smtp, /home/vagrant/.mix/rebar command failed. If you want to recompile this dependency, please run: mix deps.compile gen_smtp |
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 Permutations do | |
@moduledoc """ | |
An answer to the problem from: http://www.theguardian.com/science/alexs-adventures-in-numberland/2015/may/20/can-you-do-the-maths-puzzle-for-vietnamese-eight-year-olds-that-has-stumped-parents-and-teachers | |
iex> Permutations.main parallel: false | |
iex> Permutations.main parallel: true | |
""" |
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 Clockout.MyViewHelpers do | |
def display_name(:client, id) do | |
Clockout.Client |> display_name_by_id(id) | |
end | |
def display_name(:person, id) do | |
Clockout.Person |> display_name_by_id(id) | |
end |