Skip to content

Instantly share code, notes, and snippets.

View trialan's full-sized avatar

tr416 trialan

  • Cambridge, UK
View GitHub Profile
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
import tkinter as tk
# Sample data for X and Y
X = np.random.rand(10, 3)
Y = np.random.rand(10, 3)
# Create the main window
@trialan
trialan / count_faces.py
Last active July 3, 2024 15:31
Count faces
def dlib_count_faces(image_path):
img = Image.open(image_path)
img = img.convert('RGB')
img_array = np.array(img)
detector = dlib.get_frontal_face_detector()
faces = detector(img_array)
return len(faces)
def haar_cascade_count_faces(image_path):
@trialan
trialan / inserting_transaction_in_db.py
Created May 21, 2022 13:04
Updated successful payment callback
def successful_payment_callback(update: Update, context):
col = get_collection()
receipt = update.message.successful_payment
col.insert_one({"telegram_uid": update.message.chat.username,
"donated_amount": receipt.total_amount,
"currency": receipt.currency,
"datetime": str(datetime.datetime.now())})
print_col(col)
update.message.reply_text("Thank you for your purchase!")
@trialan
trialan / database.py
Last active May 21, 2022 12:05
Simple MongoDB
import pymongo
def get_collection():
client = pymongo.MongoClient()
db = client["database"]
col = db["transactions"]
return col
from telegram import LabeledPrice, ParseMode
from telegram.ext import PreCheckoutQueryHandler
from telegram.ext.callbackcontext import CallbackContext
from telegram.ext.commandhandler import CommandHandler
from telegram.ext.filters import Filters
from telegram.ext.messagehandler import MessageHandler
from telegram.ext.updater import Updater
from telegram.update import Update
@trialan
trialan / simple_payment_bot.py
Last active May 21, 2022 11:49
simple bot that accepts payments
from telegram import LabeledPrice, ParseMode
from telegram.ext import PreCheckoutQueryHandler
from telegram.ext.callbackcontext import CallbackContext
from telegram.ext.commandhandler import CommandHandler
from telegram.ext.filters import Filters
from telegram.ext.messagehandler import MessageHandler
from telegram.ext.updater import Updater
from telegram.update import Update
from telegram.ext.callbackcontext import CallbackContext
from telegram.ext.commandhandler import CommandHandler
from telegram.ext.filters import Filters
from telegram.ext.messagehandler import MessageHandler
from telegram.ext.updater import Updater
from telegram.update import Update
BOT_KEY = "<YOUR_BOT_TOKEN_HERE>"