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
var peer1 = new SimplePeer({ initiator: true }); | |
var peer2 = new SimplePeer(); | |
peer1.on('signal', function (data) { | |
// when peer1 has signaling data, give it to peer2 | |
peer2.signal(data); | |
}); | |
peer2.on('signal', function (data) { | |
// same as above, but in reverse |
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
var peer = new SimplePeer({ initiator: true }); | |
peer.on('signal', function (data) { | |
channel.trigger('client-signal-' + peerUserId, { userId: currentUser.id, data: data }); | |
}); | |
peer.on('ready', function () { | |
peer.send('hey peer, how is it going?') | |
}); |
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
navigator.getUserMedia({ video: true, audio: true }, function(stream) { | |
currentUser.stream = stream; | |
}, function() {}); | |
// ... | |
peer = new SimplePeer({ stream: currentUser.stream }); | |
peer.on('stream', function(stream) { | |
var video = document.querySelector("video"); |
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 CombinationsBenchmark do | |
def combinations(collection, k) do | |
List.last(do_combinations(collection, k)) | |
end | |
defp do_combinations(list, k) do | |
combinations_by_length = [[[]]|List.duplicate([], k)] | |
List.foldr list, combinations_by_length, fn x, next -> | |
sub = :lists.droplast(next) |
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 MessageSpammer.Connector do | |
use Supervisor | |
def start_link do | |
Supervisor.start_link(__MODULE__, []) | |
end | |
def init(_) do | |
IO.puts "Starting Connector" | |
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 ConcurrentAcceptance.AcceptanceCase do | |
use ExUnit.CaseTemplate | |
using do | |
quote do | |
use Hound.Helpers | |
import Ecto.Model | |
import Ecto.Query, only: [from: 2] | |
import ConcurrentAcceptance.Router.Helpers |
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
config :concurrent_acceptance, sql_sandbox: true |
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 ConcurrentAcceptance.Endpoint do | |
# rest of endpoint omitted | |
if Application.get_env(:concurrent_acceptance, :sql_sandbox) do | |
plug Phoenix.Ecto.SQL.Sandbox | |
end | |
plug ConcurrentAcceptance.Router | |
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 Phoenix.Ecto.SQL.Sandbox do | |
import Plug.Conn | |
@cookie_name "phoenix.ecto.sql.sandbox" | |
def init(opts), do: opts | |
def call(%{request_path: @config_path <> configuration} = conn, _opts) do | |
conn |> put_resp_cookie(@cookie_name, configuration) |> send_resp(200, "OK") |> halt | |
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 Phoenix.Ecto.SQL.Sandbox do | |
# ... | |
def call(conn, sandbox) do | |
conn |> fetch_cookies |> allow_sandbox_access(sandbox) | |
end | |
defp allow_sandbox_access(%{req_cookies: %{@cookie_name => configuration}} = conn, sandbox) do | |
[pid_string,repo_string] = configuration |> URI.decode |> String.split("|") | |
owner = to_pid(pid_string) |