Skip to content

Instantly share code, notes, and snippets.

View satyajeetkrjha's full-sized avatar
💭
Curious

Satyajeet Kumar Jha satyajeetkrjha

💭
Curious
  • New York ,USA
View GitHub Profile
@satyajeetkrjha
satyajeetkrjha / aecho.py
Created October 17, 2023 03:26 — forked from dabeaz/aecho.py
Live-coded examples from my PyCon Brasil 2015 Keynote
# aecho.py
from socket import *
import asyncio
loop = asyncio.get_event_loop()
async def echo_server(address):
sock = socket(AF_INET, SOCK_STREAM)
sock.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
@satyajeetkrjha
satyajeetkrjha / aproducer.py
Created October 14, 2023 02:56 — forked from dabeaz/aproducer.py
"Build Your Own Async" Workshop - PyCon India - October 14, 2019 - https://www.youtube.com/watch?v=Y4Gt3Xjd7G8
# aproducer.py
#
# Async Producer-consumer problem.
# Challenge: How to implement the same functionality, but no threads.
import time
from collections import deque
import heapq
class Scheduler:
@satyajeetkrjha
satyajeetkrjha / InterviewJavascript1.js
Last active April 14, 2023 01:15
Javascript interview questions
// Create a function which has increment and getValue functionality
//This is a really good example of closure beacuse we see that inside increment and getValue function
// we have access to the count varaible .Closure basically means if you are inside a function ,you have access
// to everything defined above or before it
const privateCounter = () =>{
let count =0;
return {
increment :(val=1) =>{
count+=val
@satyajeetkrjha
satyajeetkrjha / ecc.py
Created October 7, 2022 00:17 — forked from bellbind/ecc.py
[python]basics of elliptic curve cryptography
# Basics of Elliptic Curve Cryptography implementation on Python
import collections
def inv(n, q):
"""div on PN modulo a/b mod q as a * inv(b, q) mod q
>>> assert n * inv(n, q) % q == 1
"""
for i in range(q):
if (n * i) % q == 1:
#include <iostream>
#include <string>
#include <stack>
using namespace std;
int main() {
string line;
string res;
stack<char> st ;
while (getline(cin, line)) {
@satyajeetkrjha
satyajeetkrjha / tictactoe.cpp
Created July 5, 2022 23:14
Object Oriented Tic Tac Toe
#include <array>
#include <deque>
#include <iostream>
#include <optional>
#include <vector>
using namespace std;
class PlayingPiece {
public:
/*
if( nums[mid] == target && (mid == 0 or nums[mid-1]!=target))
in this piece of code ,if mid turns out to 0 then nums[mid-1] is not evaluated and this will not lead to run time error .
this is called short circuit evaluation .
Similary
if(nums[mid] == target && (mid +1== nums.size() or nums[mid+1]!=target))
the code nums[mid+1] is not evaluated if mid+1 is already equal to nums.size()
class Solution {
public:
int shortestPathLength(vector<vector<int>>& graph) {
int n = graph.size();
if( n == 1)
return 0;
queue <pair <int ,int> > q ; // node and bit state
int finalstate = (1 << n )-1;
vector <vector <int> > visited(n,vector <int>(finalstate+1,0));
@satyajeetkrjha
satyajeetkrjha / card.cpp
Created June 5, 2022 01:14 — forked from michaelsafyan/card.cpp
C++ Playing Cards
#include "card.h"
#include <sstream>
namespace playing_cards {
Card::Card(int value, Suit suit) : value_(value), suit_(suit) {}
Card::Card(const Card& o) : value_(o.value_), suit_(o.suit_) {}
Card::~Card() {}
@satyajeetkrjha
satyajeetkrjha / fft.cpp
Created February 17, 2022 16:13 — forked from hsiuhsiu/fft.cpp
[FFT] Fast Fourier Transform in c++ and basic applications #Algorithm #ACM
#include <complex>
#include <iostream>
#include <valarray>
#include <vector>
using namespace std;
const double PI = 3.141592653589793238460;
typedef std::complex<double> Complex;
typedef std::valarray<Complex> CArray;