Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Ole Michaelis OleMchls

🎯
Focusing
View GitHub Profile
@OleMchls
OleMchls / dnsimple_numbers.ex
Last active Aug 17, 2018
Low Volume GenStage
View dnsimple_numbers.ex
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 Jul 25, 2018
gen stage finite demand
View A.ex
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
View repo.ex
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
View -
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
elixirconfeu2017.snips
View file1.md
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 Sep 9, 2016
Jokes for a failing AV system during your talk
View jokes.md

what do you call a scary alien

a boo-lean

What's the 2nd best variable name?

$data2

@OleMchls
OleMchls / example.esx
Created Mar 23, 2016
elixir_string_match
View example.esx
# 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 Mar 9, 2016
HPACK RFC Binary sigil
View sigil.ex
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 Oct 23, 2015
golaas.com sample ruby implementation
View demo.rb
# 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 Sep 29, 2015
A tale of adventures in technology when loading a website
View abstract.md

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.