Created
May 18, 2017 22:38
-
-
Save tiennou/a23f94b5425505ff29b25e5bd42176cb to your computer and use it in GitHub Desktop.
A Ruby command line tool for your zalgo needs
This file contains hidden or 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/env ruby -w | |
# encoding: utf-8 | |
require 'optparse' | |
options = {} | |
OptionParser.new do |opts| | |
opts.banner = "#{File.basename($0)} [-dz] [string to zalgo|-]" | |
opts.on "-d", "--debug", "Debug mode" do |v| options[:debug] = v; end | |
opts.on "-z", "--zalgo-mode", "Zalgo mode" do |v| options[:zalgo_mode] = v; end | |
end.parse! | |
if ARGV.count == 0 || ARGV.count == 1 && ARGV[0] == "-" | |
string = STDIN.read | |
else | |
string = ARGV.join " " | |
end | |
unicode_diacritics = [ | |
0x0300..0x036F, # Combining Diacritical Marks | |
# 0x1AB0..0x1AFF, # Combining Diacritical Marks Extended | |
# 0x1DC0..0x1DE6, 0x1DFE..0x1DFF, # Combining Diacritical Marks Supplement | |
# 0x20D0..0x20F0, # 0x20FF, # Combining Diacritical Marks for Symbols | |
# 0xFE20..0xFE26, # 0xFE2F, # Combining Half Marks | |
# 0x0483..0x0486, 0x0488..0x0489, # Cyrillic | |
] | |
max_diacritics_bound = 30 | |
diacritics_per_char = 15 | |
zalgolized_string = "" | |
string.each_char.each_with_index do |char, index| | |
diacritics_per_char ||= 0 unless options[:zalgo_mode] | |
diacritics_per_char += rand(-rand(max_diacritics_bound)..rand(max_diacritics_bound)) | |
max_range = rand(diacritics_per_char) | |
max_range += rand(Math.log10(index + 1) / 2) if options[:zalgo_mode] | |
puts "Diacritics per char is #{diacritics_per_char}, max range is #{max_range}" if options[:debug] | |
diacritics_count = rand(0..max_range.to_i) | |
zalgolized_string << char | |
puts "Adding #{diacritics_count} diacritics to char #{char}" if options[:debug] | |
diacritics_count.abs.times do | |
diacritics_range = unicode_diacritics[rand(unicode_diacritics.count)] | |
codepoint = rand(diacritics_range) | |
diacritic = [codepoint].pack "U" | |
zalgolized_string += diacritic | |
end | |
end | |
puts | |
puts | |
puts | |
puts | |
puts zalgolized_string | |
puts | |
puts | |
puts | |
puts |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment