Skip to content

Instantly share code, notes, and snippets.

@ondrej-tucek
ondrej-tucek / collatz.ex
Created November 1, 2020 11:10
Collatz sequence
require Integer
collatz = fn
n when Integer.is_even(n) -> div(n, 2)
n when Integer.is_odd(n) -> 3*n + 1
end
n = 27
Stream.iterate(n, &collatz.(&1)) |> Enum.take(10)

some tools for diagrams in software documentation

Diagrams For Documentation

Obvious Choices

ASCII

@ondrej-tucek
ondrej-tucek / Map.Helpers
Created September 23, 2020 09:43 — forked from kipcole9/Map.Helpers
Helpers for Elixir Maps: underscore, atomise and stringify map keys
defmodule Map.Helpers do
@moduledoc """
Functions to transform maps
"""
@doc """
Convert map string camelCase keys to underscore_keys
"""
def underscore_keys(nil), do: nil

Install RabbitMQ on Ubuntu 16.04

Install Erlang

wget https://packages.erlang-solutions.com/erlang-solutions_1.0_all.deb
sudo dpkg -i erlang-solutions_1.0_all.deb
sudo apt-get update -y
sudo apt-get install -y erlang erlang-nox
DROP FUNCTION if exists aggregate_data(tbl_from text, tbl_to text);
CREATE OR REPLACE FUNCTION aggregate_data(tbl_from text, tbl_to text) RETURNS void AS $$
DECLARE
parsed_time text = split_part(tbl_to, 'agg_', 2);
time_val text;
BEGIN
CASE parsed_time
WHEN '1m' THEN
time_val = '1 minute';
@ondrej-tucek
ondrej-tucek / parse.md
Created February 8, 2019 11:06
Elixir pattern for list splitting
[fl, sl, v] =
  [1, 2, 3, 4, 5, 6, 7, 8, 9]
  |> Enum.with_index()
  |> Enum.reduce([], fn
    {v, idx}, acc when idx < 4 -> [v | acc]
    {v, idx}, acc when idx == 4 -> [[], acc | [v]]
    {v, idx}, [hd | tl] when idx > 4 -> [[v | hd] | tl]
  end)
 
@ondrej-tucek
ondrej-tucek / weather_data.json
Created January 31, 2019 09:32
Data for elm-forecast.surge.sh
{
"location": {
"woeid": 2502265,
"city": "Sunnyvale",
"region": " CA",
"country": "United States",
"lat": 37.371609,
"long": -122.038254,
"timezone_id": "America/Los_Angeles"
},
@ondrej-tucek
ondrej-tucek / influxdb-setup.md
Created January 21, 2019 11:07 — forked from travisjeffery/influxdb-setup.md
Guide to setting up InfluxData's TICK stack

Guide to setting up InfluxData's TICK stack

InfluxData's T.I.C.K. stack is made up from the following components:

Component Role
Telegraf Data collector
InfluxDB Stores data
Chronograf Visualizer
@ondrej-tucek
ondrej-tucek / Language.elm
Created April 11, 2018 09:56 — forked from hipertracker/Language.elm
Elm decoders for nested JSON structures
module Models.Language exposing (..)
import Json.Decode exposing (int, string, decodeString, Decoder)
import Json.Decode.Pipeline exposing (decode, required)
type alias Language =
{ id : Int
, name : String
, label : String
@ondrej-tucek
ondrej-tucek / README.md
Created November 19, 2016 13:10 — forked from hofmannsven/README.md
My simply Git Cheatsheet