Skip to content

Instantly share code, notes, and snippets.

@bjeanes
Created August 3, 2016 00:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bjeanes/f61d65a136c98dc86cdd8fefc98e1b84 to your computer and use it in GitHub Desktop.
Save bjeanes/f61d65a136c98dc86cdd8fefc98e1b84 to your computer and use it in GitHub Desktop.
Low effort anonymisation script a `rails-erd` generated `.dot` file (which I used to submit a Graphviz bug report)
dot = ARGF.read
matches = Hash.new { |h, k| h[k] = "Anonymized_#{rand 9999}" }
replaced1 = dot.gsub(/\b"?m_([A-Za-z0-9_:]+)"?\b/) { |m| m.sub(%r|\b#{$1}\b|, matches[$1]) }
regexp = Regexp.union(matches.keys.map { |k| Regexp.new(k) })
replaced2 = replaced1.gsub(regexp) { |m| matches[m] }
puts replaced2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment