Skip to content

Instantly share code, notes, and snippets.

@amake
Last active August 9, 2017 04:25
Show Gist options
  • Select an option

  • Save amake/289e047c9cc397a665da33c05feb50a3 to your computer and use it in GitHub Desktop.

Select an option

Save amake/289e047c9cc397a665da33c05feb50a3 to your computer and use it in GitHub Desktop.
macOS Services
# -*- coding: utf-8 -*-
import re
from sys import stdin, stdout
wspace = re.compile(r'^(\s*)(.*?)(\s*)$')
pchars = (u'ACDEFGJLMNPRTUVWY'
u'abcdefghijklmnpqrstuvwy'
u",.?!'()[]{}‿∴¯_ツ")
fchars = (u'∀ↃᗡƎℲ⅁ᒋ⅂WᴎԀᴚ⊥∩ᴧM⅄'
u'ɐqɔpǝɟƃɥıɾʞlɯudbɹsʇnʌʍʎ'
u"'˙¿¡,)(][}{⁀∵_¯ᯄ")
special = [(u'B', u'𐐒'),
(u'K', u'𝈲'),
(u'Q', u'Ό')]
flipper = dict(zip(pchars, fchars) + special)
def flip(s):
ws_l, text, ws_r = wspace.findall(s)[0]
ttext = [flipper.get(x, x) for x in text]
return ws_l + ''.join(reversed(ttext)) + ws_r
for line in stdin:
flipped = flip(line.decode('utf-8'))
stdout.write(flipped.encode('utf-8'))
# Install qrencode from MacPorts
qrencode -o - "$*" | open -f -a Preview
# Inspired by http://www.leancrew.com/all-this/2013/09/some-simple-services/
from sys import stdin, stdout
for line in stdin:
struck = u'\u0336'.join(line.decode('utf-8'))
stdout.write(struck.encode('utf-8'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment