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",
]
"""
@costastf
costastf / samsung_remote.py
Last active September 9, 2021 11:19 — forked from danielfaust/samsung_remote.py
Code used to create a class for a samsung remote
import time
import socket
import base64
src = '192.168.1.2' # ip of remote
mac = '00-AB-11-11-11-11' # mac of remote
remote = 'python remote' # remote name
dst = '192.168.1.3' # ip of tv
app = 'python' # iphone..iapp.samsung
tv = 'LE32C650' # iphone.LE32C650.iapp.samsung
#!/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'],
@costastf
costastf / gist:c5fc1dd0f73e566d312e7d6c5484b140
Created September 21, 2017 08:44
Legacy code to translate a thunderbird msgFilterRules.dat to gmail.xml format
#!/usr/bin/env python2.7
# -*- coding: UTF-8 -*-
# File: moz_filter_to_gmail
#
__author__ = 'Costas Tyfoxylos <costas.tyf@gmail.com>'
__docformat__ = 'plaintext'
__date__ = '2015-04-14'
import sys
import logging
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