Sharing! What gained.

Showing posts with label Software. Show all posts
Showing posts with label Software. Show all posts

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)



Dec 5, 2015

Getting Started with Cordova


What is Cordova?

Cordova: a mobile development tool for every platform: Android, iOS, WP, Firefox, Browser, Tizen, BB...

Installation

To start installation of the Cordova
First Download and install NodeJS
To confirm installation the installation open command prompt and type
node –v
Then we have to download Cordova. Cordova CLI is built on JavaScript to download Cordova the best option is to get it using NPM (node package manager).
NPM is installed with Node os you won’t have to download it from somewhere.
Run this command to download Cordova
npm install –g cordova
To confirm the insllation of cordova run this command
cordova –version
or just
cordova
Now at this point you can make an application and test it on browser but For building and running it on Android devices you will have to install Android SDK which have dependencies

  1. Download and install JDK (Java)
  2. Download and install Android SDK
  3. Download and install Apache Ant

After installation we have to add JDK, Android SDK and Apache Ant location to path variables.
Android SDK path are mostly %APPDATA%/Roaming/Android/sdk
%APPDATA%/Roaming/Android/sdk

%APPDATA%/Roaming/Android/sdk/tools

%APPDATA%/Roaming/Android/sdk/platform-tools

(PATH TO APACHE ANT)/bin

(PATH TO JDK)/bin

All these path will need to be set in system enviorment variables.

Setting Enviorment Path

  1. To add these the PATH,
  2. open the Control Panel
  3. click System and Security
  4. click System
  5. click Change settings
  6. click the Advanced tab
  7. click Environment Variables button.
  8. In the list User variables select PATH
  9. Then click the Edit button.
At the end of the field Variable value, add a semicolon followed by the path for every location (SDK, ANT, JDK).

We will have to create some enviorment variable also, which are
ANDROID_HOME = %APPDATA%/Roaming/Android/sdk
JAVA_HOME = (PATH TO JDK)
ANT_HOME = (PATH TO APACHE ANT)
You can add them in Environment variables windows you open previously.
Now to test the working, open command prompt and type
adb
Now we have to install a android platform in Android SDK to do that type android in command prompt and a windows will open which select Android 5 (Level 22) and install.

Creating First Application

Open command prompt
Type
cd Desktop
Then type
cordova create HelloWorld
Then type
cd HelloWorld
cordova platform add browser
To test it on browser, type
cordova serve
To build and run it on Android Device

Running on Android Device

We will have to add platform code to cordova app, Type
cordova platform add android
Then build the application
cordova build android
To check for the connected Android device, Type
adb devices
You will get the list of all connected device.
Note: If It doesn’t work check whether Debugging mode is enable in Android and MTP is disabled or not in phone. Then kill adb server if you didn’t get the device in first attempt
adb kill-server
adb start-server
adb devices
If issue continues here can get help here.

Hopefully you will get the result.
To run on connect device
cordova run android
The application will automaticallty start on the phone and Enjoy!

Adding UI in Application

When writing application, We have JavaScript, HTML and CSS in hand for everything. By default you application will appear as classic html element to add beauty to you would have to CSS, to design every element of application.
There are multiple frameworks available which will handle all these UI related stuff for us.

  1. Ionic Framework (Recommended)
  2. Onsen Framework  

Cordova Online

Everyone want quick start to start developing now there is an amazing codova online IDE available with Build option. Give it a try!

  1. Monaca - IDE + Build (Free)
  2. Build PhoneGap - Build your code online (Free)
  3. Appery - IDE + Build (Paid)
  4. ShoutEm

Using Visual Studio 2015

Instead of going through all these steps you can just get a copy of Visual Studio Community and  check Cordova and Git in Custom options while installing and it will install all these stuff: Java, Android SDK, Apache Ant, Cordova and any dependecies needed to run.

However both these step needs 3-5 hour of your time, downloads 5+ GB of stuff from internet and It take about 30+ GB space in Harddrive. 

Conclusion

I would personally suggest to use Visual Studio 2015 because of it simplicity. However I started working on Cordova through CLI in start of this year when there was no tools like these and best of luck with mobile app development.

Comprehensive Guide on Cordova Installation: https://evothings.com/doc/build/cordova-install-windows.html


Jul 27, 2015

Notepad++: A popular Windows text editor




Normally we found text editor useful for taking note and side work but that is the only case for normal user. While for developer and CS Student text editor are used for coding and modifing source code.  Developer text editor like Notepad++ (Windows), Vim (Linux), Gedit (Linux) and Sublime Text are leading text editor on different platform.