This file contains hidden or 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
| test "/index returns a list of contacts" do | |
| contacts_as_json = | |
| %Contact{name: "Gumbo", phone: "(801) 555-5555"} | |
| |> Repo.insert | |
| |> List.wrap | |
| |> Poison.encode! | |
| response = conn(:get, "/api/contacts") |> send_request | |
| assert response.status == 200 |
This file contains hidden or 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 Math do | |
| def times_three(n), do: n * 3 | |
| def odd?(n), do: rem(n, 2) != 0 | |
| end | |
| Enum.sum( | |
| Enum.filter( | |
| Enum.map(1..100_000, &(Math.times_three/1)), &(Math.odd?/1))) |
This file contains hidden or 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 Recursive do | |
| def sum([head | []]), do: head | |
| def sum([head | [head2 | tail]]), do: sum([head + head2 | tail]) | |
| end | |
| Recursive.sum([1,2,3]) # => 6 |
This file contains hidden or 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
| # Functions can put assignment logic in the arguments | |
| [head | tail] = [1, 2, 3] | |
| head | |
| # => 1 | |
| tail | |
| # => [2, 3] |
This file contains hidden or 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 D do | |
| def add(a, b, c), do: a + b + c # Arity 3 | |
| def add(b, b), do: 3 * b # Pattern matching | |
| def add("i", b), do: "#{b}i" # Pattern matching | |
| def add(a, _), do: a + a # Strange default, but we'll go with it | |
| def add(_), do: IO.puts "Can't add one number, silly" | |
| end |
This file contains hidden or 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
| # Basic function | |
| defmodule A do | |
| def add(a, b) do | |
| a + b | |
| end | |
| end | |
| A.add(1, 2) | |
| # => 3 |
This file contains hidden or 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
| # imports and basic notebook setup | |
| from cStringIO import StringIO | |
| import numpy as np | |
| import scipy.ndimage as nd | |
| import PIL.Image | |
| import sys | |
| from IPython.display import clear_output, Image, display | |
| from google.protobuf import text_format | |
| import caffe |
This file contains hidden or 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
| # imports and basic notebook setup | |
| from cStringIO import StringIO | |
| import numpy as np | |
| import scipy.ndimage as nd | |
| import PIL.Image | |
| from IPython.display import clear_output, Image, display | |
| from google.protobuf import text_format | |
| import caffe |
This file contains hidden or 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
| require 'open-uri' | |
| puts "URL: " + (url_string = "http://www.xeno-canto.org/164#{rand(100..999)}/download") | |
| begin | |
| File.open("sound.mp3", "wb") do |f| | |
| open(url_string) do |url| | |
| url.each_line {|u| f.write u} | |
| end | |
| end |
This file contains hidden or 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
| class NotObject | |
| def initialize(obj) | |
| @obj = obj | |
| end | |
| def method_missing(method, *arguments) | |
| [email protected](method, *arguments) | |
| end | |
| end |