Monday, 31 January 2022

Blockchain quick view

 

# Four types of blockchain technology (BT) networks:

public

private

consortium

hybrid

Thursday, 2 September 2021

Useful questions for CSE Students

Leetcode:

  • https://leetcode.com/problems/bulb-switcher-iii/
  • https://leetcode.com/discuss/interview-question/406031/

Geeks:

  • https://www.geeksforgeeks.org/max-count-of-unique-ratio-fraction-pairs-in-given-arrays/

Create custom Connection Pool class:

  • https://www.baeldung.com/java-connection-pooling (point 4)

Graph DFS on real life scenario: 

Implement the class User, representing a person in a social network, with the following functionalities: 

Each user has a name. Provide a public constructor accepting that name.

 Users can befriend each other with the following method:

 public void befriend(User other)

Friendships are symmetric: a.befriend(b) is equivalent to b.befriend(a).

·       Clients can check whether two users are direct friends or indirect friends (friends of friends), using the following two methods,

public boolean isDirectFriendOf(User other)

public boolean isIndirectFriendOf(User other)

Solution:

Solution

import java.util.*;


public class User {

    private String name;

    private Set<User> friends = new HashSet<>();


    public User(String name) {

        this.name = name;

    }


    public void befriend(User other) {

        friends.add(other);

        other.friends.add(this);

    }


    public boolean isDirectFriendOf(User other) {

        return friends.contains(other);

    }


    //DFS

    public boolean isIndirectFriendOf(User other) {

        Set<User> visited = new HashSet<>();

        Stack<User> stack = new Stack<>();


        stack.push(this);

        while (!stack.isEmpty()) {

            User user = stack.pop();

            if (user.equals(other)) {

                return true;

            }

            if (visited.add(user)) {

                stack.addAll(user.friends);

            }

        }

        return false;

    }


    public static void main(String...args) {

        User a = new User("A"), 

             b = new User("B"),

             c = new User("C"),

             d = new User("D"),

             e = new User("E");


        a.befriend(b);

        a.befriend(c);

        d.befriend(c);

        e.befriend(a);


        System.out.println(b.isDirectFriendOf(c));

        System.out.println(b.isIndirectFriendOf(c));

        System.out.println(b.isIndirectFriendOf(d));

        System.out.println(b.isIndirectFriendOf(e));

    }

}




Thursday, 4 March 2021

Useful Commands

 Very useful commands:

mvn dependency:tree -Dverbose > dependencyGraph.txt

 

Thursday, 3 September 2020

Attention ALL PROGRAMMERS

Read this article if your application deals with usernames: 

https://www.kalzumeus.com/2010/06/17/falsehoods-programmers-believe-about-names/


Read this article if your application deals with time on computer:

https://infiniteundo.com/post/25326999628/falsehoods-programmers-believe-about-time

Now read this if its a JAVA Application:

https://yawk.at/java.time/


Tuesday, 23 June 2020

Microsoft SQL quick help


--Describe table in MS SQL
exec sp_columns My_Table;

--Check for indexes on given table
Select 
    SysIndex.object_id As ObjectId, 
    SysIndex.index_id As IndexId, 
    SysIndex.name As IndexName, 
    type As IndexType, 
    type_desc As IndexTypeDesc, 
    is_unique As IndexIsUnique, 
    is_primary_key As IndexIsPrimarykey, 
    fill_factor As IndexFillFactor, 
    SysIndexCol.column_id, 
    SysCols.name 
From 
    sys.indexes As SysIndex
    Inner Join sys.index_columns As SysIndexCol On SysIndex.object_id = SysIndexCol.object_id And SysIndex.index_id = SysIndexCol.index_id 
    Inner Join sys.columns As SysCols On SysIndexCol.column_id = SysCols.column_id And SysIndexCol.object_id = SysCols.object_id 
Where 
    type <> 0 
    And SysIndex.object_id in (Select systbl.object_id from sys.tables as systbl Where systbl.name = 'My_Table');

Thursday, 26 July 2018

Priority Queue Using Doubly Linked List (Custom Implementation)


package com.vzt.Test.PQ;

public class PQUsingDLL {
public static void main(String[] vj) {
PriorityQUsingDLL obj = new PriorityQUsingDLL();

System.out.println("INSERTING...");
obj.enqueue(2, 3);
obj.enqueue(3, 4);
obj.enqueue(4, 5);
obj.enqueue(5, 2);
obj.enqueue(6, 7);
obj.enqueue(1, 1);

obj.displayQ();

System.out.println("REMOVING...");
obj.dequeue();
obj.dequeue();

obj.displayQ();
}
}

class PriorityQUsingDLL {
private DoublyLinkList list;

public PriorityQUsingDLL() {
list = new DoublyLinkList();
}

public void enqueue(int x, int p) {
list.insert(x, p);
}

public void dequeue() {
list.remove();
}

public void displayQ() {
System.out.println("PRINTING...");
list.display();
}
}

class DoublyLinkList {

private Node first = null;
private Node last = null;

public DoublyLinkList() {
first = null;
last = null;
}

public boolean isEmpty() {
return (first == null);
}

public void insert(int n, int p) {
Node newNode = new Node(n, p);
if (first == null) {
first = newNode;
last = newNode;
} else {
if (p <= first.priority) {
newNode.next = first;
first.prev = newNode.next;
first = newNode;
}
else if (p > last.priority) {
last.next = newNode;
newNode.prev = last.next;
last = newNode;
}
else {
Node start = first.next;
while (start.priority > p)
start = start.next;
start.prev.next = newNode;
newNode.next = start.prev;
newNode.prev = start.prev.next;
start.prev = newNode.next;
}
}
}

public Node remove() {
if (first == null) {
last = null;
return null;
}
Node temp = first;
first = first.next;
temp.displayNode();
return temp;
}

public void display() {
Node current = first;

while (current != null) {
current.displayNode();
current = current.next;
}

System.out.println(" ");
}
public int peek() {
return first.info;
}
}

class Node {
int info;
int priority;
Node prev, next;

Node(int x, int p) {
info = x;
priority = p;
prev = null;
next = null;
}

public void displayNode() {
System.out.println("Data = " + info);
}
}

Priority Queue Using Linked List (Custom Implementation)


package com.vzt.Test.PQ;

public class PQUsingLL {
public static void main(String[] vj) {
PriorityQ obj = new PriorityQ();
System.out.println("INSERTING...");
obj.enqueue("A",1);
obj.enqueue("B",2);
obj.enqueue("C",3);
obj.enqueue("D",4);
obj.displayList();
System.out.println("REMOVING...");
obj.dequeue();
obj.dequeue();
obj.dequeue();
obj.dequeue();
}
}

class PriorityQ {
    private LinkList list;

    public PriorityQ() {
        list = new LinkList();
    }

    public void enqueue(String x, int p) {
        list.insert(x, p);
    }

    public void dequeue() {
        list.remove();
    }

    public void displayList() {
        System.out.println("PRINTING...");
        list.display();
    }
}

class LinkList {

    private OneNode first;

    public LinkList() {
        first = null;
    }

    public boolean isEmpty() {
        return (first == null);
    }

    public void insert(String x, int p) {
    OneNode newNode = new OneNode(x, p);
    OneNode previous = null;
    OneNode current = first;

        while (current != null && p > current.priority) {
            previous = current;
            current = current.next;
        }

        if (previous == null) {
            newNode.next = first;
            first = newNode;
        }

        else {
            previous.next = newNode;
            newNode.next = current;
        }
    }

    public OneNode remove() {
    if(null == first) {
    return null;
    }
    OneNode temp = first;
    first = first.next;
    temp.displayNode();
        return temp;
    }

    public void display() {
    OneNode current = first;

        while (current != null) {
            current.displayNode();
            current = current.next;
        }

        System.out.println(" ");
    }

public String peek() {
return first.info;
}
}

class OneNode {

    String info;
    int priority;
    OneNode next;

    public OneNode(String x, int p) {
    info = x;
    priority = p;
    next = null;
    }

    public void displayNode() {
        System.out.println("Data = " + info);
    }

}

Tuesday, 9 September 2014

Thursday, 17 July 2014

Three times the sum of digits of the number equals number itself.

// num = 27 = 3*(2+7)
// AIM: To find all such numbers

#include<stdio.h>
void main()
{
    long num = 1, i;
    int temp = 0;
    long  test = 0;
    long count = 0;
    while(count < 100)
    {
        i = num;
        test = 0;
        while(i != 0)
        {
            temp = i % 10;
            test = test + temp;
            i = i / 10;
        }
        if( (test*3) == num)
        {
            printf("found : %d", num);
            //only such number is 27, u can check upto infinite but no use, I already tried. :P
        }
        //printf("num = %d and test*3 = %d\n",num, test*3);
        count++;
        num++;
    }
}

Saturday, 11 January 2014

Automatically Refresh/Reload a Web Page at fixed Interval of Time (Using VB Script)

Copy the code below to notepad and save it as refresh.vbs
Double click on the file to run the script.

On Error Resume Next

Set objExplorer = CreateObject("InternetExplorer.Application")

objExplorer.Navigate "http://www.youtube.com/watch?v=81MV1agQMG4"
objExplorer.Visible = 1

Wscript.Sleep 5000

Set objDoc = objExplorer.Document

Do While True
    Wscript.Sleep 5000
    objDoc.Location.Reload(True)
    If Err <> 0 Then
        Wscript.Quit
    End If
Loop

TEXT TO SPEECH (Using VB Script)

Copy the code below to notepad and save it as filename.vbs
Double click on the file to run the script.

dim m, s
   m=inputbox("Enter text","Text2Speech")
   set s=createobject("sapi.spvoice")
   s.Speak m

Monday, 23 December 2013

Program to invert 'n' alternate bits of a number (Asked in APPLIED MATERIALS coding round)

// initial 30 = 11110
// final   11 = 01011

#include<stdio.h>
int invert_alternate_bit(int,int);
int main()
{
printf("NEW num : %d\n",invert_alternate_bit(30,3));
return 0;
}
int invert_alternate_bit(int num,int n)
{
int c = 0;
printf("OLD num : %d\n",num);
for(int i=1; i<= n ; i++)
{
c = c << 2;
c = c ^ 1;
}
num = num ^ c;
return num;
}

Sunday, 22 December 2013

Program to initialize the array as a pyramid of alphabets (Asked in APPLIED MATERIALS coding round)

#include<stdio.h>
void print_in(int,int,char);
void show(int,int);
void initialize(int,int);
char a[4][9];
int main()
{
char ch='A';
initialize(5,9);
print_in(0,4,ch);
show(5,9);
}
void print_in(int row,int col,char ch)
{
int count=1;
while(count<=25) // till Y
{
if(count==1)
{
a[row][col] = ch;
ch++;
}
if(count>1 && count<=4)
{
a[row][col] = ch;
col++;
ch++;
}
if(count>4 && count<=9)
{
a[row][col] = ch;
col++;
ch++;
}
if(count>9 && count<=16)
{
a[row][col] = ch;
col++;
ch++;
}
if(count>16 && count<=25)
{
a[row][col] = ch;
col++;
ch++;
}
if(count==1)
{
row++; // 1
col--;  // 3
}
if(count==4)
{
row++; // 2
col = col-4;// 2
}
if(count==9)
{
row++; // 3
col = col-6;// 1
}
if(count==16)
{
row++; // 4
col = col-8;// 0
}

count++;
}
}
void show(int row,int col)
{
for(int i=0;i<row;i++)
{
for(int j=0;j<col;j++)
{
printf("%c ",a[i][j]);
}
printf("\n");
}
}
void initialize(int row,int col)
{
for(int i=0;i<row;i++)
{
for(int j=0;j<col;j++)
{
a[i][j] = ' ';
}
}
}


Sample Output:
A
BCD
EFGHI
JKLMNOP
QRSTUVWXY

Wednesday, 18 December 2013

CISCO CERTIFIED NETWORKING WORKSHOP @CUSAT

ACM IIT Delhi Sponsored- National Network Security Championship (NNSC-2014) @ School of Engineering, Cochin University of Science and Technology
About NNSC

NNSC-2014 is National Network Security Championship with workshop series jointly being organized by Association for Computer Machinery-IIT Delhi and Network Bulls, Gurgaon. This championship, which is sponsored by ASIA’s Biggest Cisco Training Labs- Network Bulls - Gurgaon, will help students across the country to meet at same grounds and to learn about Cisco/Networking Technologies. 

Event Details

Workshop Date@CUSAT: 18 & 19 January, 2014.
Eligible Branches: ALL Branches (Expecting large participation from CSE, IT and EC) & ALL Semesters
Participation Fees:  1190
Seats: Limited seats according to the equipments available for each students. (Nearly 50). So Hurry, grab this golden opportunity.
Event Coordinator (Faculty): Mr. Vinod Kumar P.P. & Mr. V. Damodaran
Register: HERE

Stage 1 (WORKSHOP ROUND to be held at Zonal Centers)
A two day hands-on Network Implementation workshop will be held all across India
All the participants who want to participate in NNSC-2014 are required to attend the workshops at any Zonal Center and participate in the competition after the workshop.
The Duration of the Networking workshop will be of 2 Days (7-8 hrs each day).
The workshop will be delivered by Cisco Certified Professionals working with Network Bulls, Gurgaon. 

Stage 2 (ZONAL ROUND to be held at Zonal Center) 
Just after the workshop a Mega Competition of NNSC-2014 on the basis of the two day workshop will be held.
Winners will be awarded Certificate of Merit, and are required to participate in Final Rounds which will be held in the month of March 2014 at IIT Delhi. 

Stage 3 (FINAL ROUND to be held at IIT Delhi) 
Winners of all Zonal Centers will be competing against each other at NNSC-2014 in March 2014 in association with ACM-IIT Delhi.
Winner of this Final Round will win The National Network Security Champion title and will be awarded and honored by ACM-IIT Delhi with prizes worth 1 lakh rupees. 

For further details please visit:
Website: www.nnscindia.com
Facebook Page: 
www.facebook.com/nnscindia