This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
# CC0, originally written by t184256. | |
# This is an example Python program for Linux that remaps a keyboard. | |
# The events (key presses releases and repeats), are captured with evdev, | |
# and then injected back with uinput. | |
# This approach should work in X, Wayland, anywhere! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class KMP: | |
def partial(self, pattern): | |
""" Calculate partial match table: String -> [Int]""" | |
ret = [0] | |
for i in range(1, len(pattern)): | |
j = ret[i - 1] | |
while j > 0 and pattern[j] != pattern[i]: | |
j = ret[j - 1] | |
ret.append(j + 1 if pattern[j] == pattern[i] else j) |