Monday, 28 December 2015

Perl script for my I3 Status Bar

I decided to roll out mu own little script to handle my I3 window manager status bar.  It's a good way to get back into a bit of Perl.
I also wanted to roll out my own little JSON formatter.  I did not feel to need to go with what ever Perl module offers.  Still some fine tuning required.  It crashes when a song title contains a double quote.

#!/usr/bin/perl 
use strict;

sub toJSON{
    my $retval, my $left, my $right;
    my $sep;
    while ( $left = shift){
        if ($left eq "text"){
            $left = "full_text";
        } 
        $right = shift;
        $retval = $retval . $sep. qq/"$left":"$right"/;
        $sep=",";
    }
    return "{".$retval ."}"; 
}

sub getvol{
    my $vol = 0;
    $vol=`mixerctl outputs.master`; #outputs.master=150,150
    $vol =~ /=(\d+),/;
    return sprintf ("%.0f",$1/2.55);
}

sub getdate{
    my @months = qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec );
    my @days = qw(Sun Mon Tue Wed Thu Fri Sat Sun);
    my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime();
    return sprintf("%s %s %s, %02d:%02d:%02d", @days[$wday], $mday, @months[$mon], $hour, $min, $sec);
}

sub getsong{
    my $retval = `/usr/local/bin/mpc current`;
    chomp($retval);
    return $retval;
}

sub display{
    my $song_, my $date_, my $vol_, my $weather_;
    $song_ = toJSON("text", getsong(), "color", "#808000");
    $vol_ =  toJSON("text", "Vol:".getvol()."%");
    $date_ = toJSON("text", getdate(), "color", "#9060f0");
    $weather_ = toJSON("text", checkweather(), "color", "#009000");
    printf ("[%s,%s,%s,%s],", $song_ , $vol_ , $weather_, $date_);
}

sub checkweather{
    my $epoch_ = time();
    my $filename = "/tmp/tmp.xml";
    my $fileage = time() - (stat($filename))[9];
    if ($fileage > 3600){ #Time to refresh weather data
        system("ftp -o /tmp/tmp.xml http://weather.gc.ca/rss/city/qc-126_e.xml");
    }
my $temperature="No data";
my $condition, my $pressure, my $humididy, my $windchill, my $dewpoint, my $windspeed;
    my $overnightcondition;
    my $titletagcount=0; #at 5th tag, get overnight conditions.
    # 0 : Gatineau
    # 1 : Warning
    # 2 : Current conditions
    # 3 : Night conditions
open(FILE,"/tmp/tmp.xml") || die "Failed: $!\n";
while ( <FILE> ) {
        if (/<title>(.*)<\/title>/ ){
            ++$titletagcount;
            #printf ("%d : %s\n", $titletagcount, $1);
            if ($titletagcount == 4 ){
                $overnightcondition=$1;
            }
        }
if (/<b>Condition:<\/b> (.*) <b/){
  $condition = $1;
        }elsif (/<b>Temperature:<\/b> (-?[\d.]+)/){
  $temperature = sprintf("%s°C", $1);
}elsif (/<b>Pressure.*<\/b> ([\d.]+)/){
$pressure = sprintf("%s kPa",$1);
}elsif (/<b>Humidity:<\/b> ([\d]+)/){
$humididy = sprintf("%s\%",$1);
}elsif (/<b>Wind:<\/b> (.*)<br/){
$windspeed = sprintf("%s",$1);
}elsif (/<b>Dewpoint:<\/b> (-?[\d.]+)/){
$dewpoint = $1;
}elsif (/<b>Wind Chill:<\/b> (.*)<br/){
$windchill = sprintf("[%s]", $1);
}
}
return sprintf("%s %s%s, Wind:%s, P:%s, RH:%s, %s", 
        $condition, $temperature, $windchill, $windspeed, $pressure, $humididy, $overnightcondition);

}

sub main{
    print '{"version":1}[';
    for(;;){
        display();
        sleep(5);
    }
}

main();

(.*)<\/title>/ ){
            ++$titletagcount;
            #printf ("%d : %s\n", $titletagcount, $1);
            if ($titletagcount == 4 ){
                $overnightcondition=$1;
            }
        }
  if (/<b>Condition:<\/b> (.*) <b/){
     $condition = $1;
        }elsif (/<b>Temperature:<\/b> (-?[\d.]+)/){
     $temperature = sprintf("%s°C", $1);
  }elsif (/<b>Pressure.*<\/b> ([\d.]+)/){
   $pressure = sprintf("%s kPa",$1);
  }elsif (/<b>Humidity:<\/b> ([\d]+)/){
   $humididy = sprintf("%s\%",$1);
  }elsif (/<b>Wind:<\/b> (.*)<br/){
   $windspeed = sprintf("%s",$1);
  }elsif (/<b>Dewpoint:<\/b> (-?[\d.]+)/){
   $dewpoint = $1;
  }elsif (/<b>Wind Chill:<\/b> (.*)<br/){
   $windchill = sprintf("[%s]", $1);
  }
 }
 return sprintf("%s %s%s, Wind:%s, P:%s, RH:%s, %s", 
        $condition, $temperature, $windchill, $windspeed, $pressure, $humididy, $overnightcondition);

}

sub main{
    print '{"version":1}[';
    for(;;){
        display();
        sleep(5);
    }
}

main();
</pre>

Sunday, 23 August 2015

Setting up An Alternative Aquarium.

Inspired from the book of the same title
"An Alternative Aquarium: A Robust Habitat" that I just finished reading.

I will use my 20 gal long that I bought recently.  It was not really intended for this but for some dirt setup anyway.  I did not have a stand, so had to make one.  Good old 2X4 held together with home made ash dowels and 12 1/2in carriage bolts.  A coat of iron buff to throw in some color and a coat of Dasish oil still drying.  And I need to decide where to set it up. It might be my bedroom tank.


I dug out 2 full buckets of clay from the backyard.  Dug almost 2 feet down.  I don't fertilize the lawn.  So that should be ok.  There were some pretty big earthworms.  Then I need to decide if I go wild hunting for soil or if I use the pond soil I bought as this is what I was supposed to use before I read the book...

Haven't decided yet on the plants and fauna.  There will be a heater as it gets cold here in the winter.  No filter, just a pump.

Here is the pump setup.






Layering the substrate.  Clay from my backyard, pond soil and play sand.  Then time to fill up.  It's a myth that setting up a dirt tank is messy.






Adding some supports for land plants that get their water from the tank through a wick.  One of my dog, Pasha, helped with the watering mat I used to make the wicks.







The tanks as of 3 Oct 2015.  Fauna includes 9 White cloud mountain minnows and 1 hillstream loach.  As usual, pond and trumpet snails are part of the game.


Saturday, 1 August 2015

Friday, 17 July 2015

Cala Lillies rooting in the river above the tank.

This is one week of growth for the cala lillies bulbs.  Growth is insane.  It is so far the fastest growing plant.


Tuesday, 7 July 2015

Mario's over the tank river - part 2

There has been some modifications.  I did not like the outflows.  They take too much real estate over the tank.  I installed two bulkheads instead.  I lined the inside of the bulkheads with some textile to kill the sound and eliminate splashes.

I did a leak test overnight.  All seem ok.  I added some raiser blocks to give place for the filter intake.







Saturday, 4 July 2015

Mario's over the tank river.

This little river will be installed atop my 75 gallon tank.  The river is the same length as the tank; 48 inches.  It is about 5 inches wide and just over 1.5 inches high.  It's not high, it will be low flow river with of course plants in it.  Bed will be lavarock with maybe some pieces  of drift wood.

This is the barebone box without the ends.  Because it's dadoes, just wanted to do a dry fit before glueing the parts together



This is the outflow.  Water will return to the tanks through this small opening.

This is some arrangements in progress.  I seived all the lava rock I have to get some smaller ones.  I am a little short in rocks.  I will throw some larger ones int.  I painted and varnished the outside of the wooden box.  The inside is line with a PVC pond liner.  Then I place a layer of geotextile then the rocks.


Saturday, 27 June 2015

The almost 1 2X4 riparium lamp stand

Because the 10 gal tank is in a rather dark corner, I am building this very simple stand.  If satisfy with it, I might build some more for other tanks.

Material is 1 2X4 plus about 24 inches of a 2X6 for the legs.
Hardware is 6 lag bolts, 3"X5/16.

I applied some iron buff to darken the wood.  The I will probably just oil it...  Picture to come.

Sunday, 7 June 2015

A larger planter, for my 29 gal this time - Turning it On

View Part 1

I decided to direct the output of my 2213 Eheim canister filter to the planter.  I reduced the flow for now.  Of course it made the tank rather cloudy.  That should clear up...

Some observations.  The geotextile seem to defy the gravity.  Hanging free and lower than the bottom of the planter, capillarity seem to suck the water out of the planter.


Turning the filter on, water flows down the geotextile.  I extended the geotextile by adding a longer layer as the dripping is a little noisy.  Adding a longer layer that touches the surface of the water in the tank makes the system completely silent.

Here is the outflow of the canister filter flowing into the planter.

And finally, the big mess in the tank.  Fishes really seem to careless.

9 June 2015, the flow of the filter is set to max.  Water in the tank has cleared up a bit.  Here is a close look at the mini river...

2015-06-13.  Quick update.  The planter is receiving visitors from the tank.  Some snails are working their way up the water fall :)

2015-08-04.  Peace Lily really catching up.  Tank water is clear.  It's my black water tank.  The paint holder HOB filter is... holding on.





A larger planter, for my 29 gal this time

Planter on top of aquarium or hanging on the side of the tank is an addictive activity.  Here is one I am setting up on my 29 gallon tank.

I took a planter that I lined with a piece of PVC pond liner because the planter has a drain hole.  I laid over the liner a sheet of geotextile.  I cut a piece off the front portion of the planter.  The water will drain back in the tank slowly flowing against the geotextile that I cut longer.  Eventually, some moss could be established there.

Some of the plants: Pothos, Spathiphyllum (very small for now), Tradescantia zebrina, Papyrus (Egyptian?), Fittonia.



So this is what the planter looks like on the tank.  Now I just need to figure out how I want to setup the pump.

Part 2 - Turning it On

Friday, 5 June 2015

I recently set up a home made HOB planter made of a cheap paint holder bought at Dollarama.  The planter is hung on my 15 gal tank.




I added some moss from the bottom of the tank.  I laid the moss on some geotextile that should remain wet from the water flow.  Alos put some wilder moss I collected from the pond in the backyard.




An overall view of the tank as of 30 May 2015