Skip to content

Instantly share code, notes, and snippets.

View Tuhin-thinks's full-sized avatar
🏅
Learning

Tuhin Mitra Tuhin-thinks

🏅
Learning
View GitHub Profile
@badocelot
badocelot / damlevdist.py
Last active September 8, 2023 00:13
Damerau-Levenshtein edit distance calculator in Python. Based on pseudocode from Wikipedia: <https://en.wikipedia.org/wiki/Damerau-Levenshtein_distance>
# Damerau-Levenshtein edit distance implementation
# Based on pseudocode from Wikipedia: https://en.wikipedia.org/wiki/Damerau-Levenshtein_distance
def damerau_levenshtein_distance(a, b):
# "Infinity" -- greater than maximum possible edit distance
# Used to prevent transpositions for first characters
INF = len(a) + len(b)
# Matrix: (M + 2) x (N + 2)
matrix = [[INF for n in xrange(len(b) + 2)]]
@BlueNexus
BlueNexus / python2pseudo.py
Last active November 11, 2024 05:32
Python to Pseudocode converter
import os.path
import re
'''
INSTRUCTIONS
1. Create a file with the following code
2. Put the file you want to convert into the same folder as it, and rename it to "py_file.py"
3. Add a "#F" comment to any lines in the code which have a function call that doesn't assign anything (so no =),
as the program cannot handle these convincingly
4. Run the converter file
import sys
import time
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5 import QtCore
from PyQt5.QtCore import Qt
var = 0
f = ""
choiceStr = ""
@JavaScriptDude
JavaScriptDude / SingleInstanceChecker.py
Last active July 27, 2024 11:18
Cross Platform Example of Single Instance Checking in Python
import time, sys, os
class SingleInstanceChecker:
def __init__(self, id):
if isWin():
ensure_win32api()
self.mutexname = id
self.lock = win32event.CreateMutex(None, False, self.mutexname)
self.running = (win32api.GetLastError() == winerror.ERROR_ALREADY_EXISTS)
@Tuhin-thinks
Tuhin-thinks / print_format_list.py
Last active March 9, 2024 17:53
Function to print header along with list of list in tabular format.
import re
def print_formatted(_header, _items, padding=10, alignment="^"):
"""
Function to print header along with list of list in tabular format.
:param alignment: ^ -center alignment; < -left alignment; > -right alignment
:param _header: header strings for the table
:param _items: list of list, representing collection of rows
:param padding: padding count