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 Anagram do | |
#### | |
# given a word, return a list of anagrams | |
def anagrams_of(word) do | |
Keyword.get(dictionary, signature(word), []) | |
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
require 'fiddle' | |
include Fiddle | |
user32 = DL.dlopen("user32.dll") | |
msgbox = Fiddle::Function.new(user32['MessageBoxA'], | |
[TYPE_LONG, TYPE_VOIDP, TYPE_VOIDP, TYPE_INT], | |
TYPE_INT) | |
MB_OKCANCEL = 1 | |
msgbox.call(0, "OK?", "Please Confirm", MB_OKCANCEL) |
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 Mix.Tasks.Doctest do | |
use Mix.Task | |
@shortdoc "Run the doctests for one or more files" | |
# Just for testing.... | |
defmodule Wombat do | |
@moduledoc """ | |
iex> 1 | |
1 |
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
defrecord Person, name: "", age: 0 | |
dave = Person.new name: "Dave", age: 27 | |
case dave do | |
Person[age: age] = record -> #<< ** (RuntimeError) expected module Person to be loaded and defined | |
... | |
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 Issues.GithubIssues do | |
alias HTTPotion.Response | |
def fetch(user, project) do | |
HTTPotion.start | |
case HTTPotion.get(issues_url(user, project)) do | |
Response[body: body, status_code: status, headers: headers ] -> | |
IO.puts inspect status |
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 FibSolver do | |
def fib(scheduler) do | |
scheduler <- { :ready, self } | |
receive do | |
{ :fib, n, client } -> | |
client <- { :answer, n, fib_calc(n), self } | |
fib(scheduler) | |
{:shutdown} -> | |
exit(0) |
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
defprotocol WhizBang do | |
def specific(_) | |
def common(_) | |
end | |
defrecord Foo, name: "foo" | |
defrecord Bar, name: "bar" | |
defmodule Common do | |
def common(arg), do: IO.puts "Common.common: #{inspect arg}" |
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
<?xml version="1.0" encoding="UTF-8"?> <!-- -*- xml -*- --> | |
<!DOCTYPE ref-class SYSTEM "local/xml/markup.dtd"> | |
<ref-class name="Array" id="ref:Array" super-class="Object"> | |
<mi:Class>Array</mi:Class> | |
<relies-on>each, <=></relies-on> | |
<p> | |
Arrays are ordered, integer-indexed collections of any object. | |
Array indexes start at 0, as in C or Java. A negative index is | |
relative to the end of the array; that is, an index of -1 |
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 A do | |
def c(name) do | |
IO.puts "In c(#{name})" | |
end | |
end | |
wrapper = quote do | |
defmodule Wrapper 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
import :timer, only: [ sleep: 1 ] | |
defmodule Link1 do | |
def sad_method do | |
sleep 500 | |
exit(99) | |
end | |
def run do | |
spawn(Link1, :sad_method, []) |