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
| <style type="text/css"> | |
| /** | |
| * $ pandoc README.md -H pandoc.css -o README.html --toc | |
| */ | |
| html { | |
| font-size: 100%; | |
| overflow-y: scroll; | |
| -webkit-text-size-adjust: 100%; |
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
| from itertools import zip_longest | |
| def splitby(xs, f): | |
| """Split a list by a function. | |
| >>> splitby([{'a': 1}, {'b': 2}, {'a': 3}], lambda x: x.get('a')) | |
| [[{'a': 1}, {'b': 2}], [{'a': 3}]] | |
| >>> splitby([1, 0, 0, 1, 0], lambda x: x == 1) |
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
| # from https://stackoverflow.com/questions/14596884/remove-text-between-and-in-python | |
| def remove_text_inside_brackets(text, brackets="()[]"): | |
| count = [0] * (len(brackets) // 2) # count open/close brackets | |
| saved_chars = [] | |
| for character in text: | |
| for i, b in enumerate(brackets): | |
| if character == b: # found bracket | |
| kind, is_close = divmod(i, 2) | |
| count[kind] += (-1)**is_close # `+1`: open, `-1`: close |
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 subprocess | |
| def run_sh(sh, stderr=subprocess.STDOUT, stdout=None): | |
| assert isinstance(sh, str) | |
| args = ["bash", "-c", sh] | |
| subprocess.run(args, stderr=stderr, stdout=stdout, check=True) | |
| run_sh("echo hello > hello.txt") | |
| run_sh("ls -l") |
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 Data.Char | |
| import Data.List | |
| type Parser s a = s -> Maybe (a, s) | |
| string :: String -> Parser String String | |
| string pat input = | |
| case stripPrefix pat input of | |
| Nothing -> Nothing |