Skip to content

Instantly share code, notes, and snippets.

@scresante
Created January 15, 2022 03:30
Show Gist options
  • Save scresante/658d31acf3d9938df9c7bd34a70156b5 to your computer and use it in GitHub Desktop.
Save scresante/658d31acf3d9938df9c7bd34a70156b5 to your computer and use it in GitHub Desktop.
THIs wIlL MaKe YOuR TeXt fUNKy
#!/usr/bin/python
import random
import subprocess
from itertools import zip_longest
import unicodedata
def make_fullwidth_char(ch):
name = unicodedata.name(ch)
if name[:9] == "FULLWIDTH":
return ch
try:
fullch = unicodedata.lookup("FULLWIDTH " + name)
except KeyError:
return ch
return fullch
def oof(s):
s0 = [_.upper() for _ in q[0::2]]
s1 = [_.lower() for _ in q[1::2]]
return "".join(i for j in zip_longest(s0,s1, fillvalue='') for i in j)
def getclip():
return subprocess.run(['xsel','-b'], stdout=subprocess.PIPE, encoding='UTF-8').stdout
def random_shuffle(string, percent=0.1, meth='case'):
string = list(string)
le = len(string)
num_to_shuf = le*percent
idx_to_shuf = [random.randint(0,le-1) for _ in range(int(num_to_shuf))]
for i in idx_to_shuf:
if meth == 'case':
string[i] = string[i].upper()
elif meth == 'width':
string[i] = make_fullwidth_char(string[i])
return ''.join(string)
def setclip(s):
echo_process = subprocess.Popen(['echo', q], stdout=subprocess.PIPE)
copy_process = subprocess.Popen(['xsel','-ib'], stdin=echo_process.stdout, stdout=subprocess.PIPE)
echo_process.stdout.close()
if __name__ == "__main__":
q = getclip()
q = oof(q)
q = random_shuffle(q, 0.24, meth='case')
q = random_shuffle(q, 0.11, meth='width')
setclip(q)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment