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 sys import stdin | |
data = stdin.read() | |
print(next(port | |
for port in range(491, 600) | |
if str(port) not in data)) |
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
''' | |
Say you have a logger that adds empty lines between each logged | |
event, and each event is one more more lines. You want to iterate | |
over each logged event. | |
''' | |
def sectionalize(lines): | |
''' | |
Divide lines into sections, separated by empty lines. Technically | |
you could come up with a regex and do re.split, but that's doesn't |
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 bs4 import BeautifulSoup | |
from requests import get as http_get | |
from datetime import datetime | |
from time import sleep, perf_counter as now | |
import argparse | |
def get_properties(url): | |
''' | |
returns the number of backers, and total amount backed |
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
# 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 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 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 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 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 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): |
OlderNewer