This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <string> | |
| #include <stack> | |
| using namespace std; | |
| int main() { | |
| string line; | |
| string res; | |
| stack<char> st ; | |
| while (getline(cin, line)) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <array> | |
| #include <deque> | |
| #include <iostream> | |
| #include <optional> | |
| #include <vector> | |
| using namespace std; | |
| class PlayingPiece { | |
| public: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| 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() | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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)); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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() {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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; |
NewerOlder