Skip to content

Instantly share code, notes, and snippets.

dgjustice /
Created May 5, 2022
`returns` weird `lash`
from returns import context, result, curry, pipeline, pointfree
def some(s):
def factory(deps):
print('in factory', deps)
return result.Success(42)
return context.RequiresContextResult(factory)
def plusone(arg):
dgjustice /
Created May 4, 2022
Compose `async` with `returns`
async def run_process(proc: asyncio.subprocess.Process) -> typing.Tuple[bytes, bytes]:
"""Run the async process and check the return code."""
stdout, stderr = await proc.communicate()
if proc.returncode:
logger.error('process exited with returncode {0}'.format(proc.returncode))
raise ValueError('process returned non-zero code')
return stdout, stderr
dgjustice / prime.awk
Created Mar 25, 2022
Prime number fud
View prime.awk
for ( i = 1; i < 100; i++) {
arr[i] = i
for (p = 2;p < 49; p++) {
for (i = p*2; i < 100; i += p) {
delete arr[i]
for ( i = 1; i < 100; i++) {
dgjustice /
Last active Mar 11, 2022
Check if configured password on Cisco device is what you expect it to be.
import crypt
from hmac import compare_digest
cisco = "username REDACTED password 5 $5$SALT$SOME-HASH role network-admin"
def check_pw_hashes_are_eq(username_cmd: str, cleartext: str) -> bool:
parts = username_cmd.split(' ')
pw_hash = parts[4]
pw_parts = pw_hash.split('$')
meth, salt, pw = pw_parts[1:]
dgjustice /
Created Jul 16, 2021
Cannonical interface sorting
from itertools import groupby
import re
import typing as t
WEIGHTS: t.Dict[str, int] = {".": 10, "/": 20}
def split_interface_tuple(interface: str) -> t.Tuple[str, ...]:
"""Crappy parser-combinator hacky-hack"""
head = interface.rstrip(r"/\0123456789. ")
open Angstrom
let vlan_raw =
"VLAN Name Status Ports
---- -------------------------------- --------- -------------------------------
1 default active Gi0/1
10 Management active
50 VLan50 active Fa0/1, Fa0/2, Fa0/3, Fa0/4, Fa0/5, Fa0/6, Fa0/7, Fa0/8, Fa0/9
Fa0/10, Fa0/11, Fa0/12
60 VLan60 active Fa0/13, Fa0/14, Fa0/15, Fa0/16, Fa0/17, Fa0/18, Fa0/19, Fa0/20
dgjustice /
Created Dec 15, 2020 — forked from m-radzikowski/
Minimal safe Bash script template - see the article with full description:
#!/usr/bin/env bash
set -Eeuo pipefail
cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1
usage() {
cat <<EOF
from pydantic import BaseModel
import requests
from returns.context import RequiresContext
from returns.functions import tap
from import IOResultE, impure_safe
class OVHIpAddr(BaseModel):
dgjustice /
Last active May 21, 2020 — forked from jobec/
Junos config parsing with pyparsing
import textwrap
from collections import OrderedDict
import pyparsing as pp
class Statement(str):
def __str__(self):
return super().__str__() + ";"

Keybase proof

I hereby claim:

  • I am dgjustice on github.
  • I am crzdriver ( on keybase.
  • I have a public key ASAaAtTllHQ0txMG6MsvSXUr4vTfm5dpcWgheNcmYQ-xTQo

To claim this, I am signing this object: