Wednesday 10 May 2023

Uploading and Running Lambda function in AWS

Main.go
package main

import (
"fmt"
"encoding/json"
"log"
"github.com/aws/aws-lambda-go/events"
"github.com/aws/aws-lambda-go/lambda"
)


func main() {
lambda.Start(handler)
}

func handler(request events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
var person Person
//json request body se nikaal ke person var me rakh denge
err := json.Unmarshal([]byte(request.Body), &person)
if err !=nil {
return events.APIGatewayProxyResponse{}, err
}

//ab person se firstname aur lastname nikaal ke msg bana lenge
msg := fmt.Sprintf("Hello %v %v", *person.FirstName, *person.LastName)
responseBody := ResponseBody{
Message: &msg,
}
jbytes, err := json.Marshal(responseBody)
if err !=nil {
return events.APIGatewayProxyResponse{}, err
}

log.Println("hello world Nihal")

response := events.APIGatewayProxyResponse{
StatusCode: 200,
Body: string(jbytes),
}

return response, nil
}

type Person struct {
FirstName *string `json:"firstName"`
LastName *string `json:"lastName"`
}

type ResponseBody struct {
Message *string `json:"message"`
}
Run command : GOARCH=amd64 GOOS=linux go build main.go 

(This command will set the OS as linux and run build which will generate main file) 

 Once the main file is created and we can create a zip of this main and upload it to lambda. 

 Configure API-gateway with the above lambda. 

 Through Postman send the post request. { "firstName" : "Nikhillll2", "lastName" : "Nihallll2" }

Friday 8 July 2022

Subset Sum with Recursion | memorization | DP

Given a set of non-negative integers, and a value sum, determine if there is a subset of the given set with sum equal to given sum.

https://www.geeksforgeeks.org/subset-sum-problem-dp-25/


            Recursion                                     

     class Solution {

    

    static boolean isSumK(int[] nums, int curin, int curSum) {

        

        if(curSum==0) {

            return true;

        }

        

        if(curin<0) {

            return false;

        }

        

        return isSumK(nums, curin-1, curSum-nums[curin]) 

            || isSumK(nums, curin-1, curSum);

    }



With Memorization

class Solution{


    static int issum(int arr[], int indx, int sum, int dp[][]) {

        

        if(sum==0)

         return 1;

         

        if(indx<0)

         return 0;

        

        if(dp[indx][sum]!=-1)

         return dp[indx][sum];

         

        int pick = 0;

        if(sum>=arr[indx]) 

          pick = issum(arr, indx-1, sum-arr[indx],dp);

          

        int notpick = issum(arr, indx-1, sum,dp);

        

        if(pick==1 || notpick==1) 

         return dp[indx][sum] = 1;

         

        return dp[indx][sum] = 0;

    }





Thursday 16 June 2022

Subset sum K [Recursion]

 https://www.geeksforgeeks.org/subset-sum-problem-dp-25/


class Solution {

    

    static boolean isSumK(int[] nums, int curin, int curSum) {

        

        if(curSum==0) {

            return true;

        }

        

        if(curin<0) {

            return false;

        }

        

        return isSumK(nums, curin-1, curSum-nums[curin]) 

            || isSumK(nums, curin-1, curSum);

    }



    static Boolean isSubsetSum(int N, int arr[], int sum) {

        // code here

        return isSumK(arr, N-1, sum);

    }

}

Saturday 11 June 2022

Java Practice [HashMap]

Group Anagrams https://leetcode.com/problems/group-anagrams/


 class Solution {

    public List<List<String>> groupAnagrams(String[] strs) {

        

        HashMap<String, List<String>> hm = new HashMap<>();

        

        for(int i=0;i<strs.length;i++) {

            char[] s = strs[i].toCharArray();

            Arrays.sort(s);

            String k = new String(s);

            if(hm.containsKey(k)) {

                hm.get(k).add(strs[i]);

            } else {

                List<String> ls = new ArrayList<String>();

                ls.add(strs[i]);

                hm.put(k,ls);

            }

        }

        

        List<List<String>> ans = new ArrayList<List<String>>();;

        

        for (String p:hm.keySet()) {

          ans.add(hm.get(p));   

        }

        

        return ans;

    }

}

Saturday 28 May 2022

Linked List in Java without Collections

  • Linked List in Java without Collections

class Node {
int data;
Node next;
Node(int data) {
this.data = data;
this.next = null;
}
}

public class Main {
public static void main(String[] args) {

Node n1 = new Node(5);
Node n2 = new Node(6);
Node n3 = new Node(7);
Node n4 = new Node(8);
n1.next = n2;
n2.next = n3;
n3.next = n4;

Node start = n1;
while(start!=null) {
System.out.println(start.data+" ");
start = start.next;
}
}
}

Tuesday 6 June 2017

Syscloud PHP developer Interview Questions

I got selected for Interview from HackerEarth online Test (It was a hiring challenge).

The Questions they asked was basic only.

Questions related to Webserver & PHP:-
1) How to configure apache webserver ?
2) Where is the configuration file of PHP ?
3) How server and client communication happens?
4) Explain about different methods(POST ,GET ,PUT ) ?

Apart from that they asked basic SQL Questions like :-
1) What is the difference between Truncate and Delete ?
2) How to drop table schema ?

they also asked a Programming question
1) Write a Program to reverse a string


Viewing this video tutorial will help:-  https://www.youtube.com/watch?v=1ZioHruINOA&list=PLtGnc4I6s8dsNLpl0G30Azcc-Q4eoM4TX

Sunday 28 May 2017

Getting Started With MEAN App Development with AngularJs , ExpressJs , NodeJs and MongoDB.

         Getting Started With MEAN App Development


I Started Learning AngularJs one year Back. It is always a nice experience to start learning something new. I used Some of my AngularJs skills in my Programming Calculator App.
Few Days Back , I Started my hands on NodeJs and ExpressJs. I watched many Youtube Videos and Tutorials of  NodeJs and ExpreesJs. After that , I thought to do a Small Project Using all my skills of AngularJs , NodeJs ,ExpressJs. 

I followed a Youtube Video (https://www.youtube.com/watch?v=kHV7gOHvNdk) and Made a Small Project Similiar to this one.After that I also Learnt that how to deploy my MEAN app on heroku website(heroku.com). My app uses MongoDB for database. So , i also used mLab (https://mlab.com/),which provided me MongoDB hosting service.

There is a very useful blog which helped me to learn how to deploy my app on heroku. (https://devcenter.heroku.com/articles/git#tracking-your-app-in-git) and how to install heroku on system (https://devcenter.heroku.com/articles/heroku-cli).

Finally , This is the App which i made (https://nikhil-contact-list.herokuapp.com/). This is a contact-list App, where anyone can enter there name, email-id and phone number. It also provides the option to delete and Edit the details in case of some mistake/typos.


I also deployed my app on google-cloud-platform (https://contact-list-app-170421.appspot.com/).I have taken help from these two articles (https://cloud.google.com/community/tutorials/run-expressjs-on-google-app-engine) and (https://cloud.google.com/sdk/docs/#deb).
I will Provide the code in my next Blog. Feel free to contact in case of any help.



Thanks
Nikhil


Uploading and Running Lambda function in AWS

Main.go package main import ( "fmt" "encoding/json" "log" "github.com/aws/aws-lambda-g...