Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

init

  • Loading branch information...
commit 6a5d3ab22e02727e0c6ec7309cdef22d0f7c4765 0 parents
@perlpilot authored
9 p5/af
@@ -0,0 +1,9 @@
+#!/usr/bin/env perl
+
+use Text::Autoformat;
+
+autoformat({
+ all => 1, # format all of the input
+ case => "sentence ", # use two spaces at the end of sentences
+ @ARGV # pass command line arguments as parameters
+});
20 p5/columnize
@@ -0,0 +1,20 @@
+#!/usr/bin/env perl
+
+use 5.012;
+use strict; use warnings;
+use Getopt::Std;
+
+my %opt;
+getopts("n:s:", \%opt);
+
+# -n NUMBER - number of columns, defaults to 3
+# -s STRING - delimiter between columns, default is " "
+
+my $delim = $opt{s} || " ";
+$opt{n} ||= 3;
+chomp(my @data = <>);
+
+my $inc = int(@data / $opt{n})+(@data%$opt{n} == 0 ? 0 : 1);
+for my $i (0..($inc-1)) {
+ say join $delim, grep { defined } @data[map { $i + ($_-1) * $inc } 1..$opt{n}];
+}
7 p5/dms2dd
@@ -0,0 +1,7 @@
+#!/usr/bin/perl -l
+
+while (@ARGV) {
+ ($deg,$min,$sec) = splice(@ARGV,0,3);
+ push @dd, $deg + $min/60 + $sec/3600;
+}
+print join ",", map { sprintf("%.5f",$_) } @dd;
73 p5/get-apod
@@ -0,0 +1,73 @@
+#!/usr/bin/env perl
+
+# Run with no args, gets today's Astronomy Picture of the Day (APOD)
+# Given a date, gets the APOD for that day.
+
+use 5.010;
+use strict; use warnings;
+use DateTime;
+use Mojo::UserAgent;
+use Mojo::IOLoop;
+use POSIX qw/ strftime /;
+use File::Basename;
+
+my $DEBUG = 0;
+
+my $ua = Mojo::UserAgent->new;
+
+my @dates;
+my $base_url = "http://apod.nasa.gov/apod/";
+if (@ARGV == 2) {
+ my ($start_date, $end_date) = map {
+ my ($year,$month,$day) = /^(\d\d\d\d)-(\d\d)-(\d\d)$/;
+ DateTime->new( day => $day, month => $month, year => $year )
+ } @ARGV;
+ my $cdate = $start_date;
+ while ($cdate <= $end_date) {
+ push @dates, $cdate->clone;
+ $cdate->add( days => 1 );
+ }
+} elsif (@ARGV == 1) {
+ my $date = shift;
+ my ($year,$month,$day) = $date =~ /^(\d\d\d\d)-(\d\d)-(\d\d)$/ or die "Invalid date: $date";
+ my $dt = DateTime->new( day => $day, month => $month, year => $year );
+ push @dates, $dt;
+}
+@dates = DateTime->today unless @dates;
+
+my ($crawl, @urls, %seen);
+$crawl = sub {
+ my $id = shift;
+ return Mojo::IOLoop->stop unless my $d = shift @dates;
+
+ my $apod = $base_url . $d->strftime("ap%y%m%d.html");
+ $ua->get($apod => sub {
+ my ($ua,$tx) = @_;
+ my $dom = $tx->res->dom;
+ unless ($dom =~ /404 Not Found/) {
+ $dom->find('a')->each( sub {
+ my $e = shift;
+ return unless my $img = $e->at("a > img:only-child");
+ for my $u ( $e->attrs('href'), $img->attrs('src') ) {
+ next if $seen{$u}++;
+ my $fname = basename $u;
+ my $src = $base_url . $u;
+ my $dst_dir = $d->strftime("%Y-%m");
+ mkdir($dst_dir) unless -d $dst_dir;
+ my $dst = "$dst_dir/$fname";
+ next if -e $dst;
+ say $src ." -> ".$dst if $DEBUG;
+ $ua->get($src => sub {
+ my ($ua,$tx) = @_;
+ say "saving $dst";
+ $tx->res->content->asset->move_to($dst);
+ });
+ }
+ });
+ }
+ $crawl->($id);
+ });
+};
+
+$crawl->($_) for 1..5;
+Mojo::IOLoop->start unless Mojo::IOLoop->is_running;
15 p5/jul
@@ -0,0 +1,15 @@
+#!/usr/bin/env perl
+
+use 5.012;
+use strict; use warnings;
+use POSIX qw/ strftime mktime /;
+use Time::Local qw/ timegm_nocheck /;
+use Getopt::Std;
+
+my %opt;
+getopts('y:', \%opt);
+
+my $year = $opt{y} || (localtime)[5];
+for my $j (1..366) {
+ say strftime("%m/%d/%Y (%j)", gmtime(timegm_nocheck(0, 0, 0, $j, 0, $year)));
+}
43 p5/update-wallch-config
@@ -0,0 +1,43 @@
+#!/usr/bin/env perl
+
+use 5.010;
+use strict; use warnings;
+use File::Find;
+use File::Temp qw/ tempfile /;
+
+my @DIRS = ( "/home/duff/Images/NASA" ); # where to look for images
+my $WALLCH_CONFIG = "/home/duff/.config/Wallch/MainWindow.conf";
+
+my @images; # images we've found that will be added to wallch's config
+find(sub {
+ return unless /\.(jpg|jpeg|gif|png)$/i;
+ push @images, $File::Find::name;
+}, @DIRS);
+
+@images = sort @images;
+
+my $list_widget = 0;
+my ($ofh, $outfile) = tempfile( UNLINK => 1 );
+say $outfile;
+open my $wfh, "<", $WALLCH_CONFIG or die;
+while (<$wfh>) {
+ if ($list_widget) {
+ next if /^\d+\\item=/;
+ if (/^size=\d+/) {
+ $list_widget = 0;
+ next;
+ }
+ }
+ $list_widget = 1 if /^\[listwidgetitem\]/;
+ print $ofh $_;
+ if ($list_widget) {
+ for my $i (0..$#images) {
+ say $ofh $i + 1 . "\\item=$images[$i]";
+ }
+ say $ofh "size=" . scalar @images;
+ }
+}
+close($wfh);
+close($ofh);
+unlink($WALLCH_CONFIG) && link($outfile, $WALLCH_CONFIG) or link($outfile, "/tmp/wallch") and die;
+
1  p6/README
@@ -0,0 +1 @@
+placeholder
Please sign in to comment.
Something went wrong with that request. Please try again.