defmodule PlugWithCustomCall do
use Plug.Builder
plug Plug.Logger
plug Plug.Head
def call(conn, opts) do
super(conn, opts) # calls Plug.Logger and Plug.Head
assign(conn, :called_all_plugs, true)
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 DNSimpleNumbers do | |
def fetch() do | |
HTTPotion.get("http://localhost:4567/") | |
|> case do | |
%HTTPotion.Response{body: ""} -> nil | |
%HTTPotion.Response{body: number} -> String.to_integer(number) | |
end | |
end | |
def process(number) do |
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 A do | |
use GenStage | |
def start_link(items) do | |
GenStage.start_link(A, items, name: A) | |
end | |
def init(items) do | |
{:producer, Enum.to_list(1..items)} | |
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 MyApp.Repo do | |
use Ecto.Repo, otp_app: :myapp | |
def log(entry) do | |
query_exec_time = (entry.query_time + entry.queue_time || 0) / 1000 | |
query_queue_time (entry.queue_time || 0) / 1000 | |
send_data_to_metrics_collecting_gen_server | |
super entry |
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
diff --git a/mix.lock b/mix.lock | |
index 2b5f9d5..1e934dd 100644 | |
--- a/mix.lock | |
+++ b/mix.lock | |
@@ -1,17 +1,17 @@ | |
-%{"certifi": {:hex, :certifi, "1.0.0", "1c787a85b1855ba354f0b8920392c19aa1d06b0ee1362f9141279620a5be2039", [:rebar3], []}, | |
+%{"certifi": {:hex, :certifi, "1.0.0", "1c787a85b1855ba354f0b8920392c19aa1d06b0ee1362f9141279620a5be2039", [:rebar3], [], "hexpm"}, | |
"dialyxir": {:hex, :dialyxir, "0.5.1", "b331b091720fd93e878137add264bac4f644e1ddae07a70bf7062c7862c4b952", [], [], "hexpm"}, | |
"earmark": {:hex, :earmark, "1.0.1", "2c2cd903bfdc3de3f189bd9a8d4569a075b88a8981ded9a0d95672f6e2b63141", [:mix], []}, | |
"ex_doc": {:hex, :ex_doc, "0.13.0", "aa2f8fe4c6136a2f7cfc0a7e06805f82530e91df00e2bff4b4362002b43ada65", [:mix], [{:earmark, "~> 1.0", [hex: :earmark, optional: false]}]}, |
what do you call a scary alien
a boo-lean
What's the 2nd best variable name?
$data2
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
# assign the prefix to a variable | |
iex(1)> pre = "he" | |
"he" | |
# a string match against the prefix works as expected | |
iex(2)> << "he", rest::binary >> = "hello" | |
"hello" | |
# a string match using the pinned prefix variable doesn't | |
iex(3)> << ^pre, rest::binary >> = "hello" |
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 RFCBinaries do | |
def sigil_b(string, []) do | |
string | |
|> String.split("\n") | |
|> Enum.map(fn(part) -> String.split(part, "|") |> List.first end) | |
|> Enum.map(fn(part) -> String.split(part, " ") end) | |
|> List.flatten | |
|> Enum.filter(&(byte_size(&1) > 0)) | |
|> Enum.map(fn(part) -> String.to_integer(part, 16) end) | |
|> Enum.map(fn(i) -> << i::size(16) >> 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
# The code with some animation logic for demonstration. | |
life=->g,s{(0..s*s-1).map{|i|->n{n==3||(g[i]&&n==2)||nil}[[g[i-s-1],g[i-s],g[i-s+1],g[i-1],g[i+1],g[i+s-1],g[i+s],g[i+s+1]].compact.count]}} | |
size = 160 | |
grid = (1..size*size).map { rand(0..1)==1 ? 1 : nil } | |
require 'json' | |
require 'faraday' | |
conn = Faraday.new(:url => 'http://localhost:3000') do |faraday| | |
faraday.adapter :net_http_persistent # Faraday.default_adapter # make requests with Net::HTTP |
In our daily life we rely heavily on technology. Even as technically advanced people we don’t know every bit involved in the modern web. I will take you on an adventurous tour of browsing the web, understanding the nitty gritty details of networking, name resolution, global network providers, and the HTTP/2 protocol.
NewerOlder