Skip to content

Instantly share code, notes, and snippets.

@LindseyB
Last active August 29, 2015 14:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LindseyB/4e238c7a3732226a167f to your computer and use it in GitHub Desktop.
Save LindseyB/4e238c7a3732226a167f to your computer and use it in GitHub Desktop.
filename = "test.jpg"
size = File.size(filename)
count = %x{wc -l #{filename}}.split.first.to_i
factor = count/300
factor = 1 if factor < 1
File.open(filename, "rb+") do |file|
# skip some
file.seek(size/(rand(10..20)), IO::SEEK_CUR)
file.each_line do |line|
puts line
if rand(rand(3..5)*factor) == 0
line_arr = line.force_encoding("ASCII-8BIT").split("")
line_arr[rand(line_arr.length)] = rand(256).chr
new_line = line_arr.join()
file.seek(-(new_line.length), IO::SEEK_CUR)
file.write(new_line)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment