Skip to content

Instantly share code, notes, and snippets.

@tmikeschu
Created June 23, 2019 22:20
Show Gist options
  • Save tmikeschu/6baf0dd856617ef6b8fabf5661449c0e to your computer and use it in GitHub Desktop.
Save tmikeschu/6baf0dd856617ef6b8fabf5661449c0e to your computer and use it in GitHub Desktop.
A fun little script I made to translate svgs polygon points from sketch to my inline implementations
#!/usr/bin/env ruby
def pbcopy(s)
IO.popen("pbcopy", "w") { |f| f << s }
end
def translate(x_offset, y_offset, raw_xys)
raw_xys
.strip
.split("\n")
.map { |pair|
pair
.strip
.split(/[,\s]/)
.map(&:to_i)
}
.map { |(x, y)| [x + x_offset, y + y_offset].join(",") }
.join("\n")
end
if ARGV.length < 3
puts "Too few arguments"
exit
end
x, y, raw = ARGV
result = translate(x.to_i, y.to_i, raw)
pbcopy(result)
puts result
puts "\nCopied to clipboard :)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment