-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslides.vroom
642 lines (448 loc) · 11.6 KB
/
slides.vroom
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
# This is a sample Vroom input file. It should help you get started.
#
# Edit this file with your content. Then run `vroom --vroom` to start
# the show!
#
# See `perldoc Vroom` for complete details.
#
---- config
# Basic config options.
title: Perl sysadmin stuff (Jesse Thompson)
indent: 5
height: 18
width: 20
#auto_size: 1
skip: 0
# The following options are for Gvim usage.
# vim: gvim
# gvimrc: |
# set fuopt=maxhorz,maxvert
# set guioptions=egmLtT
# set guifont=Bitstream_Vera_Sans_Mono:h18
# set guicursor=a:blinkon0-ver25-Cursor
# colorscheme default
----
Jesse Thompson
UW Madison
Division of Information Technology
(Email, Calendar, Chat, Subversion, ...)
----
Perl!
sysadminy stuff...
----
something I've just started using...
----
Compile Perl with: -Duserelocatableinc
Use Relocatable INC
Allows you to move perl to another directory.
----
How to do it?
> ./Configure \
-Dprefix=/opt/perl-5.14.2 \
-des \
-Duserelocatableinc
> # install some cpan modules...
> sudo mv /opt/perl-5.14.2 \
/opt/perl-5.14.2-WithMyAppDeps-YYMMDD
----
1. in dev: build base perl,
install your module dependencies
rename it to something unique
tarball the whole smash
2. in test: unpack tarball
configure app to use new perl path
test/QA your app
3. in prod: unpack tarball
configure app to use new perl path
----
Easy backout failed upgrades...
App uses: #!/opt/perl/bin/perl
# upgrade perl and dependencies
> ln -s /opt/perl-5.14.2-20111108 /opt/perl
# OH NO! everything is broken!
> ln -s /opt/perl-5.14.2-20110421 /opt/perl
# WHEW
----
IN PRODUCTION:
Stay away from
installing modules directly from CPAN
What if CPAN modules change
(and break your app)
between dev -> test -> prod
----
Other advantages:
No need for local::lib, fatpack, PAR
and other workarounds.
* Just install CPAN modules normally.
Easily back out to older rev.
* Just change the perl that your app uses.
Production deployments are done at off-hours
when you are likely to make a mistake.
----
Problems
Some executables installed via ExtUtils::MakeMaker
will have the wrong #!perl path
Maybe others too, but I haven't found them yet.
----
new topic
----
instead of grep and cut (and awk and sed and ...)
USE PERL :-)
----
grep is handy
but its matching capabilities suck
egrep?
getting there...
but still not as good as perl regex
---- perl,i4
> cat file | perl -pe 's/.* IPADDR=(.*?) .*/$1/g'
209.85.225.99
209.85.225.105
209.85.225.147
# I can't ever remember how to do things
# like that using shell tools
# I have to look it up every time
----
command line perl is very handy
not going to go into it all
just think of perl whenever you need
to do any fancy shell scripting
I always end up rewriting all of my
shell script into perl eventually
after they get too complex
----
grepl
A handy script that works like grep
but gives you the power of perl regex
SEE ALSO
perldoc perlretut
---- perl,i4
#!/usr/bin/perl
# regex is the first argument
#
# if there are more arguments,
# then it will treat them as files to read
# e.g. grepl foo myfile.txt
#
# otherwise it reads from STDIN
# e.g. cat myfile.txt | grepl foo
my $pattern = shift @ARGV;
while ( my $line = <> ) {
# ...
}
---- perl,i4
if ( my @matched = $line =~ m{$pattern} ) {
# there were captures in the regex
# so display what was captured
if ( scalar @matched and $matched[0] ne '1' ) {
print join(' ', @matched), "\n";
}
# otherwise the regex just matched on a line
# so display the whole line
else {
print $line;
}
}
---- perl,i4
#
# for example:
# grepl murder slipsum.txt
# (ignore this)
print `echo "> cat slipsum.txt;\n"; cat slipsum.txt; echo "\n> grepl murder slipsum.txt\n"; ./grepl murder slipsum.txt`;
---- perl,i4
#
# for example:
# cat slipsum.txt | grepl ice
# (ignore this)
print `echo "> cat slipsum.txt;\n"; cat slipsum.txt; echo "\n> cat slipsum.txt | grepl ice\n"; cat slipsum.txt | ./grepl ice`;
---- perl,i4
#
# for example:
# grepl "(\w+) made it out" slipsum.txt
# (ignore this)
print `echo "> cat slipsum.txt;\n"; cat slipsum.txt; echo "\n> grepl \\"\(\\w+\) made it out\\" slipsum.txt\n" ;./grepl \" (\\w+) made it out\" slipsum.txt`;
---- perl,i4
#
# for example:
# grepl "(\w+) made it (out)" slipsum.txt
# (ignore this)
print `echo "> cat slipsum.txt;\n"; cat slipsum.txt; echo "\n> grepl \\"\(\\w+\) made it \(out\)\\" slipsum.txt\n" ;./grepl \" (\\w+) made it (out)\" slipsum.txt`;
----
etc
----
new topic
----
overwrite a file using:
sysopen()
flock()
seek()
truncate()
tell()
----
fcntl
C library
for manipulating file descriptors
---- perl,i4
use Fcntl qw(:DEFAULT :flock);
# open file for reading and writing
# and create it if needed
sysopen( my $fh, $file, O_RDWR|O_CREAT )
or die "can't open! $!";
# lock the file
# so that other instances of this script will die
flock( $fh, LOCK_EX )
or die "can't lock! $!";
---- perl,i4
# seek to the beginning of the file
seek( $fh, 0, 0);
# print some data
print $fh "blah blah blah";
# truncate the file
# to where we stopped writing
truncate( $fh, tell($fh) );
# close releases the lock
close( $fh );
----
another example!
----
example: cat a log file starting at last position
memtail
----
something a bit more complex...
----
logcat
----
Specify a time interval,
using both relative and absolute times,
and common language...
to display log lines,
within that interval,
from multiple files,
in order,
efficiently
----
what does logcat use?
Time::ParseDate
File::SortedSeek
---- perl
Time::ParseDate
Recognizes any date and time format,
absolute or relative
---- perl,i4
$seconds = parsedate("Mon Jan 2 04:24:27 1995");
$seconds = parsedate("Tue Apr 4 00:22:12 PDT 1995");
$seconds = parsedate("04.04.95 00:22", ZONE => PDT);
$seconds = parsedate("Jan 1 1999 11:23:34.578", SUBSECOND => 1);
$seconds = parsedate("122212 950404", ZONE => PDT, TIMEFIRST => 1);
$seconds = parsedate("+3 secs", NOW => 796978800);
$seconds = parsedate("2 months", NOW => 796720932);
$seconds = parsedate("last Tuesday");
($seconds, $remaining) = parsedate("today is the day");
($seconds, $error) = parsedate("today is", WHOLE=>1);
---- perl
File::SortedSeek
fast access to large files
---- perl,i4
use File::SortedSeek ':all';
open BIG, $file or die $!;
# find a number or the first number greater
# in a file (ascending order)
$tell = numeric( *BIG, $number );
# optional argument is a reference
# to a subroutine to munge the file lines
# so that suitable values are extracted
# for comparison to $find
$tell = numeric( *BIG, $find, \&munge_line );
----
how does logcat work?
----
e.g.
logcat \
--log_name_re="access_log" \
--start_time="10 minutes ago" \
--end_time="now"
logcat \
--log_name_re="myapp" \
--relative_time="3 days ago"
--start_time="start of today" \
--end_time="end of today" \
---- perl,i4
# setup
my $relative_time = parsedate($args{relative_time});
my $start_time = parsedate($args{start_time},
NOW => $relative_time);
my $end_time = parsedate($args{end_time},
NOW => $relative_time);
---- perl,i4
# get the log files that match the specified name
# and have been modified sometime in the time window
for ( @log_dirs ) {
opendir my $logdir, $_;
for my $file (
grep m/$args{log_name_re}/i, readdir $logdir
) {
...
---- perl,i4
# exclude the ones that haven't been modified
# after the beginning of the target day
my ($mtime) = (stat("$_/$file"))[9];
next if ( $mtime < $start_time );
# save the last-modified time
# so that we can sort the files
$log_files{"$_/$file"} = $mtime;
---- perl,i4
# sort the log files
# so that they are printed in chronological order
return sort {
$log_files{$a} <=> $log_files{$b}
} keys %log_files;
---- perl,i4
# open each log file
for my $logfile ( @log_files ) {
open my $fh, $logfile;
---- perl,i4
# find the first line at or after the start time
File::SortedSeek::numeric(
$fh,
$start_time,
sub { parse_log_time($_) }
);
my $start_point = tell($fh);
my $start_line = <$fh>;
---- perl,i4
# make sure that log lines were found...
if ( ! $start_line
or
parse_log_time($start_line) > $end_time
) {
# no lines in this file
next;
}
---- perl,i4
# find the last line
File::SortedSeek::numeric(
$fh,
$end_time,
sub { parse_log_time($_) }
);
my $end_point = tell($fh);
my $end_line = <$fh>;
---- perl,i4
# seek to the start line
seek($fh, $start_point, 0);
# print all lines
while ( my $line = <$fh> ) {
print $line;
...
# until we reach the end ...
last if ( tell($fh) >= $end_point );
----
so, what is parse_log_time()???
Time::ParseDate is smart,
but you need to help it out
you need to parse out the date/time information
this is kind of a kludge...
---- perl,i4
# Time::ParseDate gives it the line to parse
# we need to return just the date/time info
sub parse_log_time {
my $line = shift;
chomp($line);
my $munged;
---- perl,i4
# UGH, this is too manual
# because there are so many date/time formats
# 20-Aug-2009 11:03:52.12
if ( $line =~ /^(\d+\-\w+\-\d+\s+\d+\:\d+\:\d+\.\d+)\s/ ) {
$munged = $1;
}
# 216.180.217.126 - - [20/Aug/2009:11:03:52 -0500]
if ( $line =~ /^[\d\.]+\s+\-\s+\S+\s+\[(\d+\/\w+\/\d+\:\d+\:\d+\:\d+\s+[\-\+]\d+)\]\s/ ) {
$munged = $1;
}
# 20092008 110352
if ( $line =~ /^(\d{4})(\d{2})(\d{2})\s(\d{2})(\d{2})(\d{2})\s/ ) {
$munged = "$1/$2/$3 $4:$5:$6";
}
# [20/Aug/2009:11:03:52 -0500]
if ( $line =~ /^\[(\d+\/\w+\/\d+\:\d+\:\d+\:\d+\s+[\-\+]\d+)\]/ ) {
$munged = $1;
}
# 2009-08-20T11:03:52
if ( $line =~ /^(\d+\-\d+\-\d+T\d+\:\d+\:\d+)\s+/ ) {
$munged = $1;
}
# [Thu Aug 20 11:03:52 2009]
if ( $line =~ /^\[(\w+\s+\w+\s+\d+\s+\d+\:\d+\:\d+\s+\d+)\]\s+/ ) {
$munged = $1;
}
# Aug 20 11:03:52
if ( $line =~ /^(\w+\s+\d+\s+\d+\:\d+:\d+)\s+/ ) {
$munged = $1;
}
# =INFO REPORT==== 2009-08-20 11:03:52 ===
if ( $line =~ /^[\=\s\w]+\s+(\d+\-\d+\-\d+\s+\d+\:\d+\:\d+)\s+/ ) {
$munged = $1;
}
# [20-Aug-2009 11:03:52]
if ( $line =~ /^\[(\d+\-\w+\-\d+\s+\d+\:\d+\:\d+)\]\s+/ ) {
$munged = $1;
}
# Aug 20 2009 11:03:52
if ( $line =~ /^(\w+\s+\d+\s+\d+\s+\d+\:\d+\:\d+)\s+/ ) {
$munged = $1;
}
# [Wed Aug 20 11:03:52 2009]
if ( $line =~ /^\[(\w+\s+\w+\d+\s+\d+\:\d+\:\d+\s+\d+)\]\s+/ ) {
$munged = $1;
}
# 2010/08/16 15:16:41
if ( $line =~ /^(\d+\/\d+\/\d+\s+\d+\:\d+\:\d+)\s+/ ) {
$munged = $1;
}
# 2011-05-20 11:58:35
if ( $line =~ /^(\d+\-\d+\-\d+\s+\d+\:\d+\:\d+)\s+/ ) {
$munged = $1;
}
---- perl,i4
# run the parsed date/time through Parse::TimeDate
return parsedate($munged);
----
Anyone got a better way to do that part?
----
THE END
----
VROOM (Ingy döt Net)
----
== Slideshows in Vim
* Hate using PowerPoint or HTML Slides for Talks?
+* Use Vroom!
+* You can write you slides in Vim...
* ...and present them in Vim!
----
== Getting Started
* Write a file called 'slides.vroom'.
* Do this in a new directory.
* Run 'vroom --vroom'.
* Voilà!
----
== Navigation
* Hit <SPACE> to move forward.
* Hit <BACKSPACE> to go backwards.
* Hit 'Q' to quit.
---- perl,i4
# This is some Perl code.
# Notice the syntax highlighting.
# Run it with the <RR> vim command.
for my $word (qw(Vroom totally rocks!)) {
print "$word\n";
}
----
== Get Vroom!
* http://search.cpan.org/dist/Vroom/
* http://github.com/ingydotnet/vroom-pm/
----
== Vroom as HTML
* http://ingydotnet.github.com/vroom-pm/
----
== The End