Skip to content

Instantly share code, notes, and snippets.

View manojnaidu619's full-sized avatar
🎯
Focusing

Manoj Kumar manojnaidu619

🎯
Focusing
  • Bangalore,India
View GitHub Profile
@manojnaidu619
manojnaidu619 / mongodb.js
Created April 4, 2020 05:13
MongoDB database connection code snippet
const mongodb = require("mongodb")
const MongoClient = mongodb.MongoClient
const connectionURL = "mongodb://127.0.0.1:27017" // Change the url in production
const databaseName = "task-manager" // Change the database name
MongoClient.connect(connectionURL, { useNewUrlParser: true, useUnifiedTopology: true }, (error, client) => {
if (error) {
return console.log("Some error occurred")
}
@manojnaidu619
manojnaidu619 / nodeCallbackDemo.js
Created April 3, 2020 14:45
Code snippet to demonstrate callback functions(async run) pattern
const addFunction = (a, b, callback) => {
setTimeout(() => {
const sum = a+b
callback(sum)
},1000)
}
addFunction(1, 2, (sum) => {
console.log(sum)
})
@manojnaidu619
manojnaidu619 / dfs.py
Created February 23, 2020 13:07
Interactive DFS on graphs in python
import queue
class Node:
def __init__(self):
self.data=None
self.neighbors=[]
class Graph:
def __init__(self):
self.root=None
@manojnaidu619
manojnaidu619 / bfs.py
Last active February 22, 2020 05:48
Interactive BFS on graphs in python
import queue
class Node:
def __init__(self):
self.data=None
self.neighbors=[]
class Graph:
def __init__(self):
self.root=None
@manojnaidu619
manojnaidu619 / binary_trees.py
Created February 15, 2020 06:03
Binary Trees implementation in Python
class Node:
def __init__(self):
self.data=None
self.left=None
self.right=None
class LL:
def __init__(self):
self.root=None
self.leaf=0
@manojnaidu619
manojnaidu619 / binarySearchRecursive.py
Created February 10, 2020 14:24
Binary Search in Python(Recursive version)
def binarySearch(arr, key, low, high):
if low>high:
return False
else:
mid = (low+high)/2
if arr[mid]==key:
return True
elif key<arr[mid]:
return binarySearch(arr,key,low,mid-1)
else:
@manojnaidu619
manojnaidu619 / binarySearch.py
Last active February 10, 2020 14:24
Binary Search in Python(Iterative version)
def binarySearch(arr,key):
low,high=0,len(arr)-1
while low<=high:
mid = (high+low)/2
if arr[mid]==key:
return mid+1
if key<arr[mid]: high=mid-1
else: low=mid+1
if low>high: return False
@manojnaidu619
manojnaidu619 / banking.py
Created February 8, 2020 15:09
Banking Management system in Python
from random import randint
class Account:
def __init__(self):
self.accounts = {}
self.name = None
self.initialDeposit = None
def createAccount(self, name, initialDeposit):
@manojnaidu619
manojnaidu619 / library.py
Created February 8, 2020 03:29
Library Management in python
class Library:
def __init__(self, listOfBooks):
self.books = listOfBooks
def showAllBooks(self):
print("\n")
for book in self.books:
print(book)
print("\n")
@manojnaidu619
manojnaidu619 / react_functional_component.js
Created January 26, 2020 11:04
React functional component(Uses hooks for state management)
import React, {useState} from 'react';
const App = props => {
const [pstate, sstate] = useState({
name: "Manoj",
country: "India"
})
const switchNameHandler = () => {