Sharing! What gained.

Showing posts with label Programming Languages. Show all posts
Showing posts with label Programming Languages. Show all posts

Oct 12, 2016

Regular Expression and Applications


Regular Expression is an expression which is used for defining a language, this definition look very simple but whole world reside this definition. Some core functionality which are provided by Regular Expression or we can say it’s implementation are as follow:

  1. String matching
  2. Search
  3. Replace

In Programming Language

It was first basic implemented in SNOBOL language in earlies 1960s. Later on enhanced version of RE was implemented in text editor for example in grep and ed, but the new boost was added in the field of regular expression when more complex engine and complicated regular expression were introduced in Perl which was originally derived from work of Henry Spencer in 1986 who later implemented his work in Tcl language which used NFA/DFA implementation for Regular Expression implementation which was highly praised.

  1. Perl - Available in it syntax
  2. Python
    1. Import re
  3. Java
    1. import java.util.regex
  4. C++ 
    1. #include<regex> was introduce in C++ in C11
  5. PHP 
    1. PCRE library (Perl Compatible) 

And today regular expression in part of standard library, hence it is available in all languages available today eg. R, Rust, ECMAScript, Python, Go, C# and etc. 

Today, Perl syntax for regular expression is followed in Java, JavaScript, PHP, Python, Ruby, Microsoft's .NET Framework, and XML Schema.

Applications

Regular have ignited further computer science field for example Natural Language Processing, Data Mining, Compiler, Automata and etc.

  1. Validation of registration form.
    1. Some default implementation available in HTML5 are email, number, url, tel (telephone), text for type attribute in HTML5.

  2. Apache Web Server, Some of it uses in created wild card domain used when created sub domain in server side. 

    1. Sub domain: *.example.com, This will redirect all sub domain queries to main script file of example.com. This approach is used in all shared hosting provider for example wordpress.com, yola.com, weebly.com and etc.
    2. Redirect Rule: In some cases we know want some core file to not get public so we hide that page using Redirect Rule which redirect based on specific query for example we want to hide all cache folder,  ini and file then query will be something like cache/*, *.ini
  3. Google Search Engine, It provied some special command in search engine, such as:
    1. HTML Tutorial  – w3schools.com” this will bring all result that don’t contain w3schools in it page.
    2. a * saved is a * earned” * can be used in place of unknown words.
  4. Text editor, We have built-in regular expression added earlier in Ed editor and in todays century it is available in Notepad++, Sublime Text, Atom, Visual Studio.
    1. Using in Notepad++, Check Regular expression option and write your expression in search box.
  5. grep, When there wasn’t GUI thing around and command line was the only interface, grep was introduced in 1974  to string matching using regular expression and it is still king for string matching in command line and for its easy syntax.
example.txt file contains name of fruits.

Where have I used RE?

  1. To minify HTML, JS and CSS. I’ve use Notepad++ RE functionality to replace newlines and repeated spaces.
  2. While configuring Web server and defining Rewrite rule in .htaccess files.
  3. For validating input in site for valid email, username, password.
  4. Used in one of my project for tokenizing SQL in htmSQL where we can parse HTML using SQL.
  5. Sometime use negative sign in Google search engine.
  6. For defining routes in MVC framework such as ExpressJS, Laravel, Django.
  7. Web scraping; when extracting product name and product price from a page.
  8. SQL LIKE operator eg. “%input%”
  9. Last not the least, In Automata course exams for defining RE from given description definition.

Hacking

  1. As RE syntax was enhanced: recursive and sub expression functionality was added, which allow us to write more complex and complicated expression but It can be exploited by analyst by inputting such string which take so long to process that server crashes (Regular expression Denial of Service). 
  2. Regular Expression, to validate whether your term is search term or url, Google Chrome have RE written for that, which was exploited earlier this year which make phishing attack easier on Firefox and Chrome. (LINK)



Jul 25, 2015

Getting Started with Boost C++ Library




Boost library is a C++ library which contain 80+ library to play with. Boost library is licensed under Boost Software License which allows to use it in free and propietary software. Some of the Boost feature have been migrated to Standard C++ library and some are in process of migrations. It is portable and support almost every c++ compiler.

Jul 23, 2015

Best Place to learn C++




Here are the some source which I find very usefull for learning C++

Cplusplus.com

To start learning new programming I always look for kickstart skipping history jumping Hello World program and continue to learn paradign of the language. For starting learning C++ I found cplusplus the best source for starting and they have a great active commnuity in their forum for solving program issues.

Jul 20, 2015

C++ Shadowing


Shadowing in common English means the Shade of one thing over the other.  Shadowing is the concept of OOP  which allow the programmer to reuse the same Datatypes in different classes or in other words its the overriding of the Datatypes,Its advantage is that we can use less memory and take more work from Datatypes .


Jul 13, 2015

C++ Friends Function


One of the features of OOP is know as friends function ,I explain this to my students by giving the example ,That lets suppose that you have a friend to whom to tell your are private stuff like secrets and that friend does not belong to your family like he is your friend but not member of your family and you tell him whats happening in your personal life similarly friend function in not a member function of class but have the capability to use the private Datatypes members of class outside of the class such a function is known as friends function .It will be further cleared by looking at this example.


C++ Constructor Overloading


Construction overloading is no different than simple overloading the function they are all most the same ,Lets follow the process first made simple constructor with no argument,Then made another constructor with 2 or more argument according to your requirement and as we know that for each object that we make in main body there is constructor called separately so now when we want to call 2 argument or more argument constructor that we have declared in class we will declare the object then after the object we will made the round bracket i.e () and we will enter the values that we want to pass with the following example it will be further cleared.

Jul 11, 2015

C++ Overloading


Overloading in general English means to put extra burden or weight on something , Overloading in C++ means to provide user the facility of  calling the function with same signature but different amount of parameters with same calling function.The parameters that you will pass must have same Datatypes as that of function the declared parameters will be further cleared by this simple example

Jul 10, 2015

C++ Combination


Combination as a common English word means to combining something, In OOP combination means linking of two classes or combining two classes in such a way that the public features of one class can be called by another class ,People use to mix up between the concept of Inheritance and Combination but they are two different things in combination, when we will link two or more classes the object that we will use for call will be of final declared class in hierarchy of declared classes.

C++ Constructor and Destructor


In OOPS constructor and destructor play very vital role , Now if we deal them as common English words ,Constructor means to construct something and destructor means to destroy something.

Constructor

Inside a class we cannot assign values to variables directly for that we made a constructor ,

Jul 9, 2015

C++ Modifiers and Accessors


Modifier and Accessors, In common English are refer to modify something from its old state to new state and accessor means to give a person  access to something .Now in OOP (Object Oriented Programming) as we all know that we cannot use private members outside of class  this allow the user to use the private Datatype outside of class i.e in Main function(Main Body) of program indirectly.In a way that we can modify the values of those Private Datatypes outside of the class and we can output those values of Private Datatype out of the class.