From d4b107f5035413bcf93f24a523a6f8b695ba6b92 Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Fri, 4 Jan 2019 13:54:00 +0100 Subject: Add new scripts Signed-off-by: Florian Pritz --- column.pl | 27 +++++++++++++++++++++++++++ cw | 3 +++ get-arch-keys.pl | 16 ++++++++++++++++ ping-ssh | 47 +++++++++++++++++++++++++++++++++++++++++++++++ sort-images-size | 3 +++ 5 files changed, 96 insertions(+) create mode 100644 column.pl create mode 100755 cw create mode 100644 get-arch-keys.pl create mode 100755 ping-ssh create mode 100755 sort-images-size diff --git a/column.pl b/column.pl new file mode 100644 index 0000000..87290af --- /dev/null +++ b/column.pl @@ -0,0 +1,27 @@ +#!/usr/bin/perl + +use Data::Dumper; +my %width = (); +my @lines = (); +while (my $line = <>) { + chomp $line; + push @lines, $line; + my @parts = split(/\t/, $line); + my $counter = 0; + for (; $counter < @parts; $counter++) { + my $partlen = length($parts[$counter]); + $width{$counter} = $partlen if !defined($width{$counter}) or $partlen > $width{$counter} + } +} + +for my $line (@lines) { + my @parts = split(/\t/, $line); + my $counter = 0; + for (; $counter < @parts; $counter++) { + my $partlen = $width{$counter}; + printf "%-*s | ", $partlen, $parts[$counter]; + } + printf "\n"; +} + +#print Dumper(\%width); diff --git a/cw b/cw new file mode 100755 index 0000000..8f128b6 --- /dev/null +++ b/cw @@ -0,0 +1,3 @@ +#!/bin/bash + +exec chromium --new-window "$@" diff --git a/get-arch-keys.pl b/get-arch-keys.pl new file mode 100644 index 0000000..b7ee42d --- /dev/null +++ b/get-arch-keys.pl @@ -0,0 +1,16 @@ +#!/usr/bin/perl +use warnings; +use strict; +use JSON; +use WWW::Mechanize; +use v5.10; + +my $url = 'https://www.archlinux.org/master-keys/json/'; + +my $mech = WWW::Mechanize->new(cookie_jar => {}); + +$mech->get($url); +my $json = JSON::decode_json($mech->content()); +for my $node (@{$json->{nodes}}) { + say $node->{key} if $node->{group} eq "packager" and $node->{key}; +} diff --git a/ping-ssh b/ping-ssh new file mode 100755 index 0000000..a35e44c --- /dev/null +++ b/ping-ssh @@ -0,0 +1,47 @@ +#!/usr/bin/python + +from timeit import default_timer as timer +import statistics +import subprocess +import sys + +if len(sys.argv) <= 3: + print("usage: ping-ssh ") + sys.exit(1) + +host = sys.argv[1] +repeat = int(sys.argv[2]) +ping_string = sys.argv[3] + +def ping(stdin, stdout): + ping_bytes = (ping_string+"\n").encode() + stdin.write(ping_bytes) + result = stdout.read(len(ping_bytes)) + assert result == ping_bytes + +proc = subprocess.Popen(['ssh', host, 'cat'], + bufsize=0, + stdout=subprocess.PIPE, stdin=subprocess.PIPE) + +# ping once to ensure the "connection" is ready. Without this the first ping +# would be much slower than all others due to ssh/cat starting up +ping(proc.stdin, proc.stdout) + +times = [] + +for i in range(repeat): + start = timer() + ping(proc.stdin, proc.stdout) + end = timer() + time = end - start + times.append(time) + print("{:.5f}ms".format(time * 1000)) + +print("") +print("mean: {:.5f}ms".format(statistics.mean(times) * 1000)) +print("median: {:.5f}ms".format(statistics.median(times) * 1000)) +print("min: {:.5f}ms".format(min(times) * 1000)) +print("max: {:.5f}ms".format(max(times) * 1000)) + +proc.stdin.close() +proc.wait() diff --git a/sort-images-size b/sort-images-size new file mode 100755 index 0000000..d6781ff --- /dev/null +++ b/sort-images-size @@ -0,0 +1,3 @@ +#!/bin/sh + +perl-rename -v 'BEGIN{use Image::ExifTool qw(ImageInfo); use Date::Parse; use Date::Format;}; $data = ImageInfo($_); $size_dir = "small"; $size_dir = "large" if $data->{ImageWidth} > 350 or $data->{ImageHeight} > 350; $date = time2str("%Y-%m-%d", str2time($data->{ModifyDate})); $_ = "$size_dir/$date/$_";' "$@" -- cgit v1.2.3-24-g4f1b