Sharing! What gained.

Jul 30, 2018

Nov 25, 2016

Java and C++ Important Libraries for Speed Programming




In my past 2 year of CS degree, I've participated in different Speed Programming competition with my amazing team. In our first competition, problem was too lengthy to be solved with simple array. We found need for some libraries to get the Speed eg. vector (for linked list like structure and can get interesting with tuple) and string (substring, replace, find...) function. But soon later we find more libraries useful such as HashMap (java) and map (c++). List below are the initial libraries we include in every competition. 

Java Libraries

  • StringBuilder
  • Scanner
  • File
  • ArrayList
  • Collection eg sort
  • HashMap
  • String
  • Math eg rand
  • LinkedList
  • Stack
  • Queue
  • DecimalFormat
  • BigInteger
  • BitSet

Some time, needed for float precision.
  • System.out.printf()

C++ Libraries

  • cstdlib
  • fstream
  • vector.h
  • cstring
  • cmath
  • algorithm
  • map.h
  • tuple.h
  • bitset
  • regex

Best of luck for competition.

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)



Feb 1, 2016

Switch Case or Select Case


Switch Case Or Select Case 

Switch case or select case are the same thing they some how work like conditional statements but in this several bodies of code are written and each body is given its own name or here we use word case for name while coding
this technique help coders to solve very complex codes and condition with ease
I have used it in almost every language I have worked on whether it was C++ or C# or JavaScript  using this we can code applications like calculates etc.
For better understanding and making you familiar with this concept I have coded the program of calculator in VB that can perform simple operations like plus,minus,multiplication and division.
Following is the code of calculator using switches in VB



Conditional Statements in Visual Basic


Conditional Statements

It's one of the most important part of any programing language and almost in any good code, Programmer needs it for writing long applications .

Why We Use It?

As the name suggest that it deals with the conditions like "if YOU WORK HARD then YOU PASS THE EXAMS now introduction some conditional signs like
  1. >=for greater than equal to
  2. >   for greater than
  3. <=for less than equal to
  4. <  for less than
  5. =  for equal to  
I have explained with the help of two codes


A very simple example it will take the value from you and then check if the value given by the user is greater than 18 If true then execute the body of If Then
else it will execute the body of ELSE

Another piece of code to clear this concept further

Use Of Basic Mathematical operator in VB


How To Use Basic Mathematical Operator

Use of mathematical operator is very important thing in different projects like building the calculator or for coding some complex mathematical application the basic operator i.e plus,minus,multiplication and division have very important role the use of these operator is exactly the same as any other language all the operations are performed and explained through the following piece of code



Working with strings in Visual Basic


Strings in Visual Basic 

Some basic and simple concepts about the string is explained by the piece of the code below which include .How to deal with strings? and how to use them to make things look fancy?


The above code is explained in simplest way possible