Skip to content

Instantly share code, notes, and snippets.

View MohammadHosseinGhorbani's full-sized avatar

Mohammad Hossein Ghorbani MohammadHosseinGhorbani

View GitHub Profile
@MohammadHosseinGhorbani
MohammadHosseinGhorbani / examples.txt
Created August 7, 2024 15:31
Python Evaluation in text like Django Templates
### Example 1:
>>> format_eval("Hello {{ 'world'.upper() }}")
'Hello WORLD'
### Example 2:
>>> import requests
>>> format_eval("Request to Google: Code {{ requests.get('https://google.com').status_code) }}")
'Request to Google: Code SyntaxError'
>>> format_eval("Request to Google: Code {{ requests.get('https://google.com').status_code }}")
'Request to Google: Code 200'

One-Liner Telegram Bot (Using python-telegram-bot)

A simple Telegram bot that responds to the /start command with a basic text message.

This is just for fun and not a proper way to develop Telegram bots.

First, install the python-telegram-bot package:

python install -U python-telegram-bot
@MohammadHosseinGhorbani
MohammadHosseinGhorbani / godot-telegram-game-article.md
Last active October 11, 2024 05:09
Making a Telegram game with Godot

Telegram Games

Telegram is a powerful messenger app with many features; such as games! You can use a Telegram bot and an HTML5 page to share your game in Telegram. The main part of this thing is the HTML5 web page that is your game, Telegram is used to share your game and record the players' score. We will use Godot for the HTML5 part, and Python for the Telegram bot.

Telegram bots can be created using any programming language, therefore Python is not a requirement.

You can read more about Telegram games here.

Let's get started!

The Telegram Bot

@MohammadHosseinGhorbani
MohammadHosseinGhorbani / dirty-brainfuck-interpreter.py
Created March 10, 2024 21:20
Dirtiest Brainfuck Interpreter I've Ever Seen (But It Works)
memory = [0]
pointer = 0
loop = False
loop_start = 0
loop_point = 0
bf_code = '<BRAINFUCK CODE>'
def check_char(char):
global memory, pointer
@MohammadHosseinGhorbani
MohammadHosseinGhorbani / conversation.py
Last active May 8, 2024 09:10
Conversations in pyrogram (no extra package needed)
from pyrogram import Client, filters
app = Client('CONVERSATION_EXAMPLE')
conversations = {}
infos = {}
def conv_filter(conversation_level):
def func(_, __, message):
return conversations.get(message.from_user.id) == conversation_level