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 Queue do | |
| use GenServer | |
| def start_link(queue, name) do | |
| GenServer.start(__MODULE__, queue, name: name) | |
| end | |
| # GenServer callbacks | |
| def handle_call(:get, _from, [item | queue]) 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 Tester do | |
| def start_run do | |
| Agent.start(fn -> [total: 0, passed: 0, failed: 0] end, name: :test_stats) | |
| end | |
| def record_pass do | |
| Agent.update(:test_stats, fn [total: t, passed: p, failed: f] -> | |
| [total: t + 1, passed: p + 1, failed: f] | |
| end) | |
| 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 KV.Registry do | |
| use GenServer | |
| ## Missing Client API - will add this later | |
| ## Defining GenServer Callbacks | |
| @impl true | |
| def init(:ok) do | |
| {:ok, %{}} |
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 Stack do | |
| use GenServer | |
| # Client | |
| def start_link(default) when is_list(default) do | |
| GenServer.start_link(__MODULE__, default) | |
| end | |
| def push(pid, element) 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 Counter do | |
| use Agent | |
| def start_link(initial_value) do | |
| Agent.start_link(fn -> initial_value end, name: __MODULE__) | |
| end | |
| def value do | |
| Agent.get(__MODULE__, & &1) | |
| 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 MovieData do | |
| def start_link do | |
| Agent.start_link(fn -> %{} end) | |
| end | |
| def add(pid, movie) do | |
| Agent.update(pid, fn(state) -> | |
| Map.put(state, movie, 1) | |
| 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
| def create_comment(attrs \\ %{}) do | |
| %Comment{} | |
| |> Comment.changeset(attrs) | |
| # TODO how to I get "post" here, to do the following step? | |
| # |> Ecto.Changeset.put_assoc(:post, post) | |
| |> Repo.insert() | |
| 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
| // replicating SwitftUI Spacer() in React | |
| import * as React from "react" | |
| export function Spacer() { | |
| return <div style={{ flex: "1 1 0" }}> </div> | |
| } |
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
| // | |
| // Modal sheets on top of each other in SwiftUI | |
| // Testing the possibilities | |
| // | |
| // ContentView.swift | |
| // navTest1 | |
| // | |
| // Created by JOSEF RICHTER on 04/03/2020. | |
| // Copyright © 2020 JOSEF RICHTER. Licence: do whatever you want, aka WTFPL http://www.wtfpl.net | |
| // |
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
| import * as React from "react" | |
| import { | |
| Frame, | |
| FrameProps, | |
| addPropertyControls, | |
| ControlType, | |
| } from "framer" | |
| type Props = Partial<FrameProps> & |