Wednesday, August 17, 2016

How To Write Codes In Perl For Accomodating To Simple Testings

In order to write scripts in perl which are testable, it is good to follow the following proposed method (assuming this code is inside file a.pl):-


#!/usr/bin/env perl                                                                                   

sub main
{                                                                                                  
    ### Your main code goes here           
    # ... ... ...                          
    1;                                                         
}


sub is_five
{
    my $num = shift(@_);
    if ($num == 5)
    {
        return 1;
    }
    else:
    {
        return 0;
    }
} # is_five


############################
# This loop will only be entered if this script is called explicitly, ie:-
#   $./a.pl
#
# This loop will not be entered If this file is required, ie:-
#   require 'a.pl'
############################
unless (caller)
{
    main();
}
Now, to write a test that tests the is_five() function, we can create a file call test_a.py, and write the test like this:-
#!/usr/bin/env perl

use Test::Simple tests => 2;
require "a.pl";

sub test_is_five___pass
{
    return is_five(5)
}
sub test_is_five___fail
{
    return is_five(3)
}

unless (caller)
{
    ok(test_is_five___pass());
    ok(! test_is_five___fail());
}

Thursday, August 4, 2016

The Untold Story Behind The Christmas Tree

Christmas Tree are a must during ....well......Christmas. (duh)

Especially when it comes to malls and huge shopping complexes, or theme parks.

People love gathering around a well decorated Christmas tree for photo shots.

Well, there was this mall which decided to make it different. They brought in a 1000 pound 100 feet Christmas tree.

2 groups of people are put in charged of making it happen
- one is responsible for decorating it with bells and whistles
- the other is responsible for making it stable so it doesn't collapse and is safe for people to stick around.

Well, I'm lazy to type. You know most of the drill. Along the process , debates on whether to emphasize more on the decorative or to put more budget and resource on safety is a never ending process.

To cut the story short, here is how it goes.....

If the tree stays put for the rest of Christmas,  no customer or even anyone is going to even notice the existence of the group that puts in effort to make the Christmas tree safe.

But If the tree falls, they are the ones that will get all the heat first.

Well, as for the group of people that focus on adding bells and whistles?

Regardless of whether the tree falls or not, they will be the first to get all the credits during the first day of Christmas when all the people pill over and stick around the Christmas tree.

What if the tree falls on the next day? Well, these folks have already claimed their credits, and are already on their way planning on decorating their next Christmas tree for the next year.

That is the hard truthful fact of life.

How To Bypass Kerberos(kinit) Authentication

Whenever you try to setuid and impersonate as someone else to run something, it is very likely that you will run into kerberos/kinit issues....