typrtail 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.textile +39 -0
- data/Rakefile +10 -0
- data/bin/typrtail +218 -0
- data/pkg/typrtail-0.0.1.gem +0 -0
- data/pkg/typrtail-0.0.1.tgz +0 -0
- data/pkg/typrtail-0.0.1/README.textile +39 -0
- data/pkg/typrtail-0.0.1/Rakefile +10 -0
- data/pkg/typrtail-0.0.1/bin/typrtail +218 -0
- data/pkg/typrtail-0.0.1/typrtail.gemspec +26 -0
- data/typrtail.gemspec +26 -0
- metadata +76 -0
data/README.textile
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
h1. typrtail
|
|
2
|
+
|
|
3
|
+
Tail or cat a file: make it look like someone is typing them.
|
|
4
|
+
|
|
5
|
+
For some processes I was monitoring, this was far more entertaining than just watching a @tail -f@.
|
|
6
|
+
|
|
7
|
+
<pre>
|
|
8
|
+
user@host ~$ tail -f /var/log/messages | typrtail
|
|
9
|
+
</pre>
|
|
10
|
+
|
|
11
|
+
<pre>
|
|
12
|
+
user@host ~$ wget -q -O - http://www.gutenberg.org/files/730/730.txt | head -n 20 | typrtail
|
|
13
|
+
</pre>
|
|
14
|
+
|
|
15
|
+
h1. Installation
|
|
16
|
+
|
|
17
|
+
<pre>
|
|
18
|
+
user@host ~$ gem install typrtail
|
|
19
|
+
</pre>
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
h1. FAQ
|
|
23
|
+
|
|
24
|
+
h2. What good is this?
|
|
25
|
+
|
|
26
|
+
Come on, it's just for fun.
|
|
27
|
+
|
|
28
|
+
h2. Why'd you do this?
|
|
29
|
+
|
|
30
|
+
I was overworked and needed an escape.
|
|
31
|
+
|
|
32
|
+
h2. Doesn't this already exist?
|
|
33
|
+
|
|
34
|
+
Yeah, I'm sure it does, they're probably better too, I needed a break.
|
|
35
|
+
|
|
36
|
+
h2. It's too slow, can you make it faster?
|
|
37
|
+
|
|
38
|
+
Yes, you can. It's a plain Ruby program, open it up and take a look at the top, there are a lot of constants (yes, globals - *gasp* globals! I know, how awful!) that control things like the typing speed. Have at 'em!
|
|
39
|
+
|
data/Rakefile
ADDED
data/bin/typrtail
ADDED
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
# to make everything faster, make this <1.0, sower >1.0 HTH
|
|
4
|
+
$speed_adjust = 1.0
|
|
5
|
+
|
|
6
|
+
$rand_base = 10
|
|
7
|
+
$rand_range = 100.0
|
|
8
|
+
|
|
9
|
+
# 1 in X chance of a typo :D
|
|
10
|
+
$typo_prob = 50
|
|
11
|
+
$min_typo_prob = 10
|
|
12
|
+
$min_slp = 0.02
|
|
13
|
+
|
|
14
|
+
# repeated chars are fast
|
|
15
|
+
$repeat_time = 0.05
|
|
16
|
+
# typing the same char 2x is fast
|
|
17
|
+
$same_type_time = 0.075
|
|
18
|
+
# oops, how fast do you recover from seeing you made one or more typos?
|
|
19
|
+
$time_to_recognize_typo = 0.3
|
|
20
|
+
$sleep_after_space = 0.2
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
# spacebar is wicked quick to hit, so is enter -- unshifted characters are
|
|
24
|
+
# easier than those that require a shift key...
|
|
25
|
+
$typing_rates = {
|
|
26
|
+
" " => 2.0,
|
|
27
|
+
"\n" => 1.5,
|
|
28
|
+
"abcdefghijklmnopqrstuvwxyz" => 0.9,
|
|
29
|
+
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" => 0.50,
|
|
30
|
+
"`1234567890-=[]\\;',./" => 0.60,
|
|
31
|
+
"~!@#\$%^&*()_+{{}|:\"<>?" => 0.2,
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
# typos are near the character typed :)
|
|
35
|
+
$typo_table = {
|
|
36
|
+
"a" => "qwsz",
|
|
37
|
+
"b" => "ghvn ",
|
|
38
|
+
"c" => "dfxv ",
|
|
39
|
+
"d" => "ersfxc",
|
|
40
|
+
"e" => "34wrsd",
|
|
41
|
+
"f" => "rtdgcv",
|
|
42
|
+
"g" => "tyfhvb",
|
|
43
|
+
"h" => "yugjbn",
|
|
44
|
+
"i" => "89uojk",
|
|
45
|
+
"j" => "uihknm,",
|
|
46
|
+
"k" => "iojlm,",
|
|
47
|
+
"l" => "opk;,.",
|
|
48
|
+
"m" => " n,jk",
|
|
49
|
+
"n" => " bmhj ",
|
|
50
|
+
"o" => "90ipkl",
|
|
51
|
+
"p" => "0-o[l;",
|
|
52
|
+
"q" => "12wsa ",
|
|
53
|
+
"r" => "45etdf",
|
|
54
|
+
"s" => "weadzx",
|
|
55
|
+
"t" => "56ryfg",
|
|
56
|
+
"u" => "78yihj",
|
|
57
|
+
"v" => "fgcb ",
|
|
58
|
+
"w" => "23qeas",
|
|
59
|
+
"x" => "sdzc ",
|
|
60
|
+
"y" => "67tugh",
|
|
61
|
+
"z" => "asx",
|
|
62
|
+
|
|
63
|
+
"A" => "aaQWSZ",
|
|
64
|
+
"B" => "bbGHVN ",
|
|
65
|
+
"C" => "ccDFXV ",
|
|
66
|
+
"D" => "ddERSFXC",
|
|
67
|
+
"E" => "ee\#$WRSD",
|
|
68
|
+
"F" => "ffRTDGCV",
|
|
69
|
+
"G" => "ggTYFHVB",
|
|
70
|
+
"H" => "hhYUGJBN",
|
|
71
|
+
"I" => "ii*(UOJK",
|
|
72
|
+
"J" => "jjUIHKNM,",
|
|
73
|
+
"K" => "kkIOJLM,",
|
|
74
|
+
"L" => "llOPK:<>",
|
|
75
|
+
"M" => "mm N<JK",
|
|
76
|
+
"N" => "nn BMHJ ",
|
|
77
|
+
"O" => "oo()IPKL",
|
|
78
|
+
"P" => "pp)_O{L:",
|
|
79
|
+
"Q" => "qq!@WSA ",
|
|
80
|
+
"R" => "rr$%ETDF",
|
|
81
|
+
"S" => "ssWEADZX",
|
|
82
|
+
"T" => "tt%^RYFG",
|
|
83
|
+
"U" => "uu&*YIHJ",
|
|
84
|
+
"V" => "vvFGCB ",
|
|
85
|
+
"W" => "ww@#QEAS",
|
|
86
|
+
"X" => "xxSDZC ",
|
|
87
|
+
"Y" => "yy^&TUGH",
|
|
88
|
+
"Z" => "zzASX",
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
"`" => "1",
|
|
92
|
+
"1" => "`22q",
|
|
93
|
+
"2" => "1133qw",
|
|
94
|
+
"3" => "2244we",
|
|
95
|
+
"4" => "3355er",
|
|
96
|
+
"5" => "4466rt",
|
|
97
|
+
"6" => "5577ty",
|
|
98
|
+
"7" => "6688yu",
|
|
99
|
+
"8" => "7799ui",
|
|
100
|
+
"9" => "8800io",
|
|
101
|
+
"0" => "99-op",
|
|
102
|
+
"-" => "00=p[",
|
|
103
|
+
"=" => "-[]",
|
|
104
|
+
"[" => "-=p];'",
|
|
105
|
+
"]" => "=[\\'",
|
|
106
|
+
"\\" => "]",
|
|
107
|
+
";" => "p[l'./",
|
|
108
|
+
"'" => "[];/",
|
|
109
|
+
"," => " m.kl",
|
|
110
|
+
"." => ",/l;",
|
|
111
|
+
"/" => ".;'",
|
|
112
|
+
"~" => "`!",
|
|
113
|
+
"!" => "11~@Q",
|
|
114
|
+
"@" => "22!#QW",
|
|
115
|
+
"\#" => "33@$WE",
|
|
116
|
+
"$" => "44#%ER",
|
|
117
|
+
"%" => "55$^RT",
|
|
118
|
+
"^" => "66%&TY",
|
|
119
|
+
"&" => "77^*YU",
|
|
120
|
+
"*" => "88&(UI",
|
|
121
|
+
"(" => "99*)IO",
|
|
122
|
+
")" => "00(_OP",
|
|
123
|
+
"_" => "--)+P{",
|
|
124
|
+
"+" => "==_{}",
|
|
125
|
+
"{" => "[[_+P}:\"",
|
|
126
|
+
"}" => "]]+{|\"",
|
|
127
|
+
"|" => "\\\}",
|
|
128
|
+
":" => ";;P{L\">?",
|
|
129
|
+
"\"" => "''{}:?",
|
|
130
|
+
"<" => ",,KLM> ",
|
|
131
|
+
">" => "..<?L:",
|
|
132
|
+
"?" => "//>:\"",
|
|
133
|
+
|
|
134
|
+
" " => " "
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
# keep it real ;)
|
|
138
|
+
def plausible_typo ch
|
|
139
|
+
chars = $typo_table[ch.chr]
|
|
140
|
+
return nil unless chars
|
|
141
|
+
chars[rand(chars.size)]
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
# Ruby msut have these, just don't know what they are
|
|
145
|
+
def is_alpha? ch
|
|
146
|
+
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".include? ch
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
def is_num? ch
|
|
150
|
+
"0123456789".include? ch
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
# Hammer^H^H^H^H^H^Hpause time
|
|
154
|
+
def pause_time ch
|
|
155
|
+
slp = 0.05 + (rand($rand_base) / $rand_range)
|
|
156
|
+
modifier = $typing_rates.keys.detect do |chars|
|
|
157
|
+
chars.include? ch
|
|
158
|
+
end
|
|
159
|
+
modifier = $typing_rates[modifier] || 0.5
|
|
160
|
+
slp / modifier
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
# backup, erase, backup (for next char)
|
|
164
|
+
# NB: should peek, and not do this if next char is a newline b/c this will add
|
|
165
|
+
# a space before the end of the line...
|
|
166
|
+
def erase_typo
|
|
167
|
+
$stderr.putc("\b"[0])
|
|
168
|
+
$stderr.putc(" "[0])
|
|
169
|
+
$stderr.putc("\b"[0])
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
lastch = ' '
|
|
173
|
+
chars_since_typeo = 0
|
|
174
|
+
total_chars = 0
|
|
175
|
+
while ch = $stdin.getc
|
|
176
|
+
total_chars += 1
|
|
177
|
+
slp = pause_time(ch)
|
|
178
|
+
# repeated characters are quick
|
|
179
|
+
if ch == lastch
|
|
180
|
+
slp = $repeat_time
|
|
181
|
+
# sequences of the same 'type' are quick
|
|
182
|
+
elsif is_alpha?(ch) && is_alpha?(lastch)
|
|
183
|
+
slp = $same_type_time
|
|
184
|
+
elsif is_num?(ch) && is_num?(lastch)
|
|
185
|
+
slp = $same_type_time
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
# awww, it gets harder to keep going w/o making a mistake :-)
|
|
189
|
+
typo_prob = $typo_prob - (chars_since_typeo/2)
|
|
190
|
+
typo_prob = typo_prob < $min_typo_prob ? $min_typo_prob : typo_prob
|
|
191
|
+
num_typos = 0
|
|
192
|
+
while rand(typo_prob) <= 1.0
|
|
193
|
+
chars_since_typeo = 0
|
|
194
|
+
typo_prob = $typo_prob
|
|
195
|
+
typo = plausible_typo ch
|
|
196
|
+
if typo
|
|
197
|
+
$stderr.putc typo
|
|
198
|
+
$stderr.flush
|
|
199
|
+
num_typos += 1
|
|
200
|
+
sleep($speed_adjust * $time_to_recognize_typo)
|
|
201
|
+
end
|
|
202
|
+
# making a typo makes another one more likely :P
|
|
203
|
+
typo_prob /= 2
|
|
204
|
+
end
|
|
205
|
+
num_typos.times { erase_typo }
|
|
206
|
+
|
|
207
|
+
# so you made it thorugh the gauntlet? emith the char...
|
|
208
|
+
lastch = ch
|
|
209
|
+
slp += Math.sin(total_chars) / 4.0
|
|
210
|
+
slp = slp < $min_slp ? $min_slp : slp
|
|
211
|
+
|
|
212
|
+
sleep($speed_adjust * slp)
|
|
213
|
+
|
|
214
|
+
$stdout.putc ch
|
|
215
|
+
$stdout.flush
|
|
216
|
+
sleep($speed_adjust * $sleep_after_space) if ' ' == ch.chr
|
|
217
|
+
chars_since_typeo += 1
|
|
218
|
+
end
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
h1. typrtail
|
|
2
|
+
|
|
3
|
+
Tail or cat a file: make it look like someone is typing them.
|
|
4
|
+
|
|
5
|
+
For some processes I was monitoring, this was far more entertaining than just watching a @tail -f@.
|
|
6
|
+
|
|
7
|
+
<pre>
|
|
8
|
+
user@host ~$ tail -f /var/log/messages | typrtail
|
|
9
|
+
</pre>
|
|
10
|
+
|
|
11
|
+
<pre>
|
|
12
|
+
user@host ~$ wget -q -O - http://www.gutenberg.org/files/730/730.txt | head -n 20 | typrtail
|
|
13
|
+
</pre>
|
|
14
|
+
|
|
15
|
+
h1. Installation
|
|
16
|
+
|
|
17
|
+
<pre>
|
|
18
|
+
user@host ~$ gem install typrtail
|
|
19
|
+
</pre>
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
h1. FAQ
|
|
23
|
+
|
|
24
|
+
h2. What good is this?
|
|
25
|
+
|
|
26
|
+
Come on, it's just for fun.
|
|
27
|
+
|
|
28
|
+
h2. Why'd you do this?
|
|
29
|
+
|
|
30
|
+
I was overworked and needed an escape.
|
|
31
|
+
|
|
32
|
+
h2. Doesn't this already exist?
|
|
33
|
+
|
|
34
|
+
Yeah, I'm sure it does, they're probably better too, I needed a break.
|
|
35
|
+
|
|
36
|
+
h2. It's too slow, can you make it faster?
|
|
37
|
+
|
|
38
|
+
Yes, you can. It's a plain Ruby program, open it up and take a look at the top, there are a lot of constants (yes, globals - *gasp* globals! I know, how awful!) that control things like the typing speed. Have at 'em!
|
|
39
|
+
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
# to make everything faster, make this <1.0, sower >1.0 HTH
|
|
4
|
+
$speed_adjust = 1.0
|
|
5
|
+
|
|
6
|
+
$rand_base = 10
|
|
7
|
+
$rand_range = 100.0
|
|
8
|
+
|
|
9
|
+
# 1 in X chance of a typo :D
|
|
10
|
+
$typo_prob = 50
|
|
11
|
+
$min_typo_prob = 10
|
|
12
|
+
$min_slp = 0.02
|
|
13
|
+
|
|
14
|
+
# repeated chars are fast
|
|
15
|
+
$repeat_time = 0.05
|
|
16
|
+
# typing the same char 2x is fast
|
|
17
|
+
$same_type_time = 0.075
|
|
18
|
+
# oops, how fast do you recover from seeing you made one or more typos?
|
|
19
|
+
$time_to_recognize_typo = 0.3
|
|
20
|
+
$sleep_after_space = 0.2
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
# spacebar is wicked quick to hit, so is enter -- unshifted characters are
|
|
24
|
+
# easier than those that require a shift key...
|
|
25
|
+
$typing_rates = {
|
|
26
|
+
" " => 2.0,
|
|
27
|
+
"\n" => 1.5,
|
|
28
|
+
"abcdefghijklmnopqrstuvwxyz" => 0.9,
|
|
29
|
+
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" => 0.50,
|
|
30
|
+
"`1234567890-=[]\\;',./" => 0.60,
|
|
31
|
+
"~!@#\$%^&*()_+{{}|:\"<>?" => 0.2,
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
# typos are near the character typed :)
|
|
35
|
+
$typo_table = {
|
|
36
|
+
"a" => "qwsz",
|
|
37
|
+
"b" => "ghvn ",
|
|
38
|
+
"c" => "dfxv ",
|
|
39
|
+
"d" => "ersfxc",
|
|
40
|
+
"e" => "34wrsd",
|
|
41
|
+
"f" => "rtdgcv",
|
|
42
|
+
"g" => "tyfhvb",
|
|
43
|
+
"h" => "yugjbn",
|
|
44
|
+
"i" => "89uojk",
|
|
45
|
+
"j" => "uihknm,",
|
|
46
|
+
"k" => "iojlm,",
|
|
47
|
+
"l" => "opk;,.",
|
|
48
|
+
"m" => " n,jk",
|
|
49
|
+
"n" => " bmhj ",
|
|
50
|
+
"o" => "90ipkl",
|
|
51
|
+
"p" => "0-o[l;",
|
|
52
|
+
"q" => "12wsa ",
|
|
53
|
+
"r" => "45etdf",
|
|
54
|
+
"s" => "weadzx",
|
|
55
|
+
"t" => "56ryfg",
|
|
56
|
+
"u" => "78yihj",
|
|
57
|
+
"v" => "fgcb ",
|
|
58
|
+
"w" => "23qeas",
|
|
59
|
+
"x" => "sdzc ",
|
|
60
|
+
"y" => "67tugh",
|
|
61
|
+
"z" => "asx",
|
|
62
|
+
|
|
63
|
+
"A" => "aaQWSZ",
|
|
64
|
+
"B" => "bbGHVN ",
|
|
65
|
+
"C" => "ccDFXV ",
|
|
66
|
+
"D" => "ddERSFXC",
|
|
67
|
+
"E" => "ee\#$WRSD",
|
|
68
|
+
"F" => "ffRTDGCV",
|
|
69
|
+
"G" => "ggTYFHVB",
|
|
70
|
+
"H" => "hhYUGJBN",
|
|
71
|
+
"I" => "ii*(UOJK",
|
|
72
|
+
"J" => "jjUIHKNM,",
|
|
73
|
+
"K" => "kkIOJLM,",
|
|
74
|
+
"L" => "llOPK:<>",
|
|
75
|
+
"M" => "mm N<JK",
|
|
76
|
+
"N" => "nn BMHJ ",
|
|
77
|
+
"O" => "oo()IPKL",
|
|
78
|
+
"P" => "pp)_O{L:",
|
|
79
|
+
"Q" => "qq!@WSA ",
|
|
80
|
+
"R" => "rr$%ETDF",
|
|
81
|
+
"S" => "ssWEADZX",
|
|
82
|
+
"T" => "tt%^RYFG",
|
|
83
|
+
"U" => "uu&*YIHJ",
|
|
84
|
+
"V" => "vvFGCB ",
|
|
85
|
+
"W" => "ww@#QEAS",
|
|
86
|
+
"X" => "xxSDZC ",
|
|
87
|
+
"Y" => "yy^&TUGH",
|
|
88
|
+
"Z" => "zzASX",
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
"`" => "1",
|
|
92
|
+
"1" => "`22q",
|
|
93
|
+
"2" => "1133qw",
|
|
94
|
+
"3" => "2244we",
|
|
95
|
+
"4" => "3355er",
|
|
96
|
+
"5" => "4466rt",
|
|
97
|
+
"6" => "5577ty",
|
|
98
|
+
"7" => "6688yu",
|
|
99
|
+
"8" => "7799ui",
|
|
100
|
+
"9" => "8800io",
|
|
101
|
+
"0" => "99-op",
|
|
102
|
+
"-" => "00=p[",
|
|
103
|
+
"=" => "-[]",
|
|
104
|
+
"[" => "-=p];'",
|
|
105
|
+
"]" => "=[\\'",
|
|
106
|
+
"\\" => "]",
|
|
107
|
+
";" => "p[l'./",
|
|
108
|
+
"'" => "[];/",
|
|
109
|
+
"," => " m.kl",
|
|
110
|
+
"." => ",/l;",
|
|
111
|
+
"/" => ".;'",
|
|
112
|
+
"~" => "`!",
|
|
113
|
+
"!" => "11~@Q",
|
|
114
|
+
"@" => "22!#QW",
|
|
115
|
+
"\#" => "33@$WE",
|
|
116
|
+
"$" => "44#%ER",
|
|
117
|
+
"%" => "55$^RT",
|
|
118
|
+
"^" => "66%&TY",
|
|
119
|
+
"&" => "77^*YU",
|
|
120
|
+
"*" => "88&(UI",
|
|
121
|
+
"(" => "99*)IO",
|
|
122
|
+
")" => "00(_OP",
|
|
123
|
+
"_" => "--)+P{",
|
|
124
|
+
"+" => "==_{}",
|
|
125
|
+
"{" => "[[_+P}:\"",
|
|
126
|
+
"}" => "]]+{|\"",
|
|
127
|
+
"|" => "\\\}",
|
|
128
|
+
":" => ";;P{L\">?",
|
|
129
|
+
"\"" => "''{}:?",
|
|
130
|
+
"<" => ",,KLM> ",
|
|
131
|
+
">" => "..<?L:",
|
|
132
|
+
"?" => "//>:\"",
|
|
133
|
+
|
|
134
|
+
" " => " "
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
# keep it real ;)
|
|
138
|
+
def plausible_typo ch
|
|
139
|
+
chars = $typo_table[ch.chr]
|
|
140
|
+
return nil unless chars
|
|
141
|
+
chars[rand(chars.size)]
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
# Ruby msut have these, just don't know what they are
|
|
145
|
+
def is_alpha? ch
|
|
146
|
+
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".include? ch
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
def is_num? ch
|
|
150
|
+
"0123456789".include? ch
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
# Hammer^H^H^H^H^H^Hpause time
|
|
154
|
+
def pause_time ch
|
|
155
|
+
slp = 0.05 + (rand($rand_base) / $rand_range)
|
|
156
|
+
modifier = $typing_rates.keys.detect do |chars|
|
|
157
|
+
chars.include? ch
|
|
158
|
+
end
|
|
159
|
+
modifier = $typing_rates[modifier] || 0.5
|
|
160
|
+
slp / modifier
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
# backup, erase, backup (for next char)
|
|
164
|
+
# NB: should peek, and not do this if next char is a newline b/c this will add
|
|
165
|
+
# a space before the end of the line...
|
|
166
|
+
def erase_typo
|
|
167
|
+
$stderr.putc("\b"[0])
|
|
168
|
+
$stderr.putc(" "[0])
|
|
169
|
+
$stderr.putc("\b"[0])
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
lastch = ' '
|
|
173
|
+
chars_since_typeo = 0
|
|
174
|
+
total_chars = 0
|
|
175
|
+
while ch = $stdin.getc
|
|
176
|
+
total_chars += 1
|
|
177
|
+
slp = pause_time(ch)
|
|
178
|
+
# repeated characters are quick
|
|
179
|
+
if ch == lastch
|
|
180
|
+
slp = $repeat_time
|
|
181
|
+
# sequences of the same 'type' are quick
|
|
182
|
+
elsif is_alpha?(ch) && is_alpha?(lastch)
|
|
183
|
+
slp = $same_type_time
|
|
184
|
+
elsif is_num?(ch) && is_num?(lastch)
|
|
185
|
+
slp = $same_type_time
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
# awww, it gets harder to keep going w/o making a mistake :-)
|
|
189
|
+
typo_prob = $typo_prob - (chars_since_typeo/2)
|
|
190
|
+
typo_prob = typo_prob < $min_typo_prob ? $min_typo_prob : typo_prob
|
|
191
|
+
num_typos = 0
|
|
192
|
+
while rand(typo_prob) <= 1.0
|
|
193
|
+
chars_since_typeo = 0
|
|
194
|
+
typo_prob = $typo_prob
|
|
195
|
+
typo = plausible_typo ch
|
|
196
|
+
if typo
|
|
197
|
+
$stderr.putc typo
|
|
198
|
+
$stderr.flush
|
|
199
|
+
num_typos += 1
|
|
200
|
+
sleep($speed_adjust * $time_to_recognize_typo)
|
|
201
|
+
end
|
|
202
|
+
# making a typo makes another one more likely :P
|
|
203
|
+
typo_prob /= 2
|
|
204
|
+
end
|
|
205
|
+
num_typos.times { erase_typo }
|
|
206
|
+
|
|
207
|
+
# so you made it thorugh the gauntlet? emith the char...
|
|
208
|
+
lastch = ch
|
|
209
|
+
slp += Math.sin(total_chars) / 4.0
|
|
210
|
+
slp = slp < $min_slp ? $min_slp : slp
|
|
211
|
+
|
|
212
|
+
sleep($speed_adjust * slp)
|
|
213
|
+
|
|
214
|
+
$stdout.putc ch
|
|
215
|
+
$stdout.flush
|
|
216
|
+
sleep($speed_adjust * $sleep_after_space) if ' ' == ch.chr
|
|
217
|
+
chars_since_typeo += 1
|
|
218
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
SPEC = Gem::Specification.new do |s|
|
|
6
|
+
s.name = "typrtail"
|
|
7
|
+
s.version = "0.0.1"
|
|
8
|
+
s.author = "Kyle Burton"
|
|
9
|
+
s.email = "kyle.burton@gmail.com"
|
|
10
|
+
s.platform = Gem::Platform::RUBY
|
|
11
|
+
s.description = <<DESC
|
|
12
|
+
typrtail is a toy program.
|
|
13
|
+
|
|
14
|
+
It simulates a person typing a file, it is suitable to be used in a pipeline.
|
|
15
|
+
|
|
16
|
+
user@host ~$ tail -f /var/log/messages | typrtail
|
|
17
|
+
|
|
18
|
+
DESC
|
|
19
|
+
s.summary = "Hey! It looks like you're typing but your fingers aren't moving!"
|
|
20
|
+
# s.rubyforge_project = "typrtail"
|
|
21
|
+
s.homepage = "http://github.com/kyleburton/typrtail"
|
|
22
|
+
s.files = Dir.glob("**/*")
|
|
23
|
+
s.executables << "typrtail"
|
|
24
|
+
s.require_path = "bin"
|
|
25
|
+
s.has_rdoc = false
|
|
26
|
+
end
|
data/typrtail.gemspec
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
SPEC = Gem::Specification.new do |s|
|
|
6
|
+
s.name = "typrtail"
|
|
7
|
+
s.version = "0.0.1"
|
|
8
|
+
s.author = "Kyle Burton"
|
|
9
|
+
s.email = "kyle.burton@gmail.com"
|
|
10
|
+
s.platform = Gem::Platform::RUBY
|
|
11
|
+
s.description = <<DESC
|
|
12
|
+
typrtail is a toy program.
|
|
13
|
+
|
|
14
|
+
It simulates a person typing a file, it is suitable to be used in a pipeline.
|
|
15
|
+
|
|
16
|
+
user@host ~$ tail -f /var/log/messages | typrtail
|
|
17
|
+
|
|
18
|
+
DESC
|
|
19
|
+
s.summary = "Hey! It looks like you're typing but your fingers aren't moving!"
|
|
20
|
+
# s.rubyforge_project = "typrtail"
|
|
21
|
+
s.homepage = "http://github.com/kyleburton/typrtail"
|
|
22
|
+
s.files = Dir.glob("**/*")
|
|
23
|
+
s.executables << "typrtail"
|
|
24
|
+
s.require_path = "bin"
|
|
25
|
+
s.has_rdoc = false
|
|
26
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: typrtail
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
hash: 29
|
|
5
|
+
prerelease: false
|
|
6
|
+
segments:
|
|
7
|
+
- 0
|
|
8
|
+
- 0
|
|
9
|
+
- 1
|
|
10
|
+
version: 0.0.1
|
|
11
|
+
platform: ruby
|
|
12
|
+
authors:
|
|
13
|
+
- Kyle Burton
|
|
14
|
+
autorequire:
|
|
15
|
+
bindir: bin
|
|
16
|
+
cert_chain: []
|
|
17
|
+
|
|
18
|
+
date: 2010-07-27 00:00:00 -04:00
|
|
19
|
+
default_executable:
|
|
20
|
+
dependencies: []
|
|
21
|
+
|
|
22
|
+
description: " typrtail is a toy program. \n\n It simulates a person typing a file, it is suitable to be used in a pipeline.\n\n user@host ~$ tail -f /var/log/messages | typrtail\n\n"
|
|
23
|
+
email: kyle.burton@gmail.com
|
|
24
|
+
executables:
|
|
25
|
+
- typrtail
|
|
26
|
+
extensions: []
|
|
27
|
+
|
|
28
|
+
extra_rdoc_files: []
|
|
29
|
+
|
|
30
|
+
files:
|
|
31
|
+
- bin/typrtail
|
|
32
|
+
- pkg/typrtail-0.0.1/bin/typrtail
|
|
33
|
+
- pkg/typrtail-0.0.1/Rakefile
|
|
34
|
+
- pkg/typrtail-0.0.1/README.textile
|
|
35
|
+
- pkg/typrtail-0.0.1/typrtail.gemspec
|
|
36
|
+
- pkg/typrtail-0.0.1.gem
|
|
37
|
+
- pkg/typrtail-0.0.1.tgz
|
|
38
|
+
- Rakefile
|
|
39
|
+
- README.textile
|
|
40
|
+
- typrtail.gemspec
|
|
41
|
+
has_rdoc: true
|
|
42
|
+
homepage: http://github.com/kyleburton/typrtail
|
|
43
|
+
licenses: []
|
|
44
|
+
|
|
45
|
+
post_install_message:
|
|
46
|
+
rdoc_options: []
|
|
47
|
+
|
|
48
|
+
require_paths:
|
|
49
|
+
- bin
|
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
51
|
+
none: false
|
|
52
|
+
requirements:
|
|
53
|
+
- - ">="
|
|
54
|
+
- !ruby/object:Gem::Version
|
|
55
|
+
hash: 3
|
|
56
|
+
segments:
|
|
57
|
+
- 0
|
|
58
|
+
version: "0"
|
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
60
|
+
none: false
|
|
61
|
+
requirements:
|
|
62
|
+
- - ">="
|
|
63
|
+
- !ruby/object:Gem::Version
|
|
64
|
+
hash: 3
|
|
65
|
+
segments:
|
|
66
|
+
- 0
|
|
67
|
+
version: "0"
|
|
68
|
+
requirements: []
|
|
69
|
+
|
|
70
|
+
rubyforge_project:
|
|
71
|
+
rubygems_version: 1.3.7
|
|
72
|
+
signing_key:
|
|
73
|
+
specification_version: 3
|
|
74
|
+
summary: Hey! It looks like you're typing but your fingers aren't moving!
|
|
75
|
+
test_files: []
|
|
76
|
+
|