Skip to content

Instantly share code, notes, and snippets.

@ievans3024
ievans3024 / reddit-gag.css
Created July 25, 2017 22:04
Reddit Gag Userstyle
/**
* Reddit Gag Userstyle
*
* by ievans3024
*
* For when you just need to prevent yourself from getting into arguments with idiots.
* This style hides all reply/submit/comment forms and links, except in existing private messages.
*/
@namespace url(http://www.w3.org/1999/xhtml);
@ievans3024
ievans3024 / reddit-comment-hider.css
Last active November 4, 2019 18:46
For when you just need to prevent yourself from getting into arguments with idiots. This style hides all comment sections in all posts.
/**
* Reddit Comment Hider Userstyle
*
* by ievans3024
*
* For when you just need to prevent yourself from getting into arguments with idiots.
* This style hides all comment sections in all posts.
*/
@namespace url(http://www.w3.org/1999/xhtml);
@ievans3024
ievans3024 / elapsed.py
Last active March 6, 2018 18:13
A module extending the builtin timedelta class to approximate a string representation of the time difference
import datetime
"""
A small module extending timedelta.
Provides a method to print a formatted
string detailing elapsed time in the given delta
"""
@ievans3024
ievans3024 / custom_log_levels.py
Last active March 22, 2018 18:32
python custom logging levels example
import logging
# keep in mind that the lower the number, the more verbose the log output
# everything greater than that number will also print
logging.DEBUG_PLUS = 5 # more verbose debug
logging.INFO_PLUS = 15 # more verbose info
logging.WARNING_PLUS = 25 # more verbose warning
logging.ERROR_PLUS = 35 # more verbose error
logging.CRITICAL_PLUS = 45 # more verbose critical
@ievans3024
ievans3024 / verbosity.py
Created May 8, 2018 13:29
Logging verbosity control with a single argument
"""
A demonstration of how to control stdout verbosity with argparse and logging.
Examples of running this file and its expected output:
$ python verbosity.py
CRITICAL :: A critical message.
$ python verbosity.py -v
CRITICAL :: A critical message.
@ievans3024
ievans3024 / indentation.py
Created July 21, 2018 15:44
Proving Jeremy wrong, indentation experimentation
"""Proving Jeremy wrong, indentation experimentation"""
def four():
# indented with 4 spaces
return 4
def three():
# indented with 3 spaces
return 3
@ievans3024
ievans3024 / alpha_getter.py
Created August 1, 2018 13:53
An overengineered way to get what 1-based index a letter is in the roman alphabet
import struct
"""
An overengineered way to get what 1-based index a letter is in the roman alphabet
"""
class AlphaBytes:
UPPERCASE = set([struct.pack('>b', i) for i in range(65, 91)])
LOWERCASE = set([struct.pack('>b', i) for i in range(97, 123)])
@ievans3024
ievans3024 / logging_verbosity
Created August 8, 2018 03:59
A function inspired by my verbosity.py gist for auto-configuring verbosity given an int and a logger.
import logging
LOG_LEVELS = [
logging.CRITICAL,
logging.ERROR,
logging.WARNING,
logging.INFO,
logging.DEBUG
]
@ievans3024
ievans3024 / binary_clock.py
Last active October 29, 2019 13:45
A simple command-line binary clock
import curses
from argparse import ArgumentParser
from datetime import datetime
from time import sleep
ON = '\N{BLACK CIRCLE}'
OFF = '\N{WHITE CIRCLE}'
@ievans3024
ievans3024 / configparser_extended.py
Last active September 12, 2023 19:34
Extension of the configparser library for some much needed but ignored features
from configparser import *
# copypasta from configparser source
# see https://github.com/python/cpython/blob/3.8/Lib/configparser.py#L357
_UNSET = object()
class ConfigParser(ConfigParser):
def __init__(self, *args, sectionless=False, strip_quotes=False, **kwargs):
self.__sectionless = sectionless