Skip to content

Instantly share code, notes, and snippets.

@mumuxme
mumuxme / pandoc.css
Last active May 13, 2022 01:49 — forked from killercup/pandoc.css
Add this to your Pandoc HTML documents using `-H pandoc.css` to make them look more awesome. (Tested with Markdown and LaTeX.)
<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%;
@mumuxme
mumuxme / itertools.py
Last active December 8, 2017 10:21
Python itertools
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)
@mumuxme
mumuxme / a.py
Last active August 9, 2017 07:00
Remove text between brackets
# 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
@mumuxme
mumuxme / run_bash.py
Last active February 15, 2018 08:58
running bash commands in python (python3.5)
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")
@mumuxme
mumuxme / a.hs
Last active January 7, 2017 05:43
Parsing in Haskell (ghc 8.0)
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