From 7d8e70e55e90f16ae6b82f0f5345caa092cebda5 Mon Sep 17 00:00:00 2001 From: neingeist Date: Mon, 3 Aug 2015 16:12:12 +0200 Subject: [PATCH] add some old scripts --- find-unused | 65 ++++++++++++++++++++++++++++++++++++++++ flickr-download-set | 8 +++++ flickr-download-tag | 8 +++++ pdfjoin-aligned | 26 ++++++++++++++++ pdfnup-slides | 34 +++++++++++++++++++++ rss-title-filter | 72 +++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 213 insertions(+) create mode 100755 find-unused create mode 100755 flickr-download-set create mode 100755 flickr-download-tag create mode 100755 pdfjoin-aligned create mode 100755 pdfnup-slides create mode 100755 rss-title-filter diff --git a/find-unused b/find-unused new file mode 100755 index 0000000..cd7b057 --- /dev/null +++ b/find-unused @@ -0,0 +1,65 @@ +#!/usr/bin/env ruby +# Find +# unused +# directories +# by +# looking +# at +# the +# atimes +# of +# the +# contained +# files. +# +require 'optparse' + +options = {} +options[:days] = 180 + +def used_recently?(path, days) + if File.directory?(path) + used_recently = false + empty = true + Dir.new(path).each do |entry| + if entry != "." && entry != ".." + empty = false + if used_recently?("#{path}/#{entry}", days) + used_recently = true + end + end + end + if !used_recently && !empty + puts "unused: #{path}" + end + return used_recently + elsif File.file?(path) || File.socket?(path) || File.symlink?(path) + return (File.lstat(path).atime >= Time.now() - (days * 24 * 3600)) + else + puts "Unknown file type: #{path}" + exit 1 + end +end + +# Parse options +OptionParser.new do |opts| + opts.banner = "Usage: #{$0} [options] DIRECTORY..." + + opts.separator "" + opts.separator "Find unused (sub-)directories, recursively traversing DIRECTORY, by looking at the atime(s) of all contained files. A directory is considered unused if ALL of the contained files weren't accessed for DAYS days (default is 180 days.)" + opts.separator "" + + opts.on("-d", "--days DAYS", Integer, + "Days after a file is considered unused") do |d| + options[:days] = d + end +end.parse! + +dirs = ARGV +if dirs.length == 0 + dirs = "." +end + +dirs.each do |dir| + used_recently?(dir, options[:days]) +end diff --git a/flickr-download-set b/flickr-download-set new file mode 100755 index 0000000..d5d48f2 --- /dev/null +++ b/flickr-download-set @@ -0,0 +1,8 @@ +#!/bin/sh +seturl=$1 +lynx -dump $seturl | perl -ne 'print "http://flickr.com/photo_zoom.gne?id=$1&size=l\n" if m#([0-9]+)/in/set-#' \ +| while read url; do + lynx -source "$url" | grep "static.*flickr.com" \ + | perl -ne 'print "$1\n" if m#a href="(.*?\.jpg)"#' \ + | xargs wget -c; +done diff --git a/flickr-download-tag b/flickr-download-tag new file mode 100755 index 0000000..9508a7c --- /dev/null +++ b/flickr-download-tag @@ -0,0 +1,8 @@ +#!/bin/sh +tagurl=$1 +lynx -dump $tagurl | perl -ne 'print "http://flickr.com/photo_zoom.gne?id=$1&size=l\n" if m#flickr.com/photos/.*/([0-9]+)/#' \ +| while read url; do + lynx -source "$url" | grep "static.*flickr.com" \ + | perl -ne 'print "$1\n" if m#a href="(.*?\.jpg)"#' \ + | xargs wget -c; +done diff --git a/pdfjoin-aligned b/pdfjoin-aligned new file mode 100755 index 0000000..752ca5d --- /dev/null +++ b/pdfjoin-aligned @@ -0,0 +1,26 @@ +#!/bin/bash +# join pdfs and insert an empty (one-page) pdf for pdfs with an odd page number + +# create an empty (one-page) pdf +emptypdf="$(mktemp -u /tmp/pdfjoin-aligned-XXXXXX).pdf" +echo -ne "0 0 moveto\n() show\n" | ps2pdf - "$emptypdf" + +# go through pdfs +declare -a pdfs +for pdf in "$@"; do + pdfs+=("$pdf") + + # is it odd or not? + pages=$(pdfinfo "$pdf" | awk '{ if (/^Pages:/) { print $2 } }') + odd=$(($pages % 2)) + if [ "$odd" = "1" ]; then + pdfs+=("$emptypdf") + fi +done + +# join! +out="$(mktemp -u /tmp/joined-XXXXXX).pdf" +pdfjoin --outfile "$out" "${pdfs[@]}" + +# cleanup +rm -f "$emptypdf" diff --git a/pdfnup-slides b/pdfnup-slides new file mode 100755 index 0000000..93d5f35 --- /dev/null +++ b/pdfnup-slides @@ -0,0 +1,34 @@ +#!/bin/bash + +tmp=$(mktemp -d /tmp/pdfnup-slides-XXXXX) +[ -z "$tmp" ] && exit 1 + +# put 2x3 slides (pdf) on one page +#pdfnup --nup 2x3 --frame true \ +# --delta "0.5cm 3cm" --offset "0cm 1cm" \ +# --scale 0.85 \ +# "$@" \ +# --outfile "$tmp/1.pdf" + +# put 2x2 slides (pdf) on one page +pdfnup --nup 2x2 --frame true \ + --delta "0.5cm 0.5cm" \ + --scale 0.9 \ + "$@" \ + --outfile "$tmp/1.pdf" + +# scale up to a4 - now works for beamer slides, too. +# hackhackhack +cat > "$tmp/2.tex" < +# Copyright (c) 2005, Joe Mason +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to permit +# persons to whom the Software is furnished to do so, subject to the +# following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +# NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +# USE OR OTHER DEALINGS IN THE SOFTWARE. +# +# Usage: rss-title-filter +# +# Skips all items which do NOT include the given titles. +# +# Example: to include all entries with the title "meme", "quiz" or +# "picture post", do: +# +# rss-title-filter meme quiz "picture post" +# +# Requires the Ruby RSS module, which is included in Ruby 1.8.3 or +# higher and available for older versions of Ruby at +# http://raa.ruby-lang.org/project/rss/. +# +# based on "rss-tag-filter" by Joe Mason. + + +require 'rss/2.0' + +# if no titles were given, no parsing needed +if ARGV.empty? then + STDIN.each do |line| + STDOUT.puts(line) + end + exit(0) +end + +# parse the RSS +rss_source = STDIN.collect.join +begin + rss = RSS::Parser.parse(rss_source) +rescue RSS::InvalidRSSError + rss = RSS::Parser.parse(rss_source, false) # no validation +end + +# filter out all items NOT in the cmd-line args +rss.channel.items.reject! do |item| + found = false + ARGV.each do |arg| + if Regexp.new(arg, Regexp::IGNORECASE).match(item.title) + found = true + end + end + !found +end + +# write the modified rss +STDOUT.puts(rss) +