eTechtips

Tech Tips and Insights

  • Perl: Missing ParserDetails.ini

    I have some scripts that were giving me the following message:
    could not find ParserDetails.ini in /usr/lib/perl5/vendor_perl/5.10/XML/SAX

    The way that I worked around this message was to create the ParserDetails.ini file in the /usr/lib/perl5/vendor_perl/5.10/XML/SAX directory with the following contents.

    [XML::SAX::PurePerl]
    http://xml.org/sax/features/namespaces = 1
    
    2 Comments
  • Edit the hosts file

    If you have every wanted to set certain IP addresses in your network without depending on a nameserver, you can edit the ‘hosts’ file in your operating system.  This can be done to stop access to any inappropriate sites as well.

    The hosts file in Windows is:

    %systemroot%System32driversetchosts

    This is typically  in:

    c:windowsSystem32driversetchosts

    On linux this file is:

    /etc/hosts

    The common layout of the file is

    <IP address> hostname [hostname]

    So if would look something like this:

    127.0.0.1  localhost
    192.168.2.222 homeserver homeserver.mydomain.net
    127.0.0.1 badlocation
    

    Remember that these lookups happen before looking to a nameserver. So this will override any name lookup. So if you happen to do this on a laptop that you regularly use outside of your home network, make sure that you do not override an address that might be needed when you are not at home.

    You will need appropriate privileges to access the file. So you may have to be root or use sudo on Linux and you may have to open an editor as administrator before opening the file on Windows.

    0 Comments
  • Toggle wrap in VI

    This turns off word wrap in the vi window

    :set nowrap

    to enable it again:

    :set wrap

    0 Comments
  • Lenovo Synaptics touchpad issue

    I have a Lenovo Thinkpad T410 running Windows 7 64-bit and the touchpad stops working after about 10 minutes or so and required a reboot and removal of devices to get it to work again.

    I found that if you remove the Lenovo version of the drivers and go to the Synaptics website to download them, then you can have the full functionality of the touchpad back.

    Synaptics Driver Download site

    0 Comments
  • HTML: How to use an external StyleSheet

    There are two ways to include an external stylesheet.  Using a <link> tag in the <head> section of your web page or using the @import tag in a <style> section.  The @import tag can also be placed inside a CSS file to include other CSS files.

    Example of an externally linked stylesheet named anyname.css

    <head>
    
    <link rel="stylesheet" type="text/css" name="anyname.css" href="url" media="all">
    
    </head>
    

    The name field is the filename and can be set to any path that is available to your Web Server. The media type can be specified in the link tag.

    An example of a @import statement to include a CSS file:

    <style>
    
    @import('anyfile.css');
    
    </style>
    

    You can also specify the type of stylesheet with the @import statement:

    @import('anyfile') screen;
    
    @import('anyfile') print;
    

    The @import statement is not understood by many older browsers, Netscape 4 ignores them completely and Internet Explorer 4 requires you to use parenthesis, even though they are optional.  Luckily, there should be very few people still using these browsers and this is a useful technique to not include features that would not work in those browsers.

    The @import directives must be the first items in your CSS. Even comments should not appear before these statements.

    Internet Explorer versions 4-7 have the limitation that they do not like specifying the type on the @import line.  I have not researched if this is the case with versions 8 and above.

    0 Comments
  • Html: how to use an internal stylesheet

    In order to use an internal stylesheet, place the following in the <head> section of your html document.

    <style type="text/css" media="all">
    
    <!--
    
    Place your css here
    
    -->
    
    </style>

    The <!– –> (xml style comment) is so that older browsers, though very unlikely, will not get confused by the CSS code within the page.

    The media=”all” entry tells the rendering engine which style sheets to use, in this case “all” means to use it for all rendering engines.

    0 Comments
  • Apple iTunes doesn’t allow purchased apps to go back to device

    I have been frustrated by the crappy Authorization scheme on the iTunes store for quite some time. Purchased apps tell me that I am not authorized to use them and will not restore any apps to my device.

    I already had to restore from a backup because the phone froze in a screen backlight issue and now cannot get back many of my apps to the device.

    This is making me want to get rid of my iPhone and go to a device that is not so locked down. I should be able to put apps that I got legitimately back to my own device.

    0 Comments
  • Python: AttributeError: ‘getopt’ module has no attribute ‘GetoptError’

    So I was figuring out how to parse command line arguments with python and using the getopt module with the following code

    
    #!/usr/bin/env python
    import sys
    import getopt
    
    def main(argv):
       infile = "some.xml"
       try:
          opts,args = getopt.getopt(argv,"hi:d",["help","infile="]
       except getopt.GetoptError:
          usage()
          sys.exit(2)
    
    if __name__ == "__main__":
        main(sys.argv[1:])
    

    And I was getting the following error:

    AttributeError: ‘getopt’ module has no attribute ‘GetoptError’

    So my first problem was that I had named my script getopt.py and after renaming the script, I got the same error. Well you now need to remove the getopt.pyc file that was generated from your earlier running of the poorly named script.

    4 Comments
  • How to address perl arguments

    If you are using perl, you may find it necessary to take some command line arguments to your scripts.  When that time comes, there is a very handy variable ARGV that contains the passed in arguments.

    To get the total number of arguments passed into the script you will need to use the following:

    $totcommandargs = #$ARGV + 1

    is equal to the number of arguments passed in to the Perl script.

    Note: you need to add one to the count to get the correct number of variables.

    To address the variables you use the following to address the first argument: $ARGV[0]

    will address the first argument

    Since arrays are addressed by n-1, to get the first element you use 0 {zero}, for the second 1, for the third {2}, and so on.

    $0 will give the name of the currently executing script.

    
    #!/usr/bin/perl
    
    $argcount =  $#ARGV +1;
    print "The script $0 has $argcount argumentsn";
    
    for( $i = 0; $i < $argcount;$i++)
    {
    print $ARGV[$i] . "n";
    }
    
    
    0 Comments
  • Bash: Command line parser for Multiple arguments to bash

    I regularly have to write scripts into different environments and when I am wrapping a build system, I typically use a Bash script to do it. I often have to pass a set of arguments to the underlying commands in my scripts as well. I have found that the %* argument is the easiest way to take those arguments.

    The %* takes the arguements and passes them along. The %1, %2, %3…and so on are the individual arguments but unless you have a fixed amount of arguments, then you will need to process a variable amount of arguments.

    while [ $#  -gt 1 ]
    do
      case "$1" in
        -a)
          ANALYZE=1
          ;;
        *)
         echo "Invalid option"
         ;;
       esac
       shift
    done
    
    
    0 Comments