Skip to content

Instantly share code, notes, and snippets.

View dmfigol's full-sized avatar

Dmitry Figol dmfigol

View GitHub Profile
@dmfigol
dmfigol / scrapli_xr_console_on_open.py
Created June 25, 2021 15:48
scrapli IOS-XR handling of standby RSP console
import asyncio
import re
from typing import TYPE_CHECKING, cast
if TYPE_CHECKING:
from scrapli.driver import AsyncNetworkDriver
class RPNotActiveError(Exception):
pass
@dmfigol
dmfigol / bootstrap-mac
Last active March 22, 2021 15:43 — forked from natelandau/bootstrapNewMac
A bootstrap script to install my dotfiles and configure a new computer
#!/usr/bin/env bash
BOOTSTRAP_SCRIPT_PATH="${HOME}/bootstrap.sh"
# set colors
if tput setaf 1 &> /dev/null; then
tput sgr0
if [[ $(tput colors) -ge 256 ]] 2>/dev/null; then
ORANGE="$(tput setaf 172)"
else
ORANGE="$(tput setaf 4)"
@dmfigol
dmfigol / retry.py
Last active April 10, 2021 09:01
retry function/decorator
import logging
import time
import traceback
from functools import wraps
from typing import Union, Type, Tuple, Optional, Callable, TypeVar
T = TypeVar("T")
logger = logging.getLogger(__name__)
@dmfigol
dmfigol / dict_to_xml.py
Last active February 4, 2023 21:48
Convert Python dictionary to NETCONF XML payload
from typing import Any, Union, Optional
from lxml import etree
__license__ = "MIT"
# Feel free to re-use the code snippet for any projects without attribution
def dict_to_xml(
data: Any, root: Union[None, str, etree._Element] = None, attr_marker: str = "_"
) -> etree.Element:
"""Converts Python dictionary with YANG data to lxml etree.Element object.
@dmfigol
dmfigol / convert_logs_to_fw_rules.py
Last active December 4, 2018 18:00
Convert logs to firewall rules
"""Script which converts Splunk logs to different firewall objects and
prints them on the console
Copyright (c) 2018 Cisco and/or its affiliates.
This software is licensed to you under the terms of the Cisco Sample
Code License, Version 1.0 (the "License"). You may obtain a copy of the
License at
https://developer.cisco.com/docs/licenses
All use of the material herein must be in accordance with the terms of
the License. All rights not expressly granted by the License are
@dmfigol
dmfigol / asyncio_loop_in_thread.py
Last active November 14, 2024 08:52
Python asyncio event loop in a separate thread
"""
This gist shows how to run asyncio loop in a separate thread.
It could be useful if you want to mix sync and async code together.
Python 3.7+
"""
import asyncio
from datetime import datetime
from threading import Thread
from typing import Tuple, List, Iterable