Skip to content

Instantly share code, notes, and snippets.

@costastf
costastf / naming_decorator.py
Created February 7, 2024 13:11
Naming decorator
from functools import wraps
class InvalidCase(Exception):
"""The case chose is not valid."""
VALID_CASES = ['title', 'lower', 'upper']
def apply_convention(function_argument=None, *, case='title', separator='-'):
if case not in VALID_CASES:
raise InvalidCase(f'Case {case} is not valid, please choose one of {VALID_CASES}.')
@costastf
costastf / pdf_redact.py
Created August 10, 2023 12:45
Redact text from pdf
#!/usr/bin/env python
__pyproject__ = """
[project]
requires-python = ">=3.9"
dependencies = [
"coloredlogs>=15.0.1,<16.0",
"pypdf>=3.15.0,<4.0",
]
"""
#!/usr/bin/env python2.7
# -*- coding: UTF-8 -*-
# File: ExpiringDictionary.py
"""
Main module file
Put your classes here
"""
import collections
@costastf
costastf / multitap.py
Last active April 16, 2021 09:37
Multi tap encoding and decoding
from copy import deepcopy
class InvalidMultiTap(Exception):
"""Input is invalid"""
class MultiTap:
mapping = {1: ['1'],
2: ['a', 'b', 'c', '2', 'A', 'B', 'C'],
3: ['d', 'e', 'f', '3', 'D', 'E', 'F'],
def split_element(input, index, splitting_character=' '):
# we don't accept to split on more than one character and check for length of list
if any([index > len(input), len(splitting_character) > 1]):
return input
# if splitting character is no character we default to a space
items = input[index].split(splitting_character or ' ')
# if we actually have items are remove the inital from the list and insert our elements
if len(items) > 1:
input.pop(index)
for count_, item in enumerate(items):

Keybase proof

I hereby claim:

  • I am costastf on github.
  • I am costastf (https://keybase.io/costastf) on keybase.
  • I have a public key ASBGktaXcSw_jZvNjwOy5BJ5veUtQ1HO-e8wHcqj3W3QCAo

To claim this, I am signing this object:

#!/usr/bin/env python2.7
# -*- coding: UTF-8 -*-
# File: daemonlib.py
"""An example of a Linux daemon written in Python.
Based on http://www.jejik.com/articles/2007/02/a_simple_unix_linux_daemon_in_python/
The changes are:
1 - Uses file open context managers instead of calls to file().
2 - Forces stdin to /dev/null. stdout and stderr go to log files.
#!/usr/bin/env python2.7
# -*- coding: UTF-8 -*-
# File: urlutils.py
#
__author__ = 'Costas Tyfoxylos <costas.tyf@gmail.com>'
__docformat__ = 'plaintext'
__date__ = '2015-01-18'
import logging
#!/usr/bin/env python2.7
# -*- coding: UTF-8 -*-
# File: ScpWrapper
#
__author__ = 'Costas Tyfoxylos <costas.tyf@gmail.com>'
__docformat__ = 'plaintext'
__date__ = '2015-03-17'
import os
import sys
#!/usr/bin/env python
#-*- coding: UTF-8 -*-
# File: getdriveinfo.py
# Copyright (c) 2011 by None
#
# GNU General Public Licence (GPL)
#
# 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 2 of the License, or (at your option) any later