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
#!/usr/bin/env python3 | |
__all__ = ['logical_xor'] | |
def logical_xor(a, b): | |
# technically, all of the parentheses on the following line may be removed | |
return ((not b) and a) or ((not a) and b) | |
# correct | |
assert logical_xor(True, False) |
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 is_dir_writable(path='.', *, _q=None): | |
import multiprocessing as mp | |
from queue import Empty | |
import tempfile | |
if _q is None: | |
# caller | |
_q = mp.Queue() | |
p = mp.Process( | |
target=is_dir_writable, # IF YOU RENAME THE FUNCTION ENSURE YOU ALSO RENAME ITS INVOCATION HERE | |
args=[path], |
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 ctypes | |
from ctypes import GetLastError, WinError, byref, create_unicode_buffer | |
from uuid import UUID | |
__all__ = ['wintypes_GUID'] | |
_CLSIDFromString = ctypes.windll.Ole32['CLSIDFromString'] | |
_CLSIDFromString.argtypes = [ctypes.c_wchar_p, ctypes.c_void_p] | |
_CO_E_CLASSSTRING = ctypes.c_int(0x800401F3).value # nominally positive, but physically negative on most platforms |
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
#!/usr/bin/env python3 | |
from Crypto.Cipher import AES # https://pypi.org/project/pycryptodome/ | |
from Crypto.Hash import SHAKE256 | |
from types import SimpleNamespace | |
def _demo(): | |
# DEMO | |
from pqc.kem import mceliece6960119f as kemalg # https://pypi.org/project/pypqc/ |
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 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 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
use GenServer | |
def act(action, state, actor \\ nil) | |
def act(_, _, _) do | |
{:error, :badarg} | |
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 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 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 Foo.Application do | |
@moduledoc false | |
use Application | |
@impl true | |
def start(_type, _args) do | |
children = [ | |
FooWeb.Telemetry, | |
Foo.Repo, |
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
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 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 FooApp.Util do | |
@doc """ | |
Exactly like [DynamicSupervisor.start_child/2](https://hexdocs.pm/elixir/1.18/DynamicSupervisor.html#start_child/2) | |
except that the "id" field is not [disregarded](https://hexdocs.pm/elixir/1.15/DynamicSupervisor.html#start_child/2:~:text=while%20the%20:id%20field%20is%20still%20required,the%20value%20is%20ignored), | |
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. |
NewerOlder