This file contains hidden or 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
# There are many patterns in python where a decorator is used to add a function to a registry, | |
# without altering it at all. Often, the function doesn't need to exist outside of the registry, | |
# and a minimal def is supplied- just enough to be decorated. The functools.singledispatch | |
# decorator is an example of this: | |
@singledispatch | |
def func(arg): | |
print(arg) | |
This file contains hidden or 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
#!/bin/sh | |
# Copy some stuff to the term clipboard | |
stuff="$(base64 -w0)" | |
exec echo -en "\x1b]52;c;${stuff}\x07" |
This file contains hidden or 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 python | |
from __future__ import print_function, unicode_literals | |
import argparse | |
import re | |
from sys import stdin | |
parser = argparse.ArgumentParser() |
This file contains hidden or 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 | |
# Copyright 2015 Nathan West | |
# | |
# This program is free software: you can redistribute it and/or modify | |
# it under the terms of the GNU General Public License as published by | |
# the Free Software Foundation, either version 3 of the License, or | |
# (at your option) any later version. | |
# | |
# This program is distributed in the hope that it will be useful, |
This file contains hidden or 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
class FunctionNotFoundError(KeyError): | |
pass | |
class Registry: | |
def __init__(self): | |
self.registry = {} | |
def register(self, key): | |
def decorator(func): | |
self.registry[key] = func |
This file contains hidden or 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 tkinter import * | |
import asyncio | |
from functools import wraps | |
import websockets | |
def runloop(func): | |
''' | |
This decorator converts a coroutine into a function which, when called, | |
runs the underlying coroutine to completion in the asyncio event loop. | |
''' |
This file contains hidden or 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 exporter(all): | |
def export(thing): | |
all.append(thing.__name__) | |
return thing | |
return export | |
################################### | |
__all__ = [] |
This file contains hidden or 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 python | |
from __future__ import print_function, unicode_literals | |
from tempfile import SpooledTemporaryFile as TempFile | |
from shutil import copyfileobj | |
from argparse import ArgumentParser | |
from io import open | |
def trim_white(istr): |
This file contains hidden or 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 | |
@asyncio.coroutine | |
def scan_remote(host, port, timeout=1): | |
try: | |
connection = asyncio.open_connection(host, port) | |
yield from asyncio.wait_for(connection, timeout) | |
except (OSError, asyncio.TimeoutError): | |
pass | |
else: |