Posts Tagged ‘Programming’

Recession, War, Politics, Poverty…. Software Development?

Friday, July 17th, 2009

The way things are these days, you’d think that I, like I would imagine many other people in the world, would be thinking about money, the recession, the potential for war between countries who have been flirting with the bomb, my mother and the sale of her house, poverty in Africa, and the general suckage (is that a word?) in the world.

But no, I’m not thinking about those things.  What’s on my most most of the time is software development and programming.  I’m constantly thinking about what I’m good at, what I suck at, and what I need to do to get better.  Is that selfish?  Let me answer that - yes it is very selfish, but I don’t necessarily believe that selfishness is always a bad thing (part of me can relate to Ayn Rand’s philosophy of Rational Self-interest).

The question though is not “is this selfish?” Rather, the question I’m putting out there is “is this normal?” There are enough things going on right now in my life, dealing with situations and people that I find simply unreasonable, that I’m finding it hard to identify what is “reasonable” any more, because what I see as unreasonable seems to be the norm for the majority.

So is it wrong to think about my career and personal development during times of stress? I feel it to be instinctive to focus on your strengths during times of uncertainty, but what do others out there think? Do you feel that in times of stress, you should cut away from what you’re used to and try something new, or go on vacation? Or do you believe that it’s the perfect time to share with others, give back to your community or family and try to increase your karma (if you believe in such things)? These courses of action are not mutually exclusive, but it helps to identify what needs focus if they’re not jumbled together.

If this post seems a little incoherent, it’s 1am, and my eye-lids have been drooping constantly since I started typing.
Have a good night all :)

Converting Freemind Mind-maps Directly to Perl Hash Trees

Friday, May 29th, 2009

I use Freemind quite a bit for brainstorming and as an outliner.  One of it’s better uses for me is to hammer out an idea for a perl hash tree very quickly.  The problem is that once I have the hash tree exactly the way I want it in Freemind, I have to manually re-create the hash tree in perl source, with all the required formatting.

This is no longer the case, as I’ve written a quick and dirty “freemind2perl” script (below) which takes a Freemind mind-map file, and converts it into a perl hash tree automagically.  I’m not sure if it will work with all versions of Freemind, but mind-map files (.mm files) are XML based, and the format really hasn’t changed across versions.

Just save the script below as ‘freemind2perl.pl’ and run it with ‘perl freemind2perl.pl yourmap.mm’.  It requires the “XML::Simple” perl module to be installed.

Here’s the script (click here to download):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/perl -w
 
use strict;
 
use XML::Simple;
use Data::Dumper;
 
my $xml = new XML::Simple;
my $mm_file = shift;
my $data = $xml->XMLin("$mm_file");
my $clean;
 
sub prep_clean
{
    my $data = shift;
    my $clean;
 
    foreach my $key ( keys %{ $data } )
    {
        if ( $key eq "TEXT" )
        {
            $clean->{$data->{$key}} = 1;
        }
 
        if ( $key eq "node" )
        {
            if ( ref( $data->{$key} ) eq "HASH" )
            {
                $clean->{$data->{'TEXT'}} = prep_clean(\%{$data->{$key}});
            }
 
            if ( ref( $data->{$key} ) eq "ARRAY" )
            {
                my $sub_hashes = {};
                for ( my $i = 0; $i <= $#{$data->{$key}}; $i++)
                {
                    foreach my $sub_hash ( \%{ $data->{$key}[$i] } )
                    {
                        my $subout = prep_clean( $sub_hash );
                        $sub_hashes = { %$sub_hashes, %$subout };
                    }
                }
                $clean->{$data->{'TEXT'}} = $sub_hashes;
            }
        }
    }
    return $clean;
}
 
$clean = prep_clean( \%{ $data->{'node'} } );
 
print Dumper(\$clean);
 
exit;

Back to Basics - Very Simple Log Monitoring with Perl

Friday, March 6th, 2009

There are many many tools out there which allow you to monitor and view your system or networking logs in several different ways.  Sometimes though, you may find yourself looking for a specific feature that none of these tools currently provide.  Whenever your goals are very specific, and you don’t want to use a big feature-full program to accomplish a simple task, you may want to consider writing your own tool.

Below is a simple Perl program I wrote which does just that. All the requirements of the program are within the script itself (using the __DATA__ handle at the bottom of the file). The only thing you may need to install on your system to get this to work is the File::Tail CPAN package.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/perl -w
 
use strict;
use File::Tail;
 
my @patterns = <data>;
my $file = File::Tail->new ("/var/log/syslog");
while ( defined(my $line=$file->read) )
{
    my $match = &filter($line);
    if ( $match eq "no" )
    {
        print $line;
    }
}
 
sub filter ()
{
    my $line = $_[0];
    my $match = "no";
    foreach my $test (@patterns)
    {
        chomp($test);
        if ( $line =~ m/$test/ )
        {
            $match = "yes";
        }
    }
    return $match;
}
 
__DATA__
PROTO=UDP SPT=67 DPT=68
ACCEPT IN=br0 OUT=vlan1 src=192.168.0.111.*PROTO=TCP.*DPT=80
ACCEPT IN=br0 OUT=vlan1 src=192.168.0.102.*PROTO=TCP.*DPT=80
ACCEPT IN=br0 OUT=vlan1 src=192.168.0.111.*PROTO=TCP.*DPT=443
ACCEPT IN=br0 OUT=vlan1 src=192.168.0.102.*PROTO=TCP.*DPT=443
ACCEPT IN=vlan1 OUT=br0.*DST=192.168.0.101.*PROTO=UDP.*DPT=1755
ACCEPT IN=vlan1 OUT=br0.*DST=192.168.0.101.*PROTO=TCP.*DPT=1755
ACCEPT IN=br0 OUT=vlan1 src=10.100.0.1.*PROTO=UDP.*DPT=53
JBLLNXWKS dhclient
 
__END__

This program will monitor the end of the file (like the Unix ‘tail’ command) and check for new log entries. When it detects new lines in the log, it will filter those lines with the patterns defined at the end of the script (under __DATA__) and display anything it detects in the logs except those filter lines.

You’ll probably notice that the filter lines are regular expressions, which makes this script more powerful than doing filtering by simple full-string comparison.

Aside from simply printing the output to STDOUT, you could use regular expressions to pop pieces of each line into an array or hash, in order to do calculations, such as how many entries had a source IP of X, or destination port of Y, etc.

Its definitely a good thing to keep in mind that whatever software you could possibly need is already out there on the internet, and possibly open source. However, its also good to keep in mind that YOU can create a tool yourself to accomplish your specific task; all it takes is a little self-confidence, effort, and patience.

Dev Tools: Recent Updates to Bazaar and Loggerhead

Thursday, February 5th, 2009

I’ve been using the Bazaar Version Control System, along with it’s Loggerhead repository viewer for only a short while, but I am very happy with how my development environments are coming together.  If you are not happy with your current version control system, then these tools are definitely worth a look.

Bazaar

For those who are using the Bazaar Version Control System (a.k.a BZR), version 1.11 was released on January 19th, which fixes a number of bugs, adds performance enhancements, and tightens up a few GUI integration features for Windows users.

Loggerhead

In step with the Bazaar project, Loggerhead, the web based BZR repository viewer has been updated to version 1.10 which includes GUI updates and improvements to Loggerhead’s repository browsing and caching features.

Download Bazaar and Loggerhead using APT

Both Loggerhead and Bazaar can be downloaded via Debian style APT repositories using these directions. Make certain to use the correct repositories for your version of Ubuntu, and add the appropriate APT repository key to your APT key ring.

For example, if you are using “hardy” (Ubuntu 8.04), you would add the following repositories to your /etc/apt/sources.list:

1
2
deb http://ppa.launchpad.net/bzr/ppa/ubuntu hardy main
deb-src http://ppa.launchpad.net/bzr/ppa/ubuntu hardy main

Then, you would add the repository public key to your key-ring, like so:

1
2
3
gpg --no-default-keyring --keyring /tmp/bzr.keyring --keyserver keyserver.ubuntu.com --recv   ECE2800BACF028B31EE3657CD702BF6B8C6C1EFD
gpg --no-default-keyring --keyring /tmp/bzr.keyring --export --armor  ECE2800BACF028B31EE3657CD702BF6B8C6C1EFD | sudo apt-key add -
rm /tmp/bzr.keyring

Then just update your local package listing, and install BZR and Loggerhead as follows:

1
2
sudo apt-get update
sudo apt-get install bzr loggerhead

And voila, you’re good to go!

Braindump: WxWidgets, Version Control, and Firefox Bookmarks

Wednesday, September 17th, 2008

WxWidgets GUI Programming

I’ve been thinking about creating an application using the WxWidgets GUI API.  I’ve read a lot about it, and many seem to really enjoy the results of the applications they’ve created with it.

For my own purposes, I’ve been looking for the ideal GUI API that would allow me to quickly create cross-platform desktop applications for Windows and Linux platforms (Mac would be a bonus).  I’ve looked at QT, GTK, and MingGW.. but I’ve been turned off because they don’t seem to have strong Perl and/or Python bindings (although Perl strong with Tk, I’ve heard).

I’ve tried a small test Python program with WxWidgets (GTK version), and was pleasantly surprised at the simplicity of the code.  I think I’m going try some other tests, this time using Perl, as I want to note the differences in complexity between Perl and Python code.  Currently, Perl is my canvas of choice1.

(more…)

  1. Being that I see programming as an art, more than anything else []

Learning Java For Freemind

Saturday, November 26th, 2005

I’m trying to do some fast track learning of Java programming so that I can extend some of the functionality of Freemind. There are many features that I think would be extremely useful, but I don’t think the current developers are going to get around to them anytime soon. I asked for some guidance on the Open Discussion forum at freemind.sourceforge.net, but didn’t get much help, so it looks like I’m on my own!

Click Here to read the message I posted to the forum.