Wednesday, 6 September 2017

Remove the first 3 chars from file - Rename the files in terminal


for file in *mp3; do mv "$file" "${file:3}"; done


=====================

This tutorial describes how to batch rename files of a specific file type by removing X number of leading characters from the beginning of the filename.

A. Background:

Sometimes I get a CD or DVD containing a lot of files of a particular type that are named to a particular convention, which I need to take a copy of. Once I've copied it locally, I want to rename the files to remove the convention. For example, say I borrow a music CD from a friend, which he has burnt himself. He has named the track listing according to his own convention thus:
  1. 001 - Track 1.mp3
  2. 002 - Track 2.mp3
  3. ...
  4. 100 - Track 100.mp3
I would like to rename these files so that the track identifier (the number part) is removed along with the spaces and the hyphen character such that I am left with just the track name. So, for example:
001 - Track 1.mp3
becomes
Track 1.mp3
Obviously I could rename these manually, which if I only had a few files to rename would be fine. However, in the example above I have 100 files to rename and doing this manually would be time consuming and tedious. So I will now show you a nice little renaming routine, which you can adapt, that will handle this for us.

B. The How To:

  1. Copy your files into one directory. The files, as I mentioned, should all be of one file type, for this to work.
  2. Open a Terminal window.
  3. At the prompt type:
cd <path_to_directory_containing_files> && for file in *<file_type> do mv "$file" "${file:<number_of_leading_characters_to_remove>}"; done

Where:

<path_to_directory_containing_files> is the path to the directory you copied you files to.

<file_type> is the file type of the files in the directory without the dot (so instead of *.mp3, simply enter *mp3).

<number_of_leading_characters_to_remove> is the number of characters you wish to remove from the front of the file name.

C. Example:

In the earlier example the filenames were prefixed with a three digit track identifier such as '001'. This was followed by a space, a hypen and space (' - ') and finally the track name ('Track 1.mp3', for example).
Let us assume, that for the 100 files in the example we want to remove the three digit identifier, the space, the hypen and the last space before the track name so that we are only left with the track name and file type, e.g:
001 - Track 1.mp3
becomes
Track 1.mp3
I therefore need to remove the first 6 characters from the beginning of each filename: 3 characters for the track identifier + 1 space + 1 hyphen + 1 more space.
Let us also assume that I have copied the 100 files into a folder on my Desktop called 'Music'.
So, in order to achieve the bulk rename I would type in the Terminal:
cd /home/me/Desktop/Music/ && for file in *mp3; do mv "$file" "${file:6}"; done
You should now have all 100 files renamed to your requirements.

D. Further Notes for Adapting This:

  1. file is simply a variable and can have any name you like. Some people use i but I chose file for the example as we were dealing with files.
  2. Naturally you can use any file type. I used mp3 files for the example as people are generally familiar with it. Remember, don't include the '.' when referencing your file type i.e. *<file_type> not *.<file_type>
  3. You can remove as many characters as you like. The number of characters to remove is not 0 based, it is 1 based. So, if you want to remove 6 characters like in our example you would not enter "${file:5}" (0, 1, 2, 3, 4, 5) but would instead enter "${file:6}" (1, 2, 3, 4, 5, 6) to achieve the correct result.
  4. for file in *mp3; do mv "$file" "${file:6}"; done is actually a small loop.
  5. I'm sure this can be modified in many other ways too, for example, to perhaps remove trailing characters. I've not needed to do that yet so haven't investigated that just now. If I need to do that, I will write another tutorial.

Friday, 1 September 2017

Windows - resmon - Resuorce Monitor

run resmon
In Network Tab click on listening port, here we could see all the ports which is currently being used.


============================================


Kill windows service PID


C:\>Taskkill /PID 26356 /F

Key Shortcut for Eclipse Imports


Some useful shortcuts. You're looking for the 1st one...
  1. Ctrl + Shift + O : Organize imports
  2. Ctrl + Shift + T : Open Type
  3. Ctrl + Shift + F4 : Close all Opened Editors
  4. Ctrl + O : Open declarations
  5. Ctrl + E : Open Editor
  6. Ctrl + / : Line Comment
  7. Alt + Shift + R : Rename
  8. Alt + Shift + L : extract to Local Variable
  9. Alt + Shift + M : extract to Method
  10. F3 : Open Declaration
Source Here

Thursday, 31 August 2017

Tomcat - Change tomcat accessing port

           Change tomcat accessing port


  • Goto tomcat>conf folder
  • Edit server.xml
  • Search "Connector port"
  • Replace "8080" by your port number
  • Restart tomcat server.
You are done!.


=====================================

Navigate to /tomcat-root/conf folder. Within you will find the server.xml file.
Open the server.xml in your preferred editor. Search the below similar statement (not exactly same as below will differ)
    <Connector port="8080" protocol="HTTP/1.1" 
           connectionTimeout="20000" 
           redirectPort="8443" />
Going to give the port number to 9090
     <Connector port="9090" protocol="HTTP/1.1" 
           connectionTimeout="20000" 
           redirectPort="8443" />
Save the file and restart the server. Now the tomcat will listen at port 9090


===================================================================

Several ports (8005, 8080, 8009) required by Tomcat Server at localhost are already in use



If you are running on windows try this in the command line prompt:
netstat -ano
This will show all ports in use and the process id PID # of the process that is using that port. Then Ctrl+Alt+Del and open Task Manager to see which process is that.
You can then choose either to close/stop it or configure your server to use another port. To check if the new choosen port (let's say 8010) is available do this:
netstat -ano | grep 8010
If it does not return any lines then you are fine.
To change the port go to the Server view, open server.xml and change the port there. Mine has this entry:
Connector port="8010" protocol="AJP/1.3" redirectPort="8443"

========================================================================

Port 80 is being used by SYSTEM (PID 4), what is that?


check for services running on 

netstat -o -n -a |findstr 0.0.:8080

--------------------------------
Also, try stopping "SQL Server Reporting Services (MSSQLSERVER)", that apparently defaults to 80. I did that and port 80 freed up. PID identified the culprit as "System", but apparently that System can mean multiple things.
--------------------------------------------------------

There are many services, which can listen port 80 on windows.
Luckily you can detect and stop them all running simple console command:
NET stop HTTP

Disable Unnecessary System Services Locally

  1. Open the Computer Management interface.
  2. In the console tree, expand Services and Applications and select Services.
  3. From the right-hand pane, select a service to disable. Right-click on the selected service and select Properties.
  4. The Properties dialog box for the selected services will appear. From the Startup type: drop down menu, select Disabled.
    Dd277425.w2kab190(en-us,TechNet.10).gif
  5. Under Service status: click on the Stop button.
  6. Click the OK button.

===================================================


  1. Select “Default Web Site” from the left tree in IIS manager.
  2. Click Bindings from the right sidebar to open a dialog box.
  3. Select “http” record from the grid and hit Edit.
  4. Enter your choice of port number in “Port” Text box and hit OK.





==============================

Tuesday, 29 August 2017

C++ Basics- oops concepts

                                  c++


   To support the principles of object-oriented programming, all OOP languages
have three traits in common:

1) encapsulation,
2) polymorphism,
3) inheritance.



1)Encapsulation :=>

 Encapsulation is the mechanism that binds together code and the data it manipulates, and keeps both safe from outside interference and misuse.


  => When code and data are linked together in this fashion, an object is
created


=> Each  time you define a new type of object, you are creating a new data type


2) Polymorphism=>

    which is characterized by the phrase "one interface, multiple methods."

   In simple terms, polymorphism is the  attribute that allows one interface to control access to a general class of actions.

=>       Polymorphism helps reduce complexity by allowing the same interface to be used to access a general class of actions. It is the compiler's job to select the specific action
(i.e., method)


3)  Inheritance  =>


Inheritance is the process by which one object can acquire the properties of another object.
This is important because it supports the concept of classification.






********************************************************************

iostream


=>  there is no .h extension to the iostream. The reason is that <iostream>      is one of the new-style headers defined by Standard C++.

=>  New-style headers do not use the .h extension.

******************************************************
using namespace std;


=>    This tells the compiler to use the std namespace.

=>    Namespaces are a recent addition  to C++.

=>   A namespace creates a declarative region in which various program elements
can be placed.

=>  Namespaces help in the organization of large programs.


=>   The using  statement informs the compiler that you want to use the std namespace.

=> This is the  namespace in which the entire Standard C++ library is declared. By using the std  namespace you simplify access to the standard library.


**************************************************************************
Function overloading =>



 One way that C++ achieves polymorphism is through the use of function overloading.

In C++, two or more functions can share the same name as long as their parameter
declarations are different. In this situation, the functions that share the same name are said to be overloaded, and the process is referred to as function overloading.


************************************************************


Operator Overloading  =>

in C++, it is possible to use the << and >> operators to perform console I/O operations.

They can perform these extra operations because in the <iostream> header, these
operators are overloaded.

  When an operator is overloaded, it takes on an additional meaning relative to a certain class. However, it still retains all of its old meanings.



******************************************************************88

Constructors and Destructors



=>  C++ allows objects to initialize themselves when they are created.

=>  This automatic initialization is performed through the use of a constructor function.


=> A constructor function is a special function that is a member of a class and has the same name as that class.


=> most constructor functions will not output or input anything. They will simply perform various initializations.




 Destructor::::::




=>    An object's constructor is automatically called when the object is created. This means that it is called when the object's declaration is executed.



===>  The complement of the constructor is the destructor

=>   in many circumstances, an object will need to perform some action or actions when it is destroyed.


=> Local objects are created when their block is entered, and destroyed when the block is left. Global
objects are destroyed when the program terminates.

=> When an object is destroyed, its destructor (if it has one) is automatically called.


=>
                                                 . There are many reasons why a
destructor function may be needed. For example, an object may need to deallocate
memory that it had previously allocated or it may need to close a file that it had
opened. In C++, it is the destructor function that handles deactivation events. The
destructor has the same name as the constructor, but it is preceded by a ~.



************************************************************************

Linux Basics

UNIX : unix operating system was developed around 1960, at AT & T labs by dennis      ritch, after few years it made commerical

    ==>  then Richard stallmen decided to develop a new open source operating
        system, he is developer from MIT. he started a project GNU . which
        similar to whatever the facilites that offering by the UNIX os , they
       made all the required modules except the kernal,

 



LINUX  :   LInus Torvaldo , student form  elisinky university (finland) ,
          started a hobby of creating his own kernel version, In 25 Aug, 1991,
        he developed a terminal emulator (based on  Minix,it's just like unix
        terminal ,which used in universities for explanation purpose. ) he
         followed the architecture of the minix but he didn't used any code from      that) then  he posted a email in the minix user groups for feedback and
      suggesition, he annouced it's name as  "freax" => free, freak, x
      released 0.99 version of kernal , then some named it as LINUX kernal, then      Richard stallman used this kernal to complete his remaining project.
      then finally developed a free Open source Operating system under the
     (GPL) General Public License.... means anyone can use this freely ,
     and distribute to the other,modify also.


OS =>
        it's complicated/sophasticated a software ,
        which manages all the softwares and hardware resources.
   
    =>software which manages all the other resources...


Kernal ==>
           user space can't directly communicate with the hardware devices,
           only kernal have the privillage to communicate with the hardware
           components.
           we request the kernal with system calls..  kernal sends interrupts to           the hardware components to communicate .

       ==>  kernal is core of os.


shell==>

        ->   it is command interpretor
        ->   a software/program which acts as interface b/w the user and the
             kernel.


Library:=>
          It's binary file , a file which contains all the definitions of the
            functions , they are precompiled.
       
         => library files are created from the binary files.

            2 types of library files

     1)  Static :
                     extension:   libc.a


     2)  Dynamic :

                    extensions:     libc.so
                                  & libc.dll

  =>static linking:
                   
                      The address of the called function known to the main
     function at the time of compile time .this kind of linking is called
    static linking.

                    =>with static linking file size will be more becuase
                   it doesn't contain any seperate dll files so all files
                  are linked as a group so size of excutable file will be more.

                   => but one useful thing with static linking is ..executable                   files are portable (no dependency).

                 =>  statically linking will consume more memory. that's why
                 developers go for dynamic linking.

  =>Dynamic  linking:

                     The address of the called function known to the main
     function at the time of Run time .this kind of linking is called
    dynamic  linking.

                   => default linking is dynamic linking.

                   => in dynamic linking executable file size will be reduced


   ex:  printf is linked to the main function in dynamic linking.

=>   printf present in both  static libray & dynamic library
               
                   i)  libc.so
                   ii)  libc.a



==> Load time linking:
                      when executable file brought into memory for processing
                    at that time all the library files(a.out depends on)
                    are brought into memory



==> Run time linking :

                      link if necessary, otherwise don't link.


Commands: =>


$ cc -c 1.c    =>  compilation without linking

$ nm 1.o      =>  to know whether the fn defined or undefined

$ ldd a.out    =>  if it is dynamically linked then it
                   displays used shared library functions.

                    =>  list the libraries of a.out which depends on.

$ cc -static 1.o 2.o  =>  to link statically

$ file a.out   =>     to know whether it is dynamically linked or
                                            Statically  linked


**********   creation of library *********************************

ex:


        $ cc -c -fpic sum.c   (compilation without linking creates .o objective                                file)
        $ cc -c -fpic mul.c


        $ cc -shared -o libDynamic.so sum.o mul.o
     
        $ ar rcs libstatic.a  sum.o mul.o




  ********************    Process & Process management: **************

Process: =>
             application under execution is called process.


          ==> actually cpu excutes one process at a time.
         

       
Job concurrency/ Multi processing : =>


             => excuting multiple process at simultaneously/concurrently                         is called  multi processing.

             ==> this type of management is called cpu management.


cpu management =>

             =>  it's one of the resource manager.

             =>   execute all the process that are demanding the cpu in
                 efficient manner is called cpu management.

 efficient way means::
       
               ->  fair cpu sharing
               ->  response time
               ->  starvation       : demanding cpu but cpu not given
                                    :-> less starvation time is better
                                    -> we can minimize by Round dropping manner


               ->  throuput
               ->  turn around time : time gap b/w process loading and
                                      release(terminating).
               ->  wait time should be better



states of process::=>

           
   -> Ready/Runnable : the job needs nothing but cpu

   -> Delay/sleep    : in delay state it's not demand the cpu for the given
                       amount of delay time.

   -> suspended      : the job is interrupted from excution by interrupts, will
                       excute if resumed.

   -> wait/pending   :  the job is in waiting state
                     
                       -> the job is pending for i/o operations
                       -> event completion


***********   PCB (process control block) ************************


-> those many process/jobs, those many pcb's present

-> life of pcb  is equal to life of job.

->  cpu manager creates pcb's

-> when job is exited then pcb is released.

-> for each process there is unique process id present.

-> the switching of pcb is called   -> pcb switching
                                   
                                    -> process switching
                                   
                                    -> context switching



************************   bound ************************************

cpu bound ==>

             if a process in it's life time ,  if it present most of the time

            ready queue is called cpu bound.



i/o bound ==>
               if a process in it's life time, if it not demand cpu then

                it is called i/o bound.




->  for process manager  i/o bounds jobs are better....



************************************************************************


  prototypes  =>


1.         pid_t  fork(void);

2.         pid_t wait(int *status);

3.         pid_t waitpid(pid_t pid,int *status , int options);

4.         int  kill(pid_t pid,int sig_num);

5.        sighandler_t  signal(int signum, sighandler_t handler);

6.         int system(const char *command);

7.        int  getrlimit( int resource, struct rlimit *rlim);

8.         int setrlimit(int resource, const struct rlimit *rlim);

9.         int execl( const char *path, const char *arg,...);

10         int execlp(const char *path, const char *arg,...);

11     int execle(const char *path , const char *arg,... , char *const envp[]);

12        int  execv(const char *path , char *const argv[]);

13         int execvp(const char *file , char *const argv[]);

14    int  execve(const char *filename , char *const argv[],char *const envp[]);