8 Commits

10 changed files with 303 additions and 57 deletions

View File

@@ -4,38 +4,57 @@
;; sync' after modifying this file! ;; sync' after modifying this file!
;; Some functionality uses this to identify you, e.g. GPG configuration, email ;; Some functionality uses this to identify you, e.g. GPG configuration, email
;; clients, file templates and snippets. ;; clients, file templates and snippets. It is optional.
(setq user-full-name "Max Regan" (setq user-full-name "Max Regan"
user-mail-address "mgregan2@gmail.com") user-mail-address "mgregan2@gmail.com")
;; Doom exposes five (optional) variables for controlling fonts in Doom. Here ;; Doom exposes five (optional) variables for controlling fonts in Doom:
;; are the three important ones:
;; ;;
;; + `doom-font' ;; - `doom-font' -- the primary font to use
;; + `doom-variable-pitch-font' ;; - `doom-variable-pitch-font' -- a non-monospace font (where applicable)
;; + `doom-big-font' -- used for `doom-big-font-mode'; use this for ;; - `doom-big-font' -- used for `doom-big-font-mode'; use this for
;; presentations or streaming. ;; presentations or streaming.
;; - `doom-unicode-font' -- for unicode glyphs
;; - `doom-serif-font' -- for the `fixed-pitch-serif' face
;; ;;
;; They all accept either a font-spec, font string ("Input Mono-12"), or xlfd ;; See 'C-h v doom-font' for documentation and more examples of what they
;; font string. You generally only need these two: ;; accept. For example:
;; (setq doom-font (font-spec :family "monospace" :size 12 :weight 'semi-light) ;;
;; doom-variable-pitch-font (font-spec :family "sans" :size 13)) ;;(setq doom-font (font-spec :family "Fira Code" :size 12 :weight 'semi-light)
;; doom-variable-pitch-font (font-spec :family "Fira Sans" :size 13))
;;
;; If you or Emacs can't find your font, use 'M-x describe-font' to look them
;; up, `M-x eval-region' to execute elisp code, and 'M-x doom/reload-font' to
;; refresh your font settings. If Emacs still can't find your font, it likely
;; wasn't installed correctly. Font issues are rarely Doom issues!
;; There are two ways to load a theme. Both assume the theme is installed and ;; There are two ways to load a theme. Both assume the theme is installed and
;; available. You can either set `doom-theme' or manually load a theme with the ;; available. You can either set `doom-theme' or manually load a theme with the
;; `load-theme' function. This is the default: ;; `load-theme' function. This is the default:
(setq doom-theme 'doom-one) (setq doom-theme 'doom-1337)
;; If you use `org' and don't want your org files in the default location below,
;; change `org-directory'. It must be set before org loads!
(setq org-directory "~/org/")
;; This determines the style of line numbers in effect. If set to `nil', line ;; This determines the style of line numbers in effect. If set to `nil', line
;; numbers are disabled. For relative line numbers, set this to `relative'. ;; numbers are disabled. For relative line numbers, set this to `relative'.
(setq display-line-numbers-type t) (setq display-line-numbers-type t)
;; If you use `org' and don't want your org files in the default location below,
;; change `org-directory'. It must be set before org loads!
(setq org-directory "~/org/")
;; Here are some additional functions/macros that could help you configure Doom: ;; Whenever you reconfigure a package, make sure to wrap your config in an
;; `after!' block, otherwise Doom's defaults may override your settings. E.g.
;;
;; (after! PACKAGE
;; (setq x y))
;;
;; The exceptions to this rule:
;;
;; - Setting file/directory variables (like `org-directory')
;; - Setting variables which explicitly tell you to set them before their
;; package is loaded (see 'C-h v VARIABLE' to look up their documentation).
;; - Setting doom variables (which start with 'doom-' or '+').
;;
';; Here are some additional functions/macros that will help you configure Doom.
;; ;;
;; - `load!' for loading external *.el files relative to this one ;; - `load!' for loading external *.el files relative to this one
;; - `use-package!' for configuring packages ;; - `use-package!' for configuring packages
@@ -48,6 +67,8 @@
;; To get information about any of these functions/macros, move the cursor over ;; To get information about any of these functions/macros, move the cursor over
;; the highlighted symbol at press 'K' (non-evil users must press 'C-c c k'). ;; the highlighted symbol at press 'K' (non-evil users must press 'C-c c k').
;; This will open documentation for it, including demos of how they are used. ;; This will open documentation for it, including demos of how they are used.
;; Alternatively, use `C-h o' to look up a symbol (functions, variables, faces,
;; etc).
;; ;;
;; You can also try 'gd' (or 'C-c c d') to jump to their definition and see how ;; You can also try 'gd' (or 'C-c c d') to jump to their definition and see how
;; they are implemented. ;; they are implemented.
@@ -64,9 +85,10 @@
(all-the-icons-ivy-rich-mode 1)) (all-the-icons-ivy-rich-mode 1))
(use-package! mgr-gitlab (use-package! mgr-gitlab
:load-path "~/.doom.d/lisp/mgr-gitlab" :load-path "lisp/mgr-gitlab"
:ensure t
:config :config
(setq gitlab-host "gitlab.maxregan.me" (setq gitlab-host "https://gitlab.maxregan.me"
gitlab-token-id (if (file-exists-p mgr-gitlab-token-file) gitlab-token-id (if (file-exists-p mgr-gitlab-token-file)
(with-temp-buffer (with-temp-buffer
(insert-file-contents mgr-gitlab-token-file) (insert-file-contents mgr-gitlab-token-file)
@@ -77,3 +99,51 @@
(recents . 5) (recents . 5)
(agenda . 5) (agenda . 5)
(projects . 5)))) (projects . 5))))
(use-package! persp-mode
:config
(setq persp-emacsclient-init-frame-behaviour-override "main"))
;; Hey doom, +ivy/compile is worse, give me projectile-compile-project back
(define-key (current-global-map) [remap projectile-compile-project] 'projectile-compile-project)
(use-package! denote
:config (setq denote-known-keywords '("meta" "emacs")
denote-directory "~/notes/denote"))
(use-package! uniquify
:config
(setq uniquify-buffer-name-style 'post-forward))
(use-package! clipetty
:config (global-clipetty-mode 1))
(use-package! vterm
:config
(push '("magit" magit) vterm-eval-cmds)
(push '("compile" compile) vterm-eval-cmds))
(use-package! with-editor
:config
(add-hook 'shell-mode-hook 'with-editor-export-editor)
(add-hook 'eshell-mode-hook 'with-editor-export-editor)
(add-hook 'term-exec-hook 'with-editor-export-editor)
(add-hook 'vterm-exec-hook 'with-editor-export-editor))
;; Utils for pinning buffers in windows. This is useful for compilation and shells.
(defun dedicate-window ()
(interactive)
(set-window-dedicated-p (get-buffer-window) t))
(defun undedicate-window ()
(interactive)
(set-window-dedicated-p (get-buffer-window) nil))
(defun disable-format-on-save ()
(interactive)
(format-all-mode -1))
;; Load optional site-specific config (e.g. work profiles)
(if (file-exists-p "~/.doom-site/config.el")
(load-file "~/.doom-site/config.el"))

View File

@@ -4,8 +4,8 @@
;; in. Remember to run 'doom sync' after modifying it! ;; in. Remember to run 'doom sync' after modifying it!
;; NOTE Press 'SPC h d h' (or 'C-h d h' for non-vim users) to access Doom's ;; NOTE Press 'SPC h d h' (or 'C-h d h' for non-vim users) to access Doom's
;; documentation. There you'll find a "Module Index" link where you'll find ;; documentation. There you'll find a link to Doom's Module Index where all
;; a comprehensive list of Doom's modules and what flags they support. ;; of our modules are listed, including what flags they support.
;; NOTE Move your cursor over a module's name (or its flags) and press 'K' (or ;; NOTE Move your cursor over a module's name (or its flags) and press 'K' (or
;; 'C-c c k' for non-vim users) to view its documentation. This works on ;; 'C-c c k' for non-vim users) to view its documentation. This works on
@@ -15,23 +15,27 @@
;; directory (for easy access to its source code). ;; directory (for easy access to its source code).
(doom! :input (doom! :input
;;bidi ; (tfel ot) thgir etirw uoy gnipleh
;;chinese ;;chinese
;;japanese ;;japanese
;;layout ; auie,ctsrnm is the superior home row ;;layout ; auie,ctsrnm is the superior home row
:completion :completion
company ; the ultimate code completion backend company ; the ultimate code completion backend
;;helm ; the *other* search engine for love and life ;;helm ; the *other* search engine for love and life
;;ido ; the other *other* search engine... ;;ido ; the other *other* search engine...
;;ivy ; a search engine for love and life ;;ivy ; a search engine for love and life
vertico ; the search engine of the future vertico ; the search engine of the future
:ui :ui
;;deft ; notational velocity for Emacs ;;deft ; notational velocity for Emacs
doom ; what makes DOOM look the way it does doom ; what makes DOOM look the way it does
doom-dashboard ; a nifty splash screen for Emacs ;;doom-dashboard ; a nifty splash screen for Emacs
;; doom-quit ; DOOM quit-message prompts when you quit Emacs ;;doom-quit ; DOOM quit-message prompts when you quit Emacs
(emoji +unicode) ; 🙂 (emoji
+unicode
+github
+ascii) ; 🙂
hl-todo ; highlight TODO/FIXME/NOTE/DEPRECATED/HACK/REVIEW hl-todo ; highlight TODO/FIXME/NOTE/DEPRECATED/HACK/REVIEW
;;hydra ;;hydra
;;indent-guides ; highlighted indent columns ;;indent-guides ; highlighted indent columns
@@ -44,7 +48,7 @@
(popup +defaults) ; tame sudden yet inevitable temporary windows (popup +defaults) ; tame sudden yet inevitable temporary windows
;;tabs ; a tab bar for Emacs ;;tabs ; a tab bar for Emacs
;;treemacs ; a project drawer, like neotree but cooler ;;treemacs ; a project drawer, like neotree but cooler
;;unicode ; extended unicode support for various languages unicode ; extended unicode support for various languages
vc-gutter ; vcs diff in the fringe vc-gutter ; vcs diff in the fringe
vi-tilde-fringe ; fringe tildes to mark beyond EOB vi-tilde-fringe ; fringe tildes to mark beyond EOB
window-select ; visually switch windows window-select ; visually switch windows
@@ -66,7 +70,7 @@
word-wrap ; soft wrapping with language-aware indent word-wrap ; soft wrapping with language-aware indent
:emacs :emacs
(dired +icons) ; making dired pretty [functional] (dire + icons) ; making dired pretty [functional]
electric ; smarter, keyword-based electric-indent electric ; smarter, keyword-based electric-indent
;;ibuffer ; interactive buffer management ;;ibuffer ; interactive buffer management
undo ; persistent, smarter undo for your inevitable mistakes undo ; persistent, smarter undo for your inevitable mistakes
@@ -85,6 +89,7 @@
:tools :tools
;;ansible ;;ansible
;;biblio ; Writes a PhD for you (citation needed)
debugger ; FIXME stepping through code, to help you add bugs debugger ; FIXME stepping through code, to help you add bugs
;;direnv ;;direnv
docker docker
@@ -93,9 +98,9 @@
(eval +overlay) ; run code, run (also, repls) (eval +overlay) ; run code, run (also, repls)
;;gist ; interacting with github gists ;;gist ; interacting with github gists
lookup ; navigate your code and its documentation lookup ; navigate your code and its documentation
lsp ; M-x vscode lsp ; M-x vscode
magit ; a git porcelain for Emacs magit ; a git porcelain for Emacs
make ; run make tasks from Emacs make ; run make tasks from Emacs
;;pass ; password manager for nerds ;;pass ; password manager for nerds
;;pdf ; pdf enhancements ;;pdf ; pdf enhancements
;;prodigy ; FIXME managing external services & code builders ;;prodigy ; FIXME managing external services & code builders
@@ -103,27 +108,28 @@
;;taskrunner ; taskrunner for all your projects ;;taskrunner ; taskrunner for all your projects
;;terraform ; infrastructure as code ;;terraform ; infrastructure as code
;;tmux ; an API for interacting with tmux ;;tmux ; an API for interacting with tmux
;;tree-sitter ; syntax and parsing, sitting in a tree...
;;upload ; map local to remote projects via ssh/ftp ;;upload ; map local to remote projects via ssh/ftp
:os :os
(:if IS-MAC macos) ; improve compatibility with macOS (:if IS-MAC macos) ; improve compatibility with macOS
tty ; improve the terminal Emacs experience (tty +osc) ; improve the terminal Emacs experience
:lang :lang
;;agda ; types of types of types of types... ;;agda ; types of types of types of types...
;;beancount ; mind the GAAP ;;beancount ; mind the GAAP
cc ; C > C++ == 1 (cc +lsp) ; C > C++ == 1
;;clojure ; java with a lisp ;;clojure ; java with a lisp
;;common-lisp ; if you've seen one lisp, you've seen them all ;;common-lisp ; if you've seen one lisp, you've seen them all
;;coq ; proofs-as-programs ;;coq ; proofs-as-programs
;;crystal ; ruby at the speed of c ;;crystal ; ruby at the speed of c
;;csharp ; unity, .NET, and mono shenanigans ;;csharp ; unity, .NET, and mono shenanigans
;;data ; config/data formats ;;data ; config/data formats
;;(dart +flutter) ; paint ui and not much else (dart +flutter) ; paint ui and not much else
;;dhall ;;dhall
;;elixir ; erlang done right ;;elixir ; erlang done right
;;elm ; care for a cup of TEA? ;;elm ; care for a cup of TEA?
emacs-lisp ; drown in parentheses emacs-lisp ; drown in parentheses
;;erlang ; an elegant language for a more civilized age ;;erlang ; an elegant language for a more civilized age
;;ess ; emacs speaks statistics ;;ess ; emacs speaks statistics
;;factor ;;factor
@@ -133,11 +139,12 @@
;;fstar ; (dependent) types and (monadic) effects and Z3 ;;fstar ; (dependent) types and (monadic) effects and Z3
;;gdscript ; the language you waited for ;;gdscript ; the language you waited for
;;(go +lsp) ; the hipster dialect ;;(go +lsp) ; the hipster dialect
;;(graphql +lsp) ; Give queries a REST
;;(haskell +lsp) ; a language that's lazier than I am ;;(haskell +lsp) ; a language that's lazier than I am
;;hy ; readability of scheme w/ speed of python ;;hy ; readability of scheme w/ speed of python
;;idris ; a language you can depend on ;;idris ; a language you can depend on
json ; At least it ain't XML json ; At least it ain't XML
(java +lsp) ; the poster child for carpal tunnel syndrome ;;(java +lsp) ; the poster child for carpal tunnel syndrome
;;javascript ; all(hope(abandon(ye(who(enter(here)))))) ;;javascript ; all(hope(abandon(ye(who(enter(here))))))
;;julia ; a better, faster MATLAB ;;julia ; a better, faster MATLAB
;;kotlin ; a better, slicker Java(Script) ;;kotlin ; a better, slicker Java(Script)
@@ -145,25 +152,25 @@
;;lean ; for folks with too much to prove ;;lean ; for folks with too much to prove
;;ledger ; be audit you can be ;;ledger ; be audit you can be
;;lua ; one-based indices? one-based indices ;;lua ; one-based indices? one-based indices
markdown ; writing docs for people to ignore markdown ; writing docs for people to ignore
;;nim ; python + lisp at the speed of c ;;nim ; python + lisp at the speed of c
;;nix ; I hereby declare "nix geht mehr!" ;;nix ; I hereby declare "nix geht mehr!"
;;ocaml ; an objective camel ;;ocaml ; an objective camel
org ; organize your plain life in plain text org ; organize your plain life in plain text
;;php ; perl's insecure younger brother ;;php ; perl's insecure younger brother
;;plantuml ; diagrams for confusing people more ;;plantuml ; diagrams for confusing people more
;;purescript ; javascript, but functional ;;purescript ; javascript, but functional
python ; beautiful is better than ugly python ; beautiful is better than ugly
;;qt ; the 'cutest' gui framework ever ;;qt ; the 'cutest' gui framework ever
;;racket ; a DSL for DSLs ;;racket ; a DSL for DSLs
;;raku ; the artist formerly known as perl6 ;;raku ; the artist formerly known as perl6
;;rest ; Emacs as a REST client ;;rest ; Emacs as a REST client
;;rst ; ReST in peace ;;rst ; ReST in peace
ruby ; 1.step {|i| p "Ruby is #{i.even? ? 'love' : 'life'}"} ;;(ruby +rails) ; 1.step {|i| p "Ruby is #{i.even? ? 'love' : 'life'}"}
;;rust ; Fe2O3.unwrap().unwrap().unwrap().unwrap() (rust +lsp) ; Fe2O3.unwrap().unwrap().unwrap().unwrap()
;;scala ; java, but good ;;scala ; java, but good
;;(scheme +guile) ; a fully conniving family of lisps ;;(scheme +guile) ; a fully conniving family of lisps
sh ; she sells {ba,z,fi}sh shells on the C xor sh ; she sells {ba,z,fi}sh shells on the C xor
;;sml ;;sml
;;solidity ; do you need a blockchain? No. ;;solidity ; do you need a blockchain? No.
;;swift ; who asked for emoji variables? ;;swift ; who asked for emoji variables?
@@ -188,3 +195,7 @@
:config :config
;;literate ;;literate
(default +bindings +smartparens)) (default +bindings +smartparens))
;; Load optional site-specific config (e.g. work profiles)
(if (file-exists-p "~/.doom-site/init.el")
(load-file "~/.doom-site/init.el"))

View File

@@ -45,12 +45,12 @@
(defun mgr-gitlab-clone (name) (defun mgr-gitlab-clone (name)
"Clone the project NAME." "Clone the project NAME."
;; TODO: Automatically set remote.pushDefault so it does not prompt
;; TODO: Clone with API token, if there is one ;; TODO: Clone with API token, if there is one
(interactive (interactive
(list (completing-read "Project: " (mgr-gitlab-list-remote-project-names)))) (list (completing-read "Project: " (mgr-gitlab-list-remote-project-names))))
(let* ((url (mgr-gitlab--get-url-by-name name)) (let* ((url (mgr-gitlab--get-url-by-name name))
(dest mgr-gitlab-project-path)) (dest mgr-gitlab-project-path))
(setf magit-clone-set-remote.pushDefault t)
(magit-clone-regular url dest nil))) (magit-clone-regular url dest nil)))
(defun mgr-gitlab-clone-all () (defun mgr-gitlab-clone-all ()
@@ -92,4 +92,8 @@ gitlab so kindly removes."
(add-to-list 'dashboard-item-generators '(mgr-gitlab-gitlab-projects . mgr-gitlab-dashboard-insert-gitlab-projects)) (add-to-list 'dashboard-item-generators '(mgr-gitlab-gitlab-projects . mgr-gitlab-dashboard-insert-gitlab-projects))
(ert-deftest mgr-gitlab-clone-test ()
"Tests that mgr-gitlab can clone a repo"
(mgr-gitlab-clone "IotButton"))
(provide 'mgr-gitlab) (provide 'mgr-gitlab)

View File

@@ -11,7 +11,7 @@
;; To install a package directly from a remote git repo, you must specify a ;; To install a package directly from a remote git repo, you must specify a
;; `:recipe'. You'll find documentation on what `:recipe' accepts here: ;; `:recipe'. You'll find documentation on what `:recipe' accepts here:
;; https://github.com/raxod502/straight.el#the-recipe-format ;; https://github.com/radian-software/straight.el#the-recipe-format
;(package! another-package ;(package! another-package
; :recipe (:host github :repo "username/repo")) ; :recipe (:host github :repo "username/repo"))
@@ -34,7 +34,7 @@
;; Specify a `:branch' to install a package from a particular branch or tag. ;; Specify a `:branch' to install a package from a particular branch or tag.
;; This is required for some packages whose default branch isn't 'master' (which ;; This is required for some packages whose default branch isn't 'master' (which
;; our package manager can't deal with; see raxod502/straight.el#279) ;; our package manager can't deal with; see radian-software/straight.el#279)
;(package! builtin-package :recipe (:branch "develop")) ;(package! builtin-package :recipe (:branch "develop"))
;; Use `:pin' to specify a particular commit to install. ;; Use `:pin' to specify a particular commit to install.
@@ -49,14 +49,14 @@
;; ...Or *all* packages (NOT RECOMMENDED; will likely break things) ;; ...Or *all* packages (NOT RECOMMENDED; will likely break things)
;(unpin! t) ;(unpin! t)
(package! org-journal)
(package! all-the-icons-ivy-rich)
(package! git-auto-commit-mode)
;; required for mgr-gitlab ;; required for mgr-gitlab
(package! gitlab) (package! gitlab)
;; Testing (package! all-the-icons-ivy-rich)
(package! dashboard) (package! paredit)
(package! denote)
;; Load optional site-specific config (e.g. work profiles)
(if (file-exists-p "~/.doom-site/init.el")
(load-file "~/.doom-site/init.el"))

View File

@@ -5,17 +5,23 @@
stages: stages:
- test - test
sast: variables:
stage: test GIT_SUBMODULE_STRATEGY: recursive
DOOMDIR: ./.doom.d
EMACSDIR: ./.emacs.d
DOOMLOCALDIR: ./.emacs.d/local
test-emacs: test-emacs:
stage: test stage: test
image: ubuntu:latest image: ubuntu:22.04
before_script: before_script:
- apt-get update - apt-get update
- apt-get install -y emacs-nox - apt-get install -y emacs-nox git
- yes | ./.emacs.d/bin/doom install || true
script: script:
- ./.mgr_config/tests/test-emacs.sh - ./.mgr_config/tests/test-emacs.sh
sast:
stage: test
include: include:
- template: Security/SAST.gitlab-ci.yml - template: Security/SAST.gitlab-ci.yml

54
.mgr_config/bin/py Normal file
View File

@@ -0,0 +1,54 @@
#!/usr/bin/env python3
import argparse
import sys
from pathlib import Path
source = " ".join(sys.argv[1:])
INPUT_SRC_NAME = "<py-input>"
global_vars = {}
local_vars = {}
py_env_conf = Path.home() / ".py-env.py"
if py_env_conf.exists():
with open(Path.home() / ".py-env.py") as f:
code = compile(f.read(), "py-env.py", "exec")
exec(code)
try:
code = compile(source, INPUT_SRC_NAME, "eval")
val = eval(code)
# If it's a string, just print it
if type(val) == str:
print(val)
exit(0)
# If it's not iterable, just print it
try:
it = iter(val)
except TypeError as e:
if val is not None:
print(val)
exit(0)
# It's iterable, print each element as a line
try:
for item in val:
print(item)
exit(0)
except Exception as e:
e.args = ("Failed to print all elements",) + e.args
raise
except (SyntaxError, NameError) as e:
pass
try:
code = compile(source, INPUT_SRC_NAME, "exec")
exec(code)
except (SyntaxError, NameError) as e:
e.args = ("Invalid Python code",) + e.args
raise e

View File

@@ -21,6 +21,7 @@ if [[ $NEEDS_GIT_DIR != 0 ]]; then
git-home remote add origin https://gitlab.maxregan.me/max/configs.git git-home remote add origin https://gitlab.maxregan.me/max/configs.git
git-home branch master --set-upstream-to origin/master git-home branch master --set-upstream-to origin/master
git-home config status.showUntrackedFiles no git-home config status.showUntrackedFiles no
git-home submodule update --init --recursive
fi fi
echo "Checking out configs." echo "Checking out configs."

View File

@@ -0,0 +1,10 @@
gitlab_start_log_section() {
NAME="$1"
HEADER="$2"
echo -e "\e[0Ksection_start:`date +%s`:${NAME}\r\e[0K${HEADER}"
}
gitlab_end_log_section() {
NAME="$1"
echo -e "\e[0Ksection_end:`date +%s`:${NAME}\r\e0K"
}

View File

@@ -1,3 +1,17 @@
#!/bin/bash #!/bin/bash
emacs --batch -u "$(whoami)" --debug-init set -e -o pipefail
SRC_ROOT="$(dirname "${BASH_SOURCE}")"
source "$SRC_ROOT/gitlab-utils.sh"
# Load emacs
gitlab_start_log_section "test_init" "Running Emacs"
emacs --batch --debug-init -l ./.emacs.d/init.el
gitlab_end_log_section "test_init"
# Run tests
gitlab_start_log_section "run_unit_tests" "Running Unit Tests"
emacs --batch --debug-init -l ert -l ./.emacs.d/init.el -f ert-run-tests-batch-and-exit
gitlab_end_log_section "run_unit_tests"

76
.py-env.py Normal file
View File

@@ -0,0 +1,76 @@
import itertools
import json
import operator
import os
import sys
import yaml
from functools import partial, reduce
from math import *
from pathlib import Path
from itertools import chain
try:
from tabulate import tabulate
except ImportError:
pass
try:
import rich
from rich import inspect, print as pp
except ImportError:
pass
# Always write heavyweight/blocking code in this file lazily to keep startup
# time short. In the same vein, be careful not to consume stdin unless an object
# in this file is called or iterated upon, e.g. stdin_str()
# Returns a lazily-evaluable map which executes multiple map functions
def maps(items, *map_funs):
it = items
for func in map_funs:
it = map(func, it)
return it
# Returns a lazily-evaluable filter which executes multiple predicate functions
def filters(items, *pred_funs):
it = items
for pred in pred_funs:
it = filter(pred, it)
return it
# Concatenate two items, there's likely a safer way to do this to avoid summing ints
concat = lambda a, b: "".join([a, b])
# Joins an interable of strings
join = "".join
# Return an iterable for file. This doesn't close the handle, but for this
# little scripting interface this is fine.
def read(filename):
return open(filename, "r")
def read_str(filename):
return concats(read(filename))
stdin_str = sys.stdin.read
# An iterable which yields the characters of stdin
stdin = (c for l in sys.stdin for c in l)
# An iterable which yields the lines of stdin
lines = map(str.strip, sys.stdin)
# An iterable which yields integers supplied via stdin lines
ints = map(int, lines)
# An iterable which yields the bytes of stdin
byts = map(lambda x: bytes(x, "utf-8"), stdin) # better name? 'bytes' is taken
jr = json.loads
jw = json.dumps
yr = lambda x: yaml.load(x, Loader=yaml.SafeLoader)
yw = yaml.dump
pwd = Path.cwd()