Archive for janvier 2014

View split on right/left : tile without compiz

10 janvier 2014

My aim was to have keybinding to split the view of my desktop into right/left without Compiz (which is how I discovered this behaviour, but I don’t have that on my desktop computer). Searching on the net for this, I came accross this: http://unix.stackexchange.com/a/17983

While trying to understand it, I rewrote part of it and simplified a bit (it parses the output of xprop to get the active window, which is useless at least for my version of wmctrl):

#!/usr/bin/env bash
# $1 ... top | bottom | left | right
#

xprop -root |
    sed -rne 's/^_NET_WORKAREA\(CARDINAL\) = ([0-9]+), ([0-9]+), ([0-9]+), ([0-9]+).*/\1 \2 \3 \4/p' |
    {
        # (x,y) is topleft corner, (w,h) is space (width, height)
        # available. for me x = 0 but y = 25 because of the gnome
        # menubar which sticks to the top.
        read x y w h
        # Now decide where you want your active window:
        case "$1" in
            top    ) ((h=h/2));;
            bottom ) ((h=h/2));((y=y+h));;
            left   ) ((w=w/2));;
            right  ) ((w=w/2));((x=x+w));;
        esac
        # unmaximize, otherwise nothing happens.
        wmctrl -r ':ACTIVE:' -b remove,maximized_vert,maximized_horz
        # change geometry:
        wmctrl -r ':ACTIVE:' -e 0,$x,$y,$w,$h
    }
Publicités

Downloading full resolution images from Wikipedia

3 janvier 2014

Here’s a snippet I used to download some images from wikipedia.

Usage:
perl younameit.pl WikipediaFilePage LocalName

where WikipediaFilePage is an url like « https://en.wikipedia.org/wiki/File:Bournemouth,_The_Square.jpg »
which describes an image that you want to download at full res, and LocalName is the name you want to give it on your harddisk. You can give as many « WikipediaFilePage LocalName » pairs as you like.

KNOWN BUGS:
– Any error will stop everything (in case there are multiples pairs on the command line).
– There’s a huge memory leak (thanks to feldspath for deeply analyzing my code :D)
– This list is very much incomplete.

#!/usr/bin/perl -w
use WWW::Mechanize;
use strict;
use HTML::TreeBuilder;
binmode STDOUT, ":utf8"; # spit utf8 to terminal
use utf8; # allow for utf8 inside the code.

my $url;
 while (defined($url = shift)) {
 my $mech = WWW::Mechanize->new;
 my $tree = HTML::TreeBuilder->new;
 my $tempfile = shift; ## user supplied

print "Downloading $url...";
 $mech->get($url) and print "done !\n" or die;
 $tree->parse_content($mech->content());
 # real image:
 $url = $tree->look_down(class=>'fullImageLink')->look_down(_tag => "a")->attr('href');

print "Downloading $url to $tempfile...";
 $mech->get($url, ':content_file' => $tempfile) and print "done !\n" or die;

}