Skip to content

Instantly share code, notes, and snippets.

@rubypanther
Created January 14, 2012 10:01
Show Gist options
  • Save rubypanther/1610875 to your computer and use it in GitHub Desktop.
Save rubypanther/1610875 to your computer and use it in GitHub Desktop.
FICS paste cleaner utility
#!/usr/bin/env ruby
FICS_LIMIT = 400
if RUBY_VERSION < '1.9'
require 'iconv'
def conv str
Iconv.conv("US-ASCII//TRANSLIT//IGNORE","UTF-8", str)
end
else
def conv str
str.encode 'US-ASCII', 'UTF-8', :invalid => :replace, :undef => :replace
end
end
def print_chunk chunk
chunk.strip!
print "\n+++\n%s\n---\s" % chunk unless chunk.empty?
end
while input = STDIN.gets
str = conv input
str.scan(/.{0,#{FICS_LIMIT}}(?:(?!\w)|$)/).each do |chunk|
print_chunk chunk
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment