public
Last active

Groovy program that rewrites itself exactly using a new, random filename.

  • Download Gist
replicator.groovy
Groovy
1 2 3 4 5
def p = '''
@Grab(group='commons-lang', module='commons-lang', version='2.4') import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric
File file = new File("${randomAlphanumeric(8)}.groovy").write(p)
new GroovyShell(new Binding([p: "def p = ${"'"*3}${p}${"'"*3}; ${p.readLines()[3]}"])).evaluate(p.readLines()[0..2].join(';') as String)
'''; new GroovyShell(new Binding([p: "def p = ${"'"*3}${p}${"'"*3}; ${p.readLines()[3]}"])).evaluate(p.readLines()[0..2].join(';') as String)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.