Skip to content

Instantly share code, notes, and snippets.

View QuiteClose's full-sized avatar

QuiteClose QuiteClose

View GitHub Profile
@QuiteClose
QuiteClose / schema.py
Last active June 18, 2024 00:06
Generate a schema from a YAML file (or from stdin.)
#!/usr/bin/env python3
'''
schema.py - Generate a schema from a YAML file (or from stdin.)
Required:
pip install PyYAML
Usage:
python3 schema.py < PATH
python3 schema.py PATH [PATH ...]
@QuiteClose
QuiteClose / day_02_task_1.py
Created December 2, 2023 22:22
Advent Of Code 2023
'''
Advent of Code 2023, Day Two, Task 1
See: https://adventofcode.com/2023/day/2
Run: python task.py < input.txt
'''
from collections import namedtuple
import sys
@QuiteClose
QuiteClose / repl.py
Created October 7, 2016 22:47
repl.py
'''
Basic REPL using coroutines. Change the operator or initial state to
modify behaviour. Currently input is just accumulated and the whole
is printed out each time.
Tested on Python 3.4 and higher. Not expected to work with Python 2.
Of course, this entire thing could just be replaced with something
much less interesting:
@QuiteClose
QuiteClose / show-all-256-colors.py
Created June 20, 2016 12:12 — forked from mgedmin/show-all-256-colors.py
Script to show all 256 colors supported by xterms
#!/usr/bin/python
"""Print a swatch using all 256 colors of 256-color-capable terminals."""
__author__ = "Marius Gedminas <[email protected]>"
__url__ = "https://gist.github.com/mgedmin/2762225"
__version__ = '2.0'
def hrun(start, width, padding=0):
@QuiteClose
QuiteClose / clear-stdin.py
Last active March 10, 2021 20:11
Checking whether a read will block and then learning stdin
'''
Basic functions for clearing stdin by checking whether a
read will block.
'''
import select
import sys
def has_unread_input(stream=sys.stdin, timeout=0):
'''
@QuiteClose
QuiteClose / sitemap.py
Last active September 23, 2015 22:08
A simple web crawler.
###############################################################################
# $Author: [email protected]
# $Expects: Python version 3.4.3
###############################################################################
"""Crawls a given URL and presents a simple sitemap based upon which
webpages are found. Each page is given as an individual WebResource
with a URL, a title and a list of links within the page.
From the command line:
@QuiteClose
QuiteClose / Progress.py
Last active February 21, 2022 01:24
A console progress bar in Python
################################################################################
# Example usage:
# $ python
# >>> import Progress
# >>> total = 100
# >>> message = 'Doing this task '
# >>> with Progress.Bar(total, message) as bar:
# ... for n in range(total):
# ... time.sleep(0.1)
# ... bar.update()
@QuiteClose
QuiteClose / HTTPResource.py
Created April 15, 2015 20:13
Using Python's socket module to send HTTP requests and receive the response.
#!/bin/env python
# expects python3
################################################################################
import argparse
import socket
import sys
################################################################################