Skip to content

Instantly share code, notes, and snippets.

# From https://apihandyman.io/api-toolbox-jq-and-openapi-part-1-using-jq-to-extract-data-from-openapi-files/#list-operations
# 1 - Selects paths objects
#--------------------------
# returns [{key: path, value: path value}]
.paths # Selects the paths property content
| to_entries # Transforms
# { "/resources": { "get": {operation data}}}
# to
# [ { "key": "/resources",
# "value": { "get": {operation data}} ]

Create a new project

poetry new <project-name>

Initialise an existing project

poetry init 

Add a new lib (prod & dev)

from typing import cast
import libcst as cst
import libcst.matchers as m
from libcst.codemod import VisitorBasedCodemodCommand
from libcst.codemod.visitors import AddImportsVisitor, RemoveImportsVisitor
class DatetimeUtcnow(VisitorBasedCodemodCommand):
@expobrain
expobrain / dict2.py
Created July 16, 2019 15:01
Dict type which behaves like the Optional Chaining operator https://github.com/tc39/proposal-optional-chaining
class NoneDict:
def __truedive__(self, key):
return self
def __or__(self, key):
return self
def __repr__(self):
return "NoneDict"
@expobrain
expobrain / bash-path-vars
Created March 11, 2019 12:52 — forked from caruccio/bash-path-vars
Path manipulation with bash vars
$ FILE=/some/path/to/file.txt
###################################
### Remove matching suffix pattern
###################################
$ echo ${FILE%.*} # remove ext
/some/path/to/file
$ FILE=/some/path/to/file.txt.jpg.gpg # note various file exts
@expobrain
expobrain / commit.py
Created January 9, 2019 18:25 — forked from danielmt/commit.py
pygit 2 snippets - most examples assume using a bare repository.
import pygit2
# open existing repository
repo = pygit2.Repository(pygit2.discover_repository('test_repos'))
# check if repos is newly created
if repo.head_is_unborn:
tb = repo.TreeBuilder()
parent = []
else: