Tuesday, October 23, 2012

PERL Remove array element

Deleting value from an array is easy if you know the element/index but if you only got the element/index value and not sure of it's location, you'll need a few more lines to do this. Here's a code snippet you can use if you need to delete an element to your array, given that you only know the element value.

---------------------
      my $index;
                foreach(0..$#array_list){
                        if ($array_list[$_] =~ /^$element_value/) {
                                $index = $_;
                        }
                }
                splice @array_list, $index, 1;

---------------------

This can used as a sub within your code and will require two arguments (@array_list --> the array where you need to delete something and $element_value --> the value you want to delete from you array)




Wednesday, August 1, 2012

PERL Date function

Basic perl script the extract system date and prints different format.

getTime() function takes a numeric argurment which determines the date format.

Function can be used as  '$variable = &getTime(x)' , where x can any number from 0 - 4 (which ever formate you want) and '$variable' takes the return value.

----------------------------------------------------------------

#!/usr/bin/perl

sub main {
        my $curr_date;
        my $count;
        for ($count=0;$count <=4;$count++){
                $curr_date = getTime($count);
                print "Current date : $curr_date\n";
        }

}

&main();

sub getTime {
        my $timeFormat = shift;
        my @months = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
        my @weekDays = qw(Sun Mon Tue Wed Thu Fri Sat Sun);
        my ($second, $minute, $hour, $dayOfMonth, $month, $yearOffset, $dayOfWeek, $dayOfYear, $daylightSavings) = localtime();
        my $year = 1900 + $yearOffset;
        my $monthss = $month +1 ;
        my $theTime = "";
        if ($timeFormat == 0){
                $theTime = "$hour:$minute:$second, $weekDays[$dayOfWeek] $months[$month] $dayOfMonth, $year";
        }
        elsif ($timeFormat == 1){
                $theTime = "$months[$month] $dayOfMonth, $year";
        }
        elsif ($timeFormat == 2 ){
                my $paddedHour = sprintf("%02d", $hour);
                my $paddedMin = sprintf("%02d", $minute);
                my $paddedSec = sprintf("%02d", $second);
                $theTime = "${paddedHour}:${paddedMin}:${paddedSec}";


        }
        elsif ($timeFormat == 3 ){
                my $paddedMonth = sprintf("%02d", $monthss);
                my $paddedDay = sprintf("%02d", $dayOfMonth);
                $theTime = "${year}-${paddedMonth}-${paddedDay}";

        }
        elsif ($timeFormat == 4 ){
                my $paddedMonth = sprintf("%02d", $monthss);
                my $paddedDay = sprintf("%02d", $dayOfMonth);
                $theTime = "${paddedMonth}/${paddedDay}";

        }
        return $theTime;

Saturday, August 13, 2011

Unlock Files and Folders

I recently had problem with Unlocker because Avast antivirus keeps on deleting the unlocker executable and treating it as W32:Malware-gen. I did a full scan and didn't find any virus on my machine. I still don't know if this is a false positive or a legit detection. Maybe on my next avast virus definition update i'll see some changes.

I'm sure that some of us has Unlocker installed and is actively using this whenever there's a write protect/file in use error. I found other tools that can be use as an alternative if in case your antivirus starts to hate your installed Unlocker.


File & Folder Unlocker

LockHunter

FileASSASSIN

Tuesday, August 31, 2010

Windows Run command

Sometimes we feel like doing stuff in Windows using our laptop or pc but a bit lazy to use the mouse . Bringing up the Remote desktop will require you to navigate the Start Menu , then go to Programs and then Accessories. The simplest way to do this is by using the Window Run command (Windows KEY + R), then key-in mstsc and click OK.

I read some additonal run command that may be of great help. See more here.

Tuesday, August 18, 2009

USB port work around

Here's how to deal with those manipulative Active Directory admins that keeps on disabling your USB ports.
You can try this to sneak out, try enable and disable the ports after completing some unrelated office work but quite important.
You can always leave this enable (meaning creating a vbs to every system start)if you really want to break the rule but be careful not to get caught, admins have
a work around as well to disable this from the BIOS side and that would be dead end.


To re-enable USB port

Click Start
Click Run
Enter regedit in the Open box and click OK
Navigate to the following registry key:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\UsbStor
Select Start, then righ click.
Select Modify
In the Value data box, type 3, click Hexadecimal
Then close Registry Editor


And here's how to get it back and not to get caught.

To disable USB port

Click Start
Click Run
Enter regedit in the Open box and click OK
Navigate to the following registry key:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\UsbStor
Select Start, then righ click.
Select Modify
In the Value data box, type 4, click Hexadecimal
Then close Registry Editor




Cheers!! Know the rules, then break some!

Monday, June 15, 2009

[Windows] - View shared folders through command line

This would enable the user to view shared folders from their Windows (XP and above) workstation/servers through command line. This can be of help if you're trying to look for some loose or forgotten shared folder location.


WMIC - Windows Management Instrument command.

Click Start
Click Run
Enter cmd in the opened input box and click OK
From the command line type, wmic share get name,path

Tuesday, April 7, 2009

Latest Vulnerability in Microsoft PowerPoint

If exploited, this latest vulnerability would enable the attacker to gain the same user rights as the local user.

read more of this post here.

Microsoft Security Advisory, can be read here.