Skip to content

Instantly share code, notes, and snippets.

@WA9ACE
Last active December 10, 2015 21:38
Show Gist options
  • Save WA9ACE/4496200 to your computer and use it in GitHub Desktop.
Save WA9ACE/4496200 to your computer and use it in GitHub Desktop.
Text Replacer
#!/usr/bin/env ruby
content = ''
Dir.glob(['*.php', '*.html', '*.htm', '*.js', '*.css']).each_with_index do |filename, index|
file = File.read(filename)
# Ruby assumes all things created are UTF-8 which is false and will stop executing
# when if finds something that isn't. Hence this.
file.encode!('UTF-16', :undef => :replace, :invalid => :replace, :replace => "")
file.encode!('UTF-8')
file = file.gsub(/href="^http/, content)
File.open(filename, 'w') { |f| f.puts file }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment