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
| trials = 10_000 | |
| simulation = | |
| 4 | |
| |> Stream.iterate(fn dollars -> | |
| case :rand.uniform(4) do | |
| 1 -> dollars - 1 | |
| 2 -> dollars + 1 | |
| _n -> dollars | |
| 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
| defmodule TicTacToe do | |
| def play do | |
| move(" ", " ", " ", " ", " ", " ", " ", " ", " ", "X") | |
| end | |
| def draw_grid(a1, b1, c1, a2, b2, c2, a3, b3, c3) do | |
| IO.puts "\n a b c " | |
| IO.puts "1 #{a1} | #{b1} | #{c1} " | |
| IO.puts " ---+---+---" | |
| IO.puts "2 #{a2} | #{b2} | #{c2} " |
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 TicTacToe do | |
| def play do | |
| move(" ", " ", " ", " ", " ", " ", " ", " ", " ", "X") | |
| end | |
| def draw_grid(a1, b1, c1, a2, b2, c2, a3, b3, c3) do | |
| IO.puts "\n a b c " | |
| IO.puts "1 #{a1} | #{b1} | #{c1} " | |
| IO.puts " ---+---+---" | |
| IO.puts "2 #{a2} | #{b2} | #{c2} " |
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 SQLTest do | |
| use ExUnit.Case, async: false | |
| alias Replicator.{Config, Database, Connection, TestHelper} | |
| defmodule Examples do | |
| use Replicator.SQL | |
| none(:prepare, "CREATE TABLE examples (id SERIAL, name TEXT)") | |
| none(:insert, "INSERT INTO examples (name) VALUES ($name)") |
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
| tell application "OmniFocus" | |
| tell default document | |
| set work_project to first flattened project whose name is "Close PivotalTracker Stories" | |
| set work_tasks to flattened tasks of work_project | |
| set tasks_string to "" | |
| repeat with the_task in work_tasks | |
| set task_name to the name of the_task | |
| if completed of the_task then | |
| set task_status to "delivered" | |
| else |
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 Fermat do | |
| require Integer | |
| def mpow(n, 1, _m), do: n | |
| def mpow(n, k, m) when Integer.is_even(k) do | |
| x = mpow(n, div(k, 2), m) | |
| rem((x * x), m) | |
| end | |
| def mpow(n, k, m) when Integer.is_odd(k) do | |
| x = mpow(n, k - 1, m) |
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 Gunfight do | |
| defstruct shooters: %{ }, kills: "" | |
| @result_limit :math.pow(10, 9) |> Kernel.+(9) |> round | |
| def new, do: %__MODULE__{ } | |
| def point(%__MODULE__{shooters: shooters} = gunfight, pointer, "0") do | |
| %__MODULE__{gunfight | shooters: Map.delete(shooters, pointer)} | |
| 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
| --- | |
| - hosts: builders | |
| tasks: | |
| - name: Fetch Erlang Solutions repository | |
| get_url: | |
| url: https://packages.erlang-solutions.com/erlang-solutions_1.0_all.deb | |
| dest: /tmp/erlang-solutions_1.0_all.deb | |
| - name: Add Erlang Solutions repository | |
| become: true | |
| apt: |
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 Counter | |
| def initialize(initial_count = 0) | |
| @mailbox = Queue.new | |
| @replies = Queue.new | |
| @state = initial_count | |
| @server = process_messages | |
| end | |
| def increment | |
| mailbox.push([:handle_increment, 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 TypeSpecs do | |
| def for_module(module) do | |
| {:ok, {^module, [{:abstract_code, {:raw_abstract_v1, attributes}}]}} = | |
| module |> :code.which |> :beam_lib.chunks([:abstract_code]) | |
| attributes | |
| |> Enum.filter_map(fn | |
| {:attribute, _, :spec, _function_and_types} -> true | |
| _attribute -> false | |
| end, fn {:attribute, _, :spec, function_and_types} -> | |
| function_and_types |
NewerOlder