Skip to content

Instantly share code, notes, and snippets.

@zoffixznet

zoffixznet/p6.p6 Secret

Created July 18, 2018 18:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zoffixznet/6902c3fb1ccab4d73624d90b3b165734 to your computer and use it in GitHub Desktop.
Save zoffixznet/6902c3fb1ccab4d73624d90b3b165734 to your computer and use it in GitHub Desktop.
constant width = 80;
my Int $total-lines = 0;
my Int $total-words = 0;
my $excludes = set <cache css data node_modules vendor views>;
sub say-so($name, $lines, $words) { say sprintf('%-60.s | %5.d | %6.d', $name, $lines, $words) }
sub count-stuff(Str $dir) {
my int $subtotal-lines = 0;
my int $subtotal-words = 0;
sub doit($dir) {
my @dirs = $dir;
while @dirs {
for dir @dirs.shift -> $file {
if ($file.IO.f && $file.IO.extension eq 'js') {
given $file.IO.open.slurp {
my @lines := .lines.cache;
my @words := .words.cache;
$subtotal-lines += @lines;
$subtotal-words += @words;
say-so($file, @lines, @words);
}
}
elsif ($file.IO.d && $file.IO.basename ∉ $excludes ) {
@dirs.push: $file;
}
}
}
}
doit($dir);
say '-' x width;
say-so('Subtotal', $subtotal-lines, $subtotal-words);
say '';
$total-lines += $subtotal-lines;
$total-words += $subtotal-words;
}
my $start = now;
count-stuff('/tmp/foo/js');
count-stuff('/tmp/foo/js2');
say '=' x width;
say-so('Total', $total-lines, $total-words);
my $stop = now;
say '';
say "start: $start, stop: $stop, diff: {$stop-$start}";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment