Skip to content

Instantly share code, notes, and snippets.

@pknowledge
pknowledge / docker-compose.yaml
Created February 26, 2024 16:36
Run Microsoft Azure SQL Edge using docker compose
version: '3.8'
services:
sql:
image: mcr.microsoft.com/azure-sql-edge
container_name: sql
ports:
- "1433:1433"
environment:
ACCEPT_EULA: "1"
@pknowledge
pknowledge / main.c
Created May 29, 2021 09:18
Arduino Tutorial for Beginners – LED Matrix With Arduino
#define ROW_1 2
#define ROW_2 3
#define ROW_3 4
#define ROW_4 5
#define ROW_5 6
#define ROW_6 7
#define ROW_7 8
#define ROW_8 9
#define COL_1 10
@pknowledge
pknowledge / Image_and_Audio_CAPTCHA_in_Python.py
Created September 2, 2020 19:27
How to Create Image & Audio CAPTCHA in Python
#Image Captcha:
from captcha.image import ImageCaptcha
image = ImageCaptcha
data = image.generate(‘9876543’)
image.write (‘9876543’,’sam.png’)
@pknowledge
pknowledge / GraphRepresentation.py
Created July 4, 2020 19:41
Competitive Programming with Python | Graph Representation | ADJACENCY LIST VS. ADJACENCY MATRIX https://youtu.be/CGOox3yLLYU
# UNDIRECTED GRAPH
'''
ADJ MATRIX
ADJ LIST
'''
'''
V E
FOR EVERY EDGE
@pknowledge
pknowledge / BitMagic.py
Created June 23, 2020 08:55
Competitive Programming with Python | Bit Magic : Interconversion, Kth Bit, Single Number https://youtu.be/4-rgHbeqjTU
# n convert it into binary
def intToBin(n):
return str(bin(n))[2:]
# bin to int
def binToInt(s):
return int(s,2)
# kth bit set from right
def kthbit(n,k):
@pknowledge
pknowledge / BitMagic.py
Created June 22, 2020 15:08
Competitive Programming with Python-Bit Magic- Power of 2 + One's in Binary Representation of Number https://youtu.be/SdP4j-n8S0g
# ispowerof 2
# n -> input
# True/False -> output
# check if n is a powerof 2
# 512 -> True 512 = 2**9
# 1024 -> True 1024 = 2**10
def ispowerof2(n):
# T.C = O(1)
if n <= 0:
# bitwise operator and - &
# bitwise operator or - |
# bitwise operator not - ~
# bitwise operator xor - ^
# bitwise operator right shift - >>
# bitwise operator left shift <<
# rightshift is divide in power of 2
# leftshift is multiply in power of 2
def evenodd(n):
if n&1 == 1:
@pknowledge
pknowledge / Sieve.py
Created June 18, 2020 09:32
Sieve of Eratosthenes | Competitive Programming with Python https://youtu.be/-wIYdmPiHcA
from math import *
def genprimes(n):
primes = [True]*(n+1)
primes[0] = False
primes[1] = False
for p in range(2,int(sqrt(n))+1):
if primes[p] == True:
for i in range(p*p,n+1,p):
primes[i] = False
@pknowledge
pknowledge / primalitytest.py
Created June 9, 2020 21:10
Number Theory for Competitive Programming with Python - Compare Primality Test in O(n) vs O(root(n)) https://youtu.be/4UZufg54dFc
# Prime numbers two factors 1 , Number Itself
# Approach One O(n)
# Aprroach Two: Base Case + Hint: O(1) -> O(root(N))
from math import *
def approach1(n):
divcnt = 0
for i in range(1,n+1): # [1,n]
if n%i == 0:
divcnt+=1
@pknowledge
pknowledge / divisors.py
Created June 9, 2020 14:50
Number Theory for Competitive Programming Using Python - Find Divisors Of A Number O(sqrt(n))
# 24 [1,2,3,4,6,8,12,24]
from math import *
def fun1(n):
# T.C = O(n)
div1 = []
for i in range(1,n+1): # [1,n]
if n%i == 0:
div1.append(i)
return div1