Skip to content

Instantly share code, notes, and snippets.

@cholick
Last active December 10, 2015 00:19
Show Gist options
  • Save cholick/4350645 to your computer and use it in GitHub Desktop.
Save cholick/4350645 to your computer and use it in GitHub Desktop.
Groovy program that rewrites itself exactly using a new, random filename.
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment