Monday, November 21, 2016

Remove the line numbers in source code using notepad++


A sample code with line numbers:

01<!DOCTYPE html>
02<html>
03<head>
04 <meta http-equiv="X-UA-Compatible" content="IE=edge">
05 <meta charset="utf-8">
06 <title>Hello App!</title>
07 <script>


To remove the numbers in each line of code, do the following:


  • Copy the code into notepad++
  • Type Ctrl + H
  • Under Search Mode choose Regular Expression.
  • In Find What :Enter ^\d+
  • Leave the Replace with: as blank
  • Now click Replace All


Now the code looks like:


<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta charset="utf-8">
<title>Hello App!</title>
<script>



Saturday, November 12, 2016

It ebooks Rest Api

Itebooks which is one of the popular sources for programming books.

They have exposed couple of REST Apis as GET request.

One of it is send request to it based on the book id.

Below is the code to get the details of the book:

import json
import urllib
response = urllib.urlopen('http://it-ebooks-api.info/v1/book/2279690981')
json_response = json.loads(response.read())
print json_response
view raw ItebooksRest.py hosted with ❤ by GitHub

Monday, November 7, 2016

Huffman Decode

Huffman coding assigns code words to fixed length characters based on frequency.
More frequent characters are given shorter code words and less frequent with longer.


Java program for a given string that has encoded and a tree structure,  decode the characters .
public void decode(String S ,Node root)
{
String decode = "";
Node temp = root;
for(char c: S.toCharArray()){
//System.out.println(c);
if(c=='1') {
if(temp.right.data != 0){
decode = decode + temp.right.data;
temp = root;
}
else{
temp = temp.right;
}
}
else if(c=='0'){
if(temp.left.data != 0){
decode = decode + temp.left.data;
temp = root;
}
else{
temp = temp.left;
}
}
}
System.out.println(decode);
}
view raw huffman.java hosted with ❤ by GitHub

To find Nth maximum salary

To find nth max salary using correlated query
SELECT * /*This is the outer query part */
FROM Employee Emp1
WHERE (N-1) = ( /* Subquery starts here */
SELECT COUNT(DISTINCT(Emp2.Salary))
FROM Employee Emp2
WHERE Emp2.Salary > Emp1.Salary)
view raw maxSal.sql hosted with ❤ by GitHub