BITCOIN MINING
==============
from hashlib import sha256
MAX NONCE 189000000006
def SHA256(text):
return sha256(text.encode("ascit")).hexdigest()
def mine(block_number,transactions,previous_hash,prefix_zeros):
prefix_str='0'*prefix zeros
for nonce in range(MAX_NONCE):
text=str(block_number)+transactions+previous_hash+str(nonce)
new_hash SHA256(text)
if new_hash.startswith(prefix_str):
print(f"Yay!Successfully mined bitcoins with nonce value:{nonce}")
return new hash
raise BaseException(f"Couldn't find correct has after trying(MAX_NONCE}times")
if_name='__ main__':
transactions ***
Dhaval->Bhavin->20,
Mando->Cara->45
***
difficultyd try changing this to higher number and you will see it will take more time
for wining as difficulty increases
import time
start=time.time()
print("start mtning")
new hash-
mine(5,transactions,'0000000xa036944e29568d0cff17edbe838f81288fecf9a66be9a2b8321c6ec7",
difficulty)
total time str((tine.time()-start))
print(frend mining.Mining took:(total time)seconds")
print(new_hash)
Car Detection
=================
#import Libraries of python OpenCV
import cv2
#capture frames fromavideo
cap=cv2.VideoCapture('video.avi')
#Trained XML classifiers describes same features of
#some object we want to detect
car_cascade=cv2.Cascade Classifier('cars.xml')
#Loop runs if capturing has been initialized.
while True:
#reads frames fromavideo
ret,frames=cap.read()
#convert to gray scale of each frames.
gray cv2.cvt Color(frames,cv2.COLOR_BGR2GRAY)
#Detects cars of different sizes in the input mage
cars car_cascade.detectMultiscale(gray,1.1,1)
#To drawarectangle in each cars
for(x,y,w,h)in cars:
CV2.rectangle(frames,(x,y),(x+w,y+h),(0,0,255),2)
#Display frames inawindow
cv2.imshow('video2',frames)
#Watt for Esc key to stop
if cv2.waitkey(33)=27:
break
#De-allocate any associated memory usage
cv2.destroyAllWindows()
Face Detection
==============
import cv2
Load the Cascade
face_cascade=cv2.CascadeClassifier("haarcascade_frontalface_default.xml')
To capture video from webcam
cap cv2.VideoCapture(0)
ato useavideo file as input
while True:
Read the frame
,ing cap.read()
Convert to grayscale
gray cv2.cvtColor(ing,cv2.COLOR_BGR2GRAY)
#Deteri the faces
faces=face_cascade.detectMultiscale(gray,1.1,4)
#Draw the rectangle around each face
for(x,y,w,h)in faces:
cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)
cv2.imshow("img',img)
#Stup of escape key is pressed
k=cv2.wattKey(30)&exff
ifk== 27:
break
Release the VideoCapture object
cap.release()
Phone Number Detail
===================
import phonenumbers
from phonenumbers import timezone,geocoder,carrier
phoneNumber=phonenumbers.parse("+918978923094")
timezone=timezone.time_zones_for_number(phoneNumber)
Carrier=carrier.name_for_number(phoneNumber,'en')
Region=
print(phoneNumber)
print(timeZone)
print(Carrier)
print(Region)
geocoder.description_for_number(phoneNumber,'en')
Top comments (0)