Created
January 31, 2017 06:41
-
-
Save RangerDane/6493e10a851982a6b79437a1a907a5bc to your computer and use it in GitHub Desktop.
aadd sone authnticity to qny sent3nce
This file contains hidden or 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
# _____ __ _ ____ | |
# / ___// /___ ______ (_) __/_ __ | |
# \__ \/ __/ / / / __ \/ / /_/ / / / | |
# ___/ / /_/ /_/ / /_/ / / __/ /_/ / | |
# /____/\__/\__,_/ .___/_/_/ \__, / | |
# /_/ /____/ | |
# type like you're trying really hard | |
# give it a sentence, an intelligence score from 0 to 1 | |
# and it'll knock you down a dozen IQ points or so | |
# non-deterministic (sorry), not very efficient (sorry) | |
# examples: | |
stupify( "I enjoy a hearty breakfast each morning.", 0.25 ) | |
# => "i enjoy a hsqrty breakfwst 3ach morning." | |
stupify( "Oh no, not the reactor!", 0.1 ) | |
# => "oh no, nott the rrreaactor!" | |
stupify( "Subtlety is the spice of life.", 0.75 ) | |
# => "Subtlety is the slice oof life." | |
def stupify( string, intelligence ) | |
# following comments apply to intelligence == 0 | |
# and scale to 0% at intelligence == 1 (nothing happens) | |
typos = (1 - intelligence) ** 2 # chance increases quadratically | |
string.chars.map do |char| | |
if char == " " && rand < 0.25 * typos | |
# 25% of spaces are removed or doubled | |
[" ", ""] .sample | |
elsif char == "!" && rand < 0.5 * typos | |
# 50% of exclamation marks are overemphasized | |
["!", "!!", "!!!", "!!!!"].sample | |
elsif [",.?"].include? char && rand < 0.5 * typos | |
# 50% of punctuation marks are simply removed | |
"" | |
elsif rand < typos * 0.05 | |
# 5% of remaining characters are just repeated | |
([char] * (( rand ** 2 ) * 2 + 1).ceil).join | |
elsif char.upcase == char && rand < 0.95 * typos | |
# 95% of remaining uppercase letters are converted to downcase | |
char.downcase | |
elsif rand < typos * 0.1 | |
# 10% of remaining characters after falling through are mapped to a typo | |
typo_letter char | |
else | |
char | |
end | |
end.join | |
end | |
def typo_letter( letter ) | |
if TYPOS[ letter.to_sym ] | |
(TYPOS[ letter.to_sym ].chars + [""]).sample | |
else | |
letter | |
end | |
end | |
TYPOS = { | |
q: "sw2`aa11", | |
w: "aq1de3ss22", | |
e: "sw2fr4dd33", | |
r: "de3gt5ff44", | |
t: "fr4hy6gg55", | |
y: "ju7gthh66", | |
u: "ji88hhy7", | |
i: "ko99jju8", | |
o: "lp00kki9", | |
p: ";[--llo0", | |
a: "xswzzqq", | |
s: "cdwwxxza", | |
d: "ccfeexs", | |
f: "vvgrrccd", | |
g: "bbhyyvvftt", | |
h: "njjuyybgg", | |
j: "mkkiuhhn", | |
k: ",,lloijjm", | |
l: ".;;po,kk", | |
z: "xsaa", | |
x: "cdszz", | |
c: "vvfdxxx", | |
v: "bbgfccc", | |
b: "nhgv", | |
n: "mmmjhb", | |
m: ",,kjnnn", | |
Q: "ASWW@!A", | |
W: "ASEEQQ###", | |
E: "SDR$$W", | |
R: "DFT%$EE", | |
T: "YYGF^&", | |
Y: "TU&&GGH", | |
U: "*&IYH", | |
I: "O(*UJK", | |
O: "0))0P", | |
P: "{_L", | |
A: "QWSS", | |
S: "AWDEZ", | |
D: "ERF", | |
F: "TRG", | |
G: "HYT", | |
H: "GJYU", | |
J: "HHUIK", | |
K: "LIJO", | |
L: "::P>", | |
Z: "XXXAS", | |
X: "ZZC", | |
C: "VVVXXXFD", | |
V: "BBBCCCGF", | |
B: "NNNVVVHG", | |
N: "MMMMNJK", | |
M: "<<<KJN" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment