Skip to content

Instantly share code, notes, and snippets.

View OleMchls's full-sized avatar
🎯
Focusing

Ole Michaelis OleMchls

🎯
Focusing
View GitHub Profile
@OleMchls
OleMchls / dnsimple_numbers.ex
Last active August 17, 2018 14:05
Low Volume GenStage
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
@OleMchls
OleMchls / A.ex
Created July 25, 2018 12:03
gen stage finite demand
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
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
@OleMchls
OleMchls / -
Created November 1, 2017 09:50
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]}]},
@OleMchls
OleMchls / file1.md
Last active May 1, 2017 19:28
elixirconfeu2017.snips
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
@OleMchls
OleMchls / jokes.md
Last active September 9, 2016 10:21
Jokes for a failing AV system during your talk

what do you call a scary alien

a boo-lean

What's the 2nd best variable name?

$data2

@OleMchls
OleMchls / example.esx
Created March 23, 2016 11:19
elixir_string_match
# 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"
@OleMchls
OleMchls / sigil.ex
Created March 9, 2016 20:32
HPACK RFC Binary sigil
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)
@OleMchls
OleMchls / demo.rb
Created October 23, 2015 14:50
golaas.com sample ruby implementation
# 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
@OleMchls
OleMchls / abstract.md
Created September 29, 2015 10:01
A tale of adventures in technology when loading a website

A tale of adventures in technology when loading a website

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.