eTechtips

Tech Tips and Insights

  • Viewing many different video formats on Windows

    So I lost my hard drive and went to play some of the videos that I have saved on the system and could no longer play them in Windows Media Player. I needed to download a set of video codecs to play my .vob files. I am using the K-Lite Codec Pack.

    Featured Software

    VIDEO CODECS
    FFDShow MPEG-4
    DivX 8
    Koepi’s XviD Codec
    DScaler MPEG Filters
    Ogg Codecs
    Xvid Video Codec
    Nic’s XviD Codec
    Ligos Indeo Codec
    AUDIO CODECS
    MPEG Layer-3 Codec
    AC3 Filter
    AC-3 ACM Codec
    CoreVorbis Decoder
    LAME DirectShow Filter
    LAME MP3 Encoder
    Monkey’s Audio
    Vorbis Ogg ACM Codec

    This allows me to view the files in other video apps as well.

    0 Comments
  • CSS: Correct order to style links

    This is the correct order to place the styles in your Cascading Style Sheet(CSS) markup to style links.
    The order does matter as out of order markup can lead to lost properties.

    a:link {}
    a:visited {}
    a:focus {}
    a:hover {}
    a:active {}
    
    0 Comments
  • Perl: Open and read file line by line

    I regularly have to process Comma Seperated Value or CSV files, usually for user lists. So the following perl code is a framework for processing a file line by line.

    #!/usr/bin/perl
    use strict;
    my $line;
    
    open(FILEIN, "filename.txt");
    
    while(<FILEIN>)
    {
      chomp();
      $line = $_;
      # Process $line for data
      # Example seperating line by commas: 
      my ($username,$firstname,$lastname,$email) = split(/,/,$line);
    }
    
    close(FILEIN);
    
    0 Comments
  • Perl: Hashes

    Here are some basics about Perl hashes that can be helpful to be used when an you need to associate a label with some value such as for names and telephone numbers or account numbers with amounts owed.

    Create a hash variable.

    my %hashvar;
    

    Create a hash reference

    my $refhash = {};
    

    Add a value to a hash variable.

    $hashvar{'somekey'} = 'someval';
    

    Add a value to a hash reference.

    $hashref->{'somekey'} = 'someotherval';
    

    Access a value in a hash.

    print $hashvar{'somekey'};
    

    Access a value in a hash reference.

    print $hashref->{'somekey}';
    

    Access all Keys in a hash variable.
    foreach my $k (keys(%hashvar))
    {
    print $hashvar{$k};
    }

    Access all Keys in a hash reference.

    foreach my $k (keys(%$hashref))
    {
      print $k . "n";
    }
    

    Access all Keys and values in a hash.

    while (my ($key,$value) = each %hashvar)
    {
      print "Key: " . $key . " has value:" . $value . "n";
    }
    

    Access all Keys and values in a hash.

    while (my ($key,$value) = each %$refhash)
    {
      print "Key: " . $key . " has value:" . $value . "n";
    }
    

    Assigning multiple values to a hash

    %hasvar = (
      'test2' => 'myval',
      'test3' => 'myval3'
    );
    

    Note: This will clear the existing hash.

    Delete a value from a hash

    delete $hashvar{'key1'};
    

    Delete a value from a hash reference.

    delete $hashref->{'key1'};
    
    0 Comments
  • Perl: Arrays

    I use perl arrays in some of my programs, and just started to look at the regular things that I do with these arrays and thought it would be useful to keep a list of frequently used items.

    Create a variable specified as an array.

    my @vararray
    

    Add an item to the beginning of an array

    unshift (@vararray, "File2");
    

    Add an item to the end of an array

    push (@vararray, "File1");
    

    Remove an item from the beginning of an array

    my $var = shift(@array);
    

    Remove an item from the end of an array

    pop(@array)
    

    Clear an array

    @vararray = ();
    

    Address an item in an array

    print $vararray[0] ; 
    

    Get the size of an array

    my $arraysize = @array;
    

    Remove an item based on the index

    delete @vararray[1];
    

    Iterate over an array

    foreach my $var (@vararay)
    {
      print "$var n";
    }
     
    # or 
    my $size = @vararray;
    my $i;
    for ($i = 0 ; $i < @size; $i++)
    {
      print "$vararray[$i]n";
    }
    
    0 Comments
  • Linux System utilization tools

    I was asked about system utilization on Linux systems. I found thesystatset of tools which consist of: sar, sadf, mpstat, iostat, nfsiostat, cifsiostat, pidstat and sa tools.

    I will talk about the iostat tool in this article and follow up about some of the other tools.

    On Ubuntu or debian systems you can install this toolset with:

    sudo apt-get install sysstat

    Then you will have access to the iostat command. The command output from executing with no options is below:

    # iostat
    Linux 2.6.32-33-generic (sumo)  09/01/2011      _i686_  (2 CPU)
    
    avg-cpu:  %user   %nice %system %iowait  %steal   %idle
               0.11    0.00    0.47    0.01    0.00   99.41
    
    Device:            tps   Blk_read/s   Blk_wrtn/s   Blk_read   Blk_wrtn
    sda               0.54         1.85         8.91    1611385    7740024

    This displays the avg-cpu utilization and a device usage list with basic utilization.
    Some options you can use are

    Option Explanation
    -c Display CPU utilization only
    -d Display Device utilization only
    -k Display information in kilobytes
    -m Display information in megabytes
    -t Display time for each report
    -x Display extended statistics

    One more way to use the iostat tool is to specify an interval and count to the command

    iostat -d -x 10 5
    

    This will display the output 5 more times with 10 seconds between each run.

    1 Comment
  • VI: Paste code without formatting

    I happened to be creating a script and found myself trying to copy and past some functions between them. Well my functions
    had some comments and this caused the paste operation into vi to add comments to every line after the first comment.

    So this:

    sub somefunc {
      # input args
      my $var1 = shift;
      my $var2 = shift;
    
      if ($var1 < $var2)
      {
        return $var1;
      }
      else
      {
        return $var2;
      }
    }
    

    Became this:

    sub somefunc {
      # input args
      #my $var1 = shift;
      #my $var2 = shift;
      #
      #if ($var1 < $var2)
      #{
      #  return $var1;
      #}
      #else
      #{
      #  return $var2;
      #}
      #}
    

    This made all my formatting go awry as well, and there were about 4 different functions I was about to cut and past. So I looked into how to make vi accept the text as is without adding formatting. The answer is the paste and nopaste mode.

    To enter the mode to allow pasting without formatting:

    :set paste
    

    To return to regular mode:

    :set nopaste
    

    There are also ways to bind a key to more quickly enter and exit this mode if you are pasting on a regular basis.
    That will be in another article.

    0 Comments
  • Cron Job entry format

    If you ever need to schedule a job regularly on a Unix system, they have a great utility called cron. This will run a job at a regularly scheduled time.

    Here is the format:

    * * * * *  command to be executed
    _ _ _ _ _ 
    | | | | |
    | | | | +--- day of week (0 = Sunday - 6 = Saturday)
    | | | +----- month (1 - 12)
    | | +------- day of month (1-31)
    | +--------- hour(0-23)
    +----------- minute (0-59)
    

    example of a script that runs every day at 7:

    * 7 * * * sendmeupdate
    
    0 Comments
  • How to exit python script

    When I was trying to terminate a python script after a failure, I tried to find the nicest way to exit. The sys.exit() command provided by importing the sys library was what I found.

    The function can take an optional numeric argument, usually in the range of 0-127, and with no argument it returns 0. The return code is passed back to the Operating System.

    import sys
    sys.exit(1)
    

    When exit returns a non-zero value, it is considered an error.

    0 Comments
  • Vi: toggle syntax highlighting

    If you have ever used vi to edit source code, there are occasions where you get on a system that has a very difficult to read color mode. At these times you want the colors to just go away. You can use the following in command mode in vi:

    This will toggle off the syntax highlighting mode.

    :syntax off
    

    This will turn it back on.

    :syntax on
    
    0 Comments