Skip to content

Instantly share code, notes, and snippets.

@banderson
Last active December 20, 2015 11:39
Show Gist options
  • Save banderson/6125480 to your computer and use it in GitHub Desktop.
Save banderson/6125480 to your computer and use it in GitHub Desktop.
Ruby Script to flip text
!/usr/bin/env ruby
# encoding: UTF-8
# adapted from http://www.leancrew.com/all-this/2009/05/im-feelin-upside-down/
class Flipper
CHARS = " abcdefghijklmnopqrstuvwxyz,.?!'()[]{}".split('')
FLIPPED_CHARS = " ɐqɔpǝɟƃɥıɾʞlɯuodbɹsʇnʌʍxʎz'˙¿¡,)(][}{".split('')
DICTIONARY = Hash[CHARS.zip FLIPPED_CHARS]
def self.doit(phrase)
phrase.downcase.reverse.split('').map do |char|
DICTIONARY[char]
end.join ''
end
end
phrase = ARGV.first
raise 'You must provide a phrase to reverse' if phrase.nil?
puts Flipper.doit phrase
flip "{query}" | pbcopy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment