Last active
December 16, 2015 16:49
-
-
Save draegtun/5465881 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Rebol [ | |
see-gist: https://gist.github.com/miyagawa/5455942 | |
also-this: https://gist.github.com/shanselman/5422230#comment-823247 | |
comment: "My fledgling Rebol port of this Perl code" | |
requires: "Rebol/View - for https:// port" | |
github-support: "Thank you Austin@Github for (initiating) the fix for Rebol syntax highlighting" | |
] | |
split-string: func [text delim /local s coll] [ | |
coll: copy [] | |
parse/all text [ | |
some [copy s [to delim | to end] (append coll s) delim] | |
] | |
coll | |
] | |
pick-random: func [from-series] [ | |
random/seed now ; only needs to be done once per script but here so not forgotten! | |
pick from-series random length? from-series | |
] | |
spam-text: read https://gist.github.com/shanselman/5422230/raw/9863d88bde2f9dcf6b2e7a284dd4a428afdc8 | |
samples: split-string spam-text "|^/" | |
template: pick-random samples | |
; below replaces {placeholders} within the input stream (template) | |
parse/all template [ | |
any [ | |
thru "{" begin: copy s to "}" ending: | |
( | |
begin: back begin ; move back to include { | |
ending: next ending ; move forward to include } | |
text: split-string s "|" | |
move-mark: change/part begin pick-random text ending | |
) | |
:move-mark ; moved the mark to end of change | |
] | |
] | |
print template |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment