Skip to content

Instantly share code, notes, and snippets.

View zookzook's full-sized avatar

Michael Maier zookzook

View GitHub Profile
@zookzook
zookzook / utilization.js
Created September 5, 2024 06:48
Scheduler utilization with D3.js
import * as d3 from "d3";
function extentTime(ref) {
let to = ref || new Date();
let totalMilliSeconds = to.getTime();
let millisecondsToSubtract = 60 * 1000;
let from = new Date(totalMilliSeconds - millisecondsToSubtract);
return d3.extent([from, to]);
}
@zookzook
zookzook / generator.ex
Created March 10, 2020 09:13
Generator
defmodule PolarisWeb.Generator do
@moduledoc false
use Phoenix.ConnTest
@endpoint PolarisWeb.Endpoint
def generate() do
conn = Phoenix.ConnTest.build_conn()
base = Application.get_env(:polaris, :generator)[:out]
@zookzook
zookzook / paragraph.conf
Last active March 11, 2020 09:21
Example: Paragraph
{
text: """
|## Phoenix Web-Framework ##
|
|I'll show you how we create a boilerplate code that has all the necessary functions to get you started quickly.
|This code is then ready for further adjustments and changes. First we create a Phoenix project without
|database connection:
|
|```elixir
|#> mix phx.new polaris --no-ecto
<div class="row">
<article class="column">
<%= @paragraph["text"] |> strip_margin() |> markdown() |> raw() %>
</article>
</div>
<%= if length(@paragraph["images"]) > 0 do %>
<div class="row">
<%= for img <- @paragraph["images"] do %>
<div class="column">
<figure>
@zookzook
zookzook / index.html.eex
Last active March 10, 2020 07:36
Index-Page
<section>
<div class="row">
<div class="column">
<h1><%= @page_title%></h1>
</div>
</div>
<%= render_many @pars, PolarisWeb.PageView, "paragraph.html", as: :paragraph, conn: @conn %>
</section>
defmodule PolarisWeb.PageView do
use PolarisWeb, :view
def markdown(string) do
with {:ok, html_doc, []} <- Earmark.as_html(strip_margin(string)) do
html_doc
end
end
def strip_margin(string) do
@zookzook
zookzook / page_controller.ex
Last active March 10, 2020 07:36
PageController
defmodule PolarisWeb.PageController do
use PolarisWeb, :controller
alias Polaris.Page
def index(conn, _params) do
%Page{title: title, content: content} = Polaris.Site.index()
conn
|> assign(:page_title, title)
@zookzook
zookzook / site.ex
Created March 7, 2020 15:12
Module Site
defmodule Polaris.Site do
@moduledoc false
alias Polaris.Page
pages_paths = "hocon/**/*.conf" |> Path.wildcard() |> Enum.sort()
pages = for page_path <- pages_paths do
@external_resource Path.relative_to_cwd(page_path)
Page.parse!(page_path)
@zookzook
zookzook / page.ex
Created March 7, 2020 15:09
Page.ex
defmodule Polaris.Page do
@moduledoc false
alias Polaris.Page
@enforce_keys [:filename, :title, :content]
defstruct [:filename, :section, :title, :content]
def parse!(filename) do
@zookzook
zookzook / decode.ex
Created March 7, 2020 14:57
Hocon-Decode-Example
iex(9)> Hocon.decode(File.read!("./hocon/index.conf"))
{:ok,
%{
"pars" => [
%{
"text" => "|## Introduction ##\n |\n |Phoenix is not only an excellent web framework, but also it can be transformed with a few steps into a\n |static content generator. You need some programming knowledge, so this way is\n |rather something for developers.\n |\n |Usually a static content generator is a system that reads a text document with a few\n |meta-information such as author, date, title and a markdown block to produce\n |HTML files, which can be uploaded to a web server.\n |\n |There are a lot of existing solutions for this, so why would you create a new system\n |develop? Let's take a look at the current limits. Maybe we can find this something\n |to the back.\n |\n |### text documents ###\n |Usually, the structure of a document is rigid and sim