This file contains 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 FooWeb.Util do | |
# https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#valid-local-date-and-time-string | |
@spec parse_web_time!(String.t()) :: NaiveDateTime.t() | |
@spec parse_web_time!(String.t(), Calendar.time_zone()) :: DateTime.t() | |
@spec parse_web_time!(String.t(), Calendar.time_zone(), Calendar.time_zone_database()) :: DateTime.t() | |
def parse_web_time!(<<s::binary-size(16)>>) do | |
Timex.parse!(s, "{YYYY}-{0M}-{0D}T{h24}:{m}") | |
end | |
def parse_web_time!(<<s::binary-size(19)>>) do | |
Timex.parse!(s, "{YYYY}-{0M}-{0D}T{h24}:{m}:{s}") |
This file contains 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
use GenServer | |
def act(action, state, actor \\ nil) | |
@impl true | |
def handle_call({:act, actor, action}, _from, state) do | |
case act(action, state, actor) do | |
:ok -> | |
# call succeeded; no specific reply; state unchanged | |
{:reply, :ok, state} |
This file contains 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 FooWeb.CoreComponents do | |
@moduledoc """ | |
Provides core UI components. | |
At first glance, this module may seem daunting, but its goal is to provide | |
core building blocks for your application, such as modals, tables, and | |
forms. The components consist mostly of markup and are well-documented | |
with doc strings and declarative assigns. You may customize and style | |
them in any way you want, based on your application growth and needs. |
This file contains 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 Foo.Application do | |
@moduledoc false | |
use Application | |
@impl true | |
def start(_type, _args) do | |
children = [ | |
FooWeb.Telemetry, | |
Foo.Repo, |
This file contains 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
function [intensities, wavelengths, t] = load_oceanView(filesGlobString) | |
%load_oceanVew | |
% - output is INSTANTLY ready to be graphed | |
% via surf(t, wavelengths, intensities) | |
% - does NOT fail on data that's non-uniform in time | |
% e.g. when OceanView malfunctions | |
files = matlab.buildtool.io.FileCollection.fromPaths( ... | |
replace(filesGlobString,'/',filesep)); | |
paths = files.paths; |
This file contains 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 Foo.Util do | |
@doc """ | |
Exactly like [DynamicSupervisor.start_child/2](https://hexdocs.pm/elixir/1.17/DynamicSupervisor.html#start_child/2) | |
except that the "id" field is not [disregarded](https://hexdocs.pm/elixir/1.17/Supervisor.html#module-child-specification), | |
but instead used as a unique key. | |
Only works with simple GenServer supervisees for now. | |
Does NOT work with remote DynamicSupervor or distributed systems for now. |
This file contains 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
from contextlib import contextmanager | |
from datetime import date, timedelta | |
from functools import reduce | |
from gettext import dgettext | |
import re | |
import traceback | |
from types import SimpleNamespace | |
import uuid | |
from beancount.core.account import join as account_join, leaf, root, sans_root |
This file contains 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
from contextlib import contextmanager | |
import re | |
import traceback | |
from beancount.core.data import * | |
from beancount.core.prices import get_price, build_price_map | |
from beancount.plugins.implicit_prices import ImplicitPriceError as ImplicitPriceError_t | |
"""Beancount plugin to make certain prices transitive |
This file contains 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
/* pending https://github.com/tc39/proposal-explicit-resource-management */ | |
/* Usage: | |
let result = await use_resource({ | |
async acquire(url) { | |
// "__enter__" | |
const e = document.createElement('iframe'); | |
e.src = url; | |
e.hidden = true; |
This file contains 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 queue | |
import logging | |
from tkinter import TclError | |
import weakref | |
def data_bind(widget, callback, *, pass_tk_event=False, timeout=0.0, catastrophic_timeout=30.0): | |
"""Foolproof, thread-safe workaround for https://github.com/python/cpython/issues/47655 | |
https://tkdocs.com/tutorial/eventloop.html | |
> If you need to communicate from another thread to the thread running |
NewerOlder