Wednesday, 22 January 2014

Batch File Concepts

BATCH FILE:
        

                       These are simple text files containing some lines with commands that get executed in sequence, one after the other. These files have the special extension BAT or CMD.

Files of this type are recognized and executed through an interface (shell) provided by a system file called the command interpreter. In Windows XP/ Vista the command interpreter is the file cmd.exe.

The large assortment of versatile commands available in Windows XP/Vista/7 makes batch files a powerful tool.Constructing a batch file consists of nothing more than opening any text editor like the accessory Notepad, entering some lines containing commands, and saving the file with an extension BAT or CMD.


Basic Commands Are,


@echo off - The purpose of this first command is to turn off this display. The command "echo off" turns off the display for the whole script, except for the "echo off" command itself. The "at" sign "@" in front makes the command apply to itself as well.

Rem - Very often batch files contain lines that start with "Rem". This is a way to enter comments and documentation. The computer ignores anything on a line following Rem.

set /p variable= [string] - "Variable" is the name of the variable that will be assigned to the data that we want the user to input. "String" is the message that the user will see as a prompt. If desired, "string" can be omitted.

Here is an example that asks the user to enter his or her name:

            set /p name= What is wer name?

This will create a variable %name% whose value is whatever the user enters. Note that the user must press the "Enter' key after typing the input.


Conditional branching with "If" statements:

Batch files can make decisions and choose actions that depend on conditions. This type of action makes use of a statement beginning with "If".

The basic meaning of an "If" statement is ,

        If something is true then do an action (otherwise do a different action)

The second part of the statement (in parentheses) is optional.

Otherwise, the system just goes to the next line in the batch file if the first condition isn't met.

The actual syntax is ,
   
        If (condition) (command1) Else (command2) The "Else" part is optional. The form "If not" can also be used to test if a condition is false.

Note that "If" tests for true or false in the Boolean sense.

"If exist" statement:

There is a special "If exist" statement that can be used to test for the existence of a file, followed by a command.

An example would be:

        If exist somefile.ext del somefile.ext

 we can also use a negative existence test:

        if not exist somefile.ext echo no file


"If defined" statement:

Another special case is "if defined ", which is used to test for the existence of a variable.

        For example: if defined somevariable somecommand

This can also be used in the negative form, "if not defined".


When comparing variables that are strings, it may be best to enclose the variable name in quotes.

For example, use:

        if "%1" == somestring somecommand


 Variables are declared and given a value in a single statement using "set".

  The syntax is: set some_variable = some_value




Localizing variables:

The declaration of a variable lasts as long as the present command window is open. If you are using a batch file that does not close its instance of the command window when the batch file terminates, any variables that the batch file declares remain.

If you wish to localize a variable to a particular set of statements, use the "setlocal" and "endlocal" commands. Thus. to confine a variable declaration to a particular block of code, use:....


                setlocal
           
                set some_variable = some_value

                ...some statements

                endlocal

                ...

C PROGRAMMING TRICKS

C Programming Tricks:

1.

Always try to compare like

if ( 0 == i )

rather than

if ( i == 0)

In this way you can catch error for unintended assignments like

if ( 0 = i) .


2.

Dont use strlen in a loop condition:

The strlen function is expensive. For every call it must loop over every character in the input string until a nul terminator is found. Therefore, it is very unwise to call it more often than needed. This is bad code:

for ( int ix = 0; ix < strlen(a_str); ix++)
{
     a_str[ix] = tolower( (unsigned char) a_str[ix] );
}


Lets consider a string 1000 characters in length. strlen will be called 1001 times and loop over 1000 characters each time. That is over one million wasted iterations. If the tolower call and assignment takes the equivalent of 10 iterations we can calculate that the operation takes one hundred times longer than it would if written correctly.

strlen as a loop condition should be replaced with:

for ( int ix = 0; a_str[ix] != '\0'; ix++)
{
     a_str[ix] = tolower( (unsigned char) a_str[ix] );
}


or the slightly less efficient:

int len = strlen(a_str);
for ( int ix = 0; ix < len; ix++)
{
     a_str[ix] = tolower( (unsigned char) a_str[ix] );
}


As well as removing unnecessary strlen calls from loops, we should try to remove any other expensive function calls.

3.

Temporarily swap:

Here's a neat trick to swap two variables without creating a temporary:

void swap(int& a, int& b)
{
   a ^= b;
   b ^= a;
   a ^= b;
}


To check correctness, you only need to know that (a^b)^a = b and (b^a)^b = a.

Tuesday, 10 December 2013

HDMI(High Definition Multimedia Interface)

 

HDMI stands for High Definition Multimedia Interface. A HDMI cable is a single cable that serves as link for audio as well as video applications. For a video recorded in high definition, a standard Audio-video component cable gives an output of 480 pixels per inch. On the other hand, HDMI connectors give at least a 720 pixel/inch output, thus giving a more rich and lively video that can recreate the actual scene with more accuracy. There are similar enhancements in audio side too (2.1 channel sound and above). This means that a single HDMI cable can replace up to 11 analog signal cables not only in aspects like reduced clutter, but in bandwidth, content transmission and presentation quality too. HDMI is constantly worked upon and improved by HDMI Consortium, which also handles certifying HDMI cables.

Friday, 6 December 2013

Wi-Fi SD card and USB drive reader


Wi-Fi SD card and USB drive reader




Elecom is going to release the SD card and USB drive reader MR-WI01BK in early December.

The MR-WI01BK is compatible with Wi-Fi connection (IEEE802.11n/g/b). By setting an SD memory card or USB drive to the reader, you can check data or play music saved in those media wirelessly with your smartphone or tablet. This, in effect, allows you to increase the media available to you beyond the smartphone or tablet’s capacity shortage.

It’s able to be accessed by a maximum of 5 devices at a time so that it makes data share with your friends easier.

21 kinds of media are compatible with the card reader MR-WI01BK (5 more kinds can be compatible if you use a conversion adapter).

Your Next USB Connector Will Be Thinner, Reversible


Usb3


As mobile devices get increasingly slimmer, so too will their corresponding USB connectors. Even better, you won't have to flip the cable when you try to slip it in upside down. Finally.

Development for the next-generation USB connector, called the Type-C, is underway and will be thinner and sleeker than current USB 3.0 cables (pictured above), according to the USB 3.1 Promoter Group, which is made up of industry heavy hitters including Microsoft, Hewlett-Packard and Intel.

To pack the powerful punch of the USB 3.1 standard, which can move data at 10 gigabits per second, into a smaller cable, it will closely resemble the USB 2.0 Micro-B. But it has a few advantages over existing models: Specifically, it's reversible, meaning users no longer need to worry about plug orientation.


The plug design is similar to the Apple's Lightning cables and will take away one of USB's main frustrations. The downside is that the new cables won't work with existing connectors.

The Type-C connector is built on existing USB 3.1 and USB 2.0 technologies and will have scalable power capabilities, meaning it will be able to charge a wide range of gadgets.

“While USB technology is well established as the favored choice for connecting and powering devices, we recognize the need to develop a new connector to meet evolving design trends in terms of size and usability,” said Brad Saunders, USB 3.0 Promoter Group Chairman, in a statement. “The new Type-C connector will fit well with the market’s direction and affords an opportunity to lay a foundation for future versions of USB.”