Tuesday, 27 October 2020

Aws lambda API getway and Dynamodb.

 https://iotdemos.wordpress.com/2017/04/24/building-simple-back-end-using-aws-dynamodb-lambda-api-gateway/



Handle payload and parse to Lambda function 


{
  "body" : $input.json('$'),
  "headers": {
    #foreach($header in $input.params().header.keySet())
    "$header": "$util.escapeJavaScript($input.params().header.get($header))" #if($foreach.hasNext),#end
 
    #end
  },
  "method": "$context.httpMethod",
  "params": {
    #foreach($param in $input.params().path.keySet())
    "$param": "$util.escapeJavaScript($input.params().path.get($param))" #if($foreach.hasNext),#end
 
    #end
  },
  "query": {
    #foreach($queryParam in $input.params().querystring.keySet())
    "$queryParam": "$util.escapeJavaScript($input.params().querystring.get($queryParam))" #if($foreach.hasNext),#end
 
    #end
  
}

Tuesday, 13 October 2020

nested if in mysql

SELECT IF(500<1000, IF(10>12,'pawan','kumar'), IF(10>5,'oo','mm'));

Tuesday, 6 October 2020

How to create procedure in mysql

 DELIMITER $$

CREATE procedure getAnswerByQuestionId(IN questionID INT)

BEGIN 

SELECT * FROM sh_answers where question_id=questionID;

END$$

DELIMITER ;


call getAnswerByQuestionId(5);



https://www.codegrepper.com/code-examples/sql/sql+cursor+w3schools

https://www.javatpoint.com/mysql-cursor

Monday, 5 October 2020

synchronization keyword use in java

 https://stackabuse.com/synchronized-keyword-in-java/#:~:text=To%20avoid%20such%20issues%2C%20Java,the%20resource%20to%20become%20free.


public class NonSynchronizedMethod { public void printNumbers() { System.out.println("Starting to print Numbers for " + Thread.currentThread().getName()); for (int i = 0; i < 5; i++) { System.out.println(Thread.currentThread().getName() + " " + i); } System.out.println("Completed printing Numbers for " + Thread.currentThread().getName()); } }



class ThreadOne extends Thread { NonSynchronizedMethod nonSynchronizedMethod; public ThreadOne(NonSynchronizedMethod nonSynchronizedMethod) { this.nonSynchronizedMethod = nonSynchronizedMethod; } @Override public void run() { nonSynchronizedMethod.printNumbers(); } } class ThreadTwo extends Thread { NonSynchronizedMethod nonSynchronizedMethod; public ThreadTwo(NonSynchronizedMethod nonSynchronizedMethod) { this.nonSynchronizedMethod = nonSynchronizedMethod; } @Override public void run() { nonSynchronizedMethod.printNumbers(); } }


public class TestSynchronization { public static void main(String[] args) { NonSynchronizedMethod nonSynchronizedMethod = new NonSynchronizedMethod(); ThreadOne threadOne = new ThreadOne(nonSynchronizedMethod); threadOne.setName("ThreadOne"); ThreadTwo threadTwo = new ThreadTwo(nonSynchronizedMethod); threadTwo.setName("ThreadTwo"); threadOne.start(); threadTwo.start(); } }



public synchronized void printNumbers() { System.out.println("Starting to print Numbers for " + Thread.currentThread().getName()); for (int i = 0; i < 5; i++) { System.out.println(Thread.currentThread().getName() + " " + i); } System.out.println("Completed printing Numbers for " + Thread.currentThread().getName()); }