Categorie
Information and Communications Technology

VBA Macro Example to Update Outlook Contacts

This is a simple macro example that describes how to update outlook contacts:

Sub updateContacts()
    Dim ContactsFolder As Folder
    Dim Contact As ContactItem
    Set ContactsFolder = Session.GetDefaultFolder(olFolderContacts)
    i = 0
    For Each Contact In ContactsFolder.Items
        first_name = Contact.FirstName
        middle_name = Contact.MiddleName
        last_name = Contact.LastName
        If middle_name <> "" Then
            Contact.FirstName = first_name & " " & middle_name
            Contact.MiddleName = ""
            Contact.Save
            i = i + 1
        End If
    Next
    MsgBox ("Contacts Found: " & ContactsFolder.Items.Count & ", Updated: " & i)
End Sub
Categorie
Information and Communications Technology

GNU ddrescue log SVG graph

This is a perl script that creates the svg code that matches a ddrescue log file.
SVG module is required. Edit the $INPUT_FILE and $SCALE_FACTOR variables as needed.
The SVG code is outputted to standard output. The messages to standard error.
Use ddrescue-svg-log.pl > output.svg to output to file.

#!/usr/bin/perl
use strict;
use warnings;
use SVG;
use Math::BigInt;
##############################
my $SCALE_FACTOR = 10240000;
my $SCALE_FACTOR_LABEL = 1024 * 1024 * 1024; #giga
my $INPUT_FILE = "sda-80gb-log.txt";
##############################
my $ddlogfile;
open $ddlogfile, "<$INPUT_FILE";
my $svg = SVG->new(width=>1000,height=>200);
# use explicit element constructor to generate a group element
my $svg_disc_group=$svg->group(id => 'disc_group');
while (<$ddlogfile>) {
    my $row = $_;
    chomp $row;
    # STATUS CHARACTERS: +,-,/,*,?
    if($row =~ m/^(0x[0-9A-z]*)\s*(0x[0-9A-z]*)\s*(\+|-|\/|\*|\?)/) {
        my $start = $1;
        my $size = $2;
        my $status = $3;
        
        print STDERR $row;
        
        #CALCULATE SVG COORDINATES USING $SCALE_FACTOR
        my $bigint_start_scaled = Math::BigInt->new($1);
        my $bigint_size_scaled = Math::BigInt->new($2);
        my ($_qx, $_rx) = $bigint_start_scaled->bdiv($SCALE_FACTOR);
        my ($_qw, $_rw) = $bigint_size_scaled->bdiv($SCALE_FACTOR);
        my $x = $_qx->numify() + ( $_rx->numify() / $SCALE_FACTOR ) ;
        my $w = $_qw->numify() + ( $_rw->numify() / $SCALE_FACTOR ) ;
       
        #LABEL VALUES
        my $bigint_start_label = Math::BigInt->new($1);
        my $bigint_size_label = Math::BigInt->new($2);
        my ($_q_start_lbl, $_r_start_lbl) = $bigint_start_label->bdiv($SCALE_FACTOR_LABEL);
        my ($_q_size_lbl, $_r_size_lbl) = $bigint_size_label->bdiv($SCALE_FACTOR_LABEL);
        my $start_lbl = $_q_start_lbl->numify() + ( $_r_start_lbl->numify() / $SCALE_FACTOR_LABEL ) ;
        my $size_lbl = $_q_size_lbl->numify() + ( $_r_size_lbl->numify() / $SCALE_FACTOR_LABEL ) ;
        my $rect_label = sprintf("%.2f", $start_lbl) . "[" . sprintf("%.2f", $size_lbl) . "]($status)";
               
        my $svg_sector_group = $svg_disc_group->group();
        my $rect_style = ($status eq '+')?{ fill=>"green" }:{ fill=>"red", stroke=>"red" };
        
        # add a rectangle to the group
        $svg_sector_group->rectangle(
                x     => $x,
                width => $w,
                y => 0,
                height => 30,
                style => $rect_style
            );
               
        $svg_sector_group->text(x=>$x, y=>40, -cdata=> $rect_label, style=>'font-size: 2px');
        
        print STDERR ("START: $start, SIZE: $size, STATUS: $status\n");
    }
    
}
# now render the SVG object, implicitly use svg namespace
print $svg->xmlify;