This file contains 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 asyncio | |
async def task(seconds: int=5): | |
"""Sleep for some time.""" | |
await asyncio.sleep(seconds) | |
return f"slept {seconds} seconds!" | |
async def multi_task(sleeps_to_sleep: list[int]): | |
"""Start coroutines from a list of inputs.""" | |
all_the_tasks = [task(sleep_time) for sleep_time in sleeps_to_sleep] |
This file contains 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 extras.validators import CustomValidator | |
from virtualization.models import VirtualMachine | |
class UniqueVirtualMachineNamesCasefold(CustomValidator): | |
"""Enforce case-insensitive unique VM names. | |
Your configuration.py file would contain something like this: | |
CUSTOM_VALIDATORS = { |
This file contains 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 extras.validators import CustomValidator | |
from circuits.models import Circuit | |
class SiteStatusCircuitValidator(CustomValidator): | |
""" | |
Prevent sites from being retired if they have circuits that aren't in deprovisioning or decommissioned status. | |
""" | |
def validate(self, site): | |
circuit_count = Circuit.objects.filter(terminations__site=site).exclude( |
This file contains 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 asyncio | |
def do_work_sync(seconds): | |
"""Wait 'seconds' using sync code""" | |
return asyncio.run(do_work_async(seconds, "sync")) | |
def organize_work_sync(work_inputs): | |
"""Execute multiple calls of the sync function""" |
This file contains 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
""" | |
Uses the `words_alpha.txt` file from | |
https://github.com/dwyl/english-words/ | |
""" | |
import random | |
from collections import Counter | |
from typing import Iterable, Tuple | |
def has_no_repeat_letters(word: str) -> bool: |
This file contains 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 pyshark | |
from collections import defaultdict | |
FIELDS = ( | |
"srcaddr", | |
"dstaddr", | |
"octets", | |
) | |
This file contains 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
#!/usr/bin/env python3 | |
''' | |
Use processes and Netmiko to connect to each of the devices. Execute | |
'show version' on each device. Use concurrent futures built-in queue | |
to pass the output back to the parent process. Record the amount of | |
time required to do this. | |
''' | |
import concurrent.futures as cf | |
from datetime import datetime |
This file contains 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 python:3.6 | |
# Annoying sources for net-snmp, which is a dependency for easysnmp | |
RUN export DEBIAN_FRONTEND=noninteractive && \ | |
export DEBIAN_RELEASE=$(awk -F'[" ]' '/VERSION=/{print $3}' /etc/os-release | tr -cd '[[:alnum:]]._-' ) && \ | |
echo "remove main from /etc/apt/sources.list" && \ | |
sed -i '/main/d' /etc/apt/sources.list && \ | |
echo "remove contrib from /etc/apt/sources.list" && \ | |
sed -i '/contrib/d' /etc/apt/sources.list && \ | |
echo "remove non-free from /etc/apt/sources.list" && \ | |
sed -i '/non-free/d' /etc/apt/sources.list && \ |
This file contains 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
def parsePortList(portlist): | |
""" | |
Returns indexes of ports where | |
VLAN is present. | |
""" | |
port_status = [] | |
present_ports = [] | |
for values in portlist: | |
for i, bit in enumerate('{:08b}'.format(values)): | |
bit = int(bit) |
This file contains 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
Traceback (most recent call last): | |
File "/venv/3.6.4/envs/fmt/lib/python3.6/site-packages/flask/app.py", line 1997, in __call__ | |
return self.wsgi_app(environ, start_response) | |
File "/venv/3.6.4/envs/fmt/lib/python3.6/site-packages/flask/app.py", line 1985, in wsgi_app | |
response = self.handle_exception(e) | |
File "/venv/3.6.4/envs/fmt/lib/python3.6/site-packages/flask/app.py", line 1540, in handle_exception | |
reraise(exc_type, exc_value, tb) | |
File "/venv/3.6.4/envs/fmt/lib/python3.6/site-packages/flask/_compat.py", line 33, in reraise | |
raise value | |
File "/venv/3.6.4/envs/fmt/lib/python3.6/site-packages/flask/app.py", line 1982, in wsgi_app |
NewerOlder