Skip to content

Instantly share code, notes, and snippets.

View prav-raghu's full-sized avatar
🐍
Working from home

Prav prav-raghu

🐍
Working from home
View GitHub Profile
@prav-raghu
prav-raghu / fastify-server.ts
Created August 31, 2021 19:08
Fastify ws socket
// [the entire purpose of this exercise is to make a post request that will emit an event that takes in an id that should match up with one of the connected socket clients
// if we get this process right it will not only help with our payment work thats being worked on but any future dashboard realtime updates for stats]
// step processes work as follows with no auth considered in this code
// 1) make a post request with a unique identifier attached to it
// 2) if there exists a client with said matching unique identifier thats currently open accept that message from the server
// 3) we can choose in this case to then close the connection for that client
// ** lets assume this is what would done for the payment
// [feed back will be much appreciated]
'use strict';
import { v4 as uuidv4 } from "uuid";
["Afghanistan",
"Albania",
"Algeria",
"Andorra",
"Angola",
"Antigua and Barbuda",
"Argentina",
"Armenia",
"Australia",
"Austria",
def is_multiple(n,m):
if (n % m == 0):
return True
else:
return False
print(is_multiple(10,3))
def is_even(k):
if(k ^ 1 == k+1):
return True
else:
return False
k = input("Please provide a number: ")
print(is_even(int(k)))
def minmax(data):
max = data[0]
min = data[0]
for k in data:
if(k > max):
max = k
if(k < min):
min = k
print('max: ' + str(max))
print('min: ' + str(min))
def square(data):
squares = []
for k in list(range(1,data)):
squares.append(k*k)
return squares
print(square(5))
def square(n):
squares = [k*k for k in range(1, n)]
return squares
print(square(100))
def square(n):
total = 0
for k in range(1, n):
if(k % 2 != 0):
total +=(k*k)
return total
print(square(5))
def square(n):
squares = sum(k*k for k in range(1, n) if k % 2 != 0 and k > 0)
return squares
print(square(5))
@prav-raghu
prav-raghu / recursiveBinarySearch.js
Created March 31, 2022 11:48
Recursive Binary Search in JavaScript
var array = [1,2,3,4,5]
let recursiveFunction = function(array,x,start,end){
if(start > end){
return false
}
let mid = Math.floor((start + end)/2)
if(array[mid] === x){
return true;
}