Skip to content

Instantly share code, notes, and snippets.

View viveksyngh's full-sized avatar

Vivek Kumar Singh viveksyngh

View GitHub Profile
@viveksyngh
viveksyngh / setup-of-cloud-on-swarm.md
Last active September 18, 2018 14:14
Step by Step description to setup OpenFaaS-Cloud on docker swarm.

Deploy OpenFaaS on docker swarm using deploy script.

Use --no-auth if you want to disable basic authentication

./deploy_stack.sh --no-auth

Deploy local docker registry.

docker service rm registry
@viveksyngh
viveksyngh / handler.go
Last active July 29, 2018 12:41
OpenFaaS function in a gist
package function
import (
"fmt"
)
// Handle a serverless request
func Handle(req []byte) string {
return fmt.Sprintf("Hello, Go. You said: %s", string(req))
}
@viveksyngh
viveksyngh / server.go
Last active December 24, 2020 07:24
Http Response in go
package main
import (
"fmt"
"net/http"
"encoding/json"
"html/template"
)
type User struct {
@viveksyngh
viveksyngh / DNUMS.py
Created February 1, 2016 17:03
You are given an array of N integers, A1, A2 ,…, AN and an integer K. Return the of count of distinct numbers in all windows of size K. Formally, return an array of size N-K+1 where i’th element in this array contains number of distinct elements in sequence Ai, Ai+1 ,…, Ai+k-1.
class Solution:
# @param A : list of integers
# @param B : integer
# @return a list of integers
def dNums(self, A, B):
mapOfNums = {}
count = 0
ptr = -1
res = []
if B > len(A) :
@viveksyngh
viveksyngh / 2SUM.py
Created October 4, 2015 16:41
Given an array of integers, find two numbers such that they add up to a specific target number.
__author__ = 'Vivek'
#Given an array of integers, find two numbers such that they add up to a specific target number.
class Solution:
# @param A : tuple of integers
# @param B : integer
# @return a list of integers
def twoSum(self, A, B):
Map = {}
@viveksyngh
viveksyngh / FALTTEN.py
Created October 3, 2015 12:10
Given a binary tree, flatten it to a linked list in-place.
__author__ = 'Vivek'
#Given a binary tree, flatten it to a linked list in-place.
# Definition for a binary tree node
# class TreeNode:
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
@viveksyngh
viveksyngh / MERGEKLIST.py
Created October 2, 2015 09:20
Merge k sorted linked lists and return it as one sorted list.
__author__ = 'Vivek'
# Definition for singly-linked list.
class ListNode:
def __init__(self, x):
self.val = x
self.next = None
import heapq
class Solution:
# @param A : list of linked list
@viveksyngh
viveksyngh / BINARYTREE2.py
Created September 29, 2015 06:10
Given preorder and inorder traversal of a tree, construct the binary tree.
__author__ = 'Vivek'
#Given preorder and inorder traversal of a tree, construct the binary tree.
# Definition for a binary tree node
class TreeNode:
def __init__(self, x):
self.val = x
self.left = None
self.right = None
@viveksyngh
viveksyngh / BINARYTREE1.py
Created September 29, 2015 06:09
Given inorder and postorder traversal of a tree, construct the binary tree.
__author__ = 'Vivek'
#Given inorder and postorder traversal of a tree, construct the binary tree.
# Definition for a binary tree node
class TreeNode:
def __init__(self, x):
self.val = x
self.left = None
self.right = None
@viveksyngh
viveksyngh / SUMROOTLEAF.py
Created September 28, 2015 07:00
Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number. An example is the root-to-leaf path 1->2->3 which represents the number 123. Find the total sum of all root-to-leaf numbers % 1003.
__author__ = 'Vivek'
#Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number.
#An example is the root-to-leaf path 1->2->3 which represents the number 123.
#Find the total sum of all root-to-leaf numbers % 1003.
# Definition for a binary tree node
# class TreeNode:
# def __init__(self, x):