Skip to content

Instantly share code, notes, and snippets.

View imankulov's full-sized avatar

Roman Imankulov imankulov

View GitHub Profile
You are a powerful agentic AI coding assistant, powered by GPT-4o. You operate exclusively in Cursor, the world's best IDE.
You are pair programming with a USER to solve their coding task.
The task may require creating a new codebase, modifying or debugging an existing codebase, or simply answering a question.
Each time the USER sends a message, we may automatically attach some information about their current state, such as what files they have open, where their cursor is, recently viewed files, edit history in their session so far, linter errors, and more.
This information may or may not be relevant to the coding task, it is up for you to decide.
Your main goal is to follow the USER's instructions at each message.
<communication>
1. Be conversational but professional.
@imankulov
imankulov / fastapi_dependencies.py
Last active March 3, 2023 09:53
FastAPI service with and without dependencies
"""
A simple contrived example of a FastAPI application that heavily uses
the FastAPI dependency injection system.
Sample request http://127.0.0.1:9876/tasks?user_id=123456
returns [{"id":1,"name":"Task 1","user":{"id":123456,"name":"John Doe"}}]
Dependency tree:
get_me()
@imankulov
imankulov / default_session.py
Created January 6, 2023 21:57
A Python request.Session() instance with reasonable defaults for retries.
import requests
from requests.adapters import HTTPAdapter
from urllib3.util.retry import Retry
USER_AGENT = "My project (https://example.com)"
def get_default_session() -> requests.Session:
"""Return a request.Session() instance with reasonable defaults for retries.
@imankulov
imankulov / README.md
Last active September 21, 2024 10:28
Parse JSON-encoded parameters from request queries with FastAPI

Problem: FastAPI doesn't accept JSON-encoded pydantic models in query strings. See #884.

Solution: Use json_param() from the snippet below.

Usage example.

from fastapi import FastAPI
from pydantic import BaseModel
@imankulov
imankulov / sqlalchemy_with_pydantic.py
Last active March 10, 2025 10:05
Using pydantic models as SQLAlchemy JSON fields (convert beween JSON and pydantic.BaseModel subclasses)
#!/usr/bin/env ipython -i
import datetime
import json
from typing import Optional
import sqlalchemy as sa
from sqlalchemy.orm import declarative_base, sessionmaker
from sqlalchemy.dialects.postgresql import JSONB
from pydantic import BaseModel, Field, parse_obj_as
@imankulov
imankulov / cpython.geojson
Last active November 4, 2021 22:50
CPython file type codemaps exported as GeoJSON
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
  • Who is your craziest/most interesting relative?
  • What’s a weird fact you happen to know?
  • What’s your strangest talent?
  • Everyone has those recurring bad dreams … what is your nightmare?
  • What is your favorite smell and why?
  • What completely safe animal are you inexplicably afraid of?
  • What do you pretend to hate but actually love?
  • If you had a boat, what would you name it?
  • What was your first job?
  • Have you ever met anyone famous?
@imankulov
imankulov / cron.sh
Created December 16, 2020 15:47
A cron script to send Telegram notifications about the new menu
menu=$(curl -s 'https://www.facebook.com/SambaNaGrelha' | \
rg -o 'Bom dia estimados clientes hoje para prato do dia temos.*?Fazemos entregas ao domicílio' | \
head -n1 | html2text)
curl -s "https://api.telegram.org/bot$BOT_ID/sendMessage?chat_id=$CHAT_ID" -d text="$menu" > /dev/null
@imankulov
imankulov / 00_stakoverflow_questions.py
Last active August 19, 2020 12:47
Analyze the percentage of the topic-specific StackOverflow questions for each programming language
#!/usr/bin/env python
"""
An ad-hoc script to analyze the percentage of the topic-specific questions for
each programming language.
For each language, the script downloads two pages and looks for the number of questions
in the title, like "NNN,NNN questions". For example, for "python" and
an extra tag "architecture", the script downloads
https://stackoverflow.com/questions/tagged/python and
https://stackoverflow.com/questions/tagged/python+architecture.
@imankulov
imankulov / quote.py
Created February 17, 2019 18:25
Generating documents from Google Sheets with Python
import pandas as pd
from docxtpl import DocxTemplate
SHEET_URL='https://docs.google.com/spreadsheets/d/1Kvb5bmm2qZWEH4I5hJYZMEuIBU-CCw_ivyv_jjB1w4w/export?exportFormat=csv'
TEMPLATE = 'quote.docx'
def save_quote(quote_id):
df = pd.read_csv(SHEET_URL, index_col='QuoteID')
context = dict(df.loc[quote_id])
doc = DocxTemplate(TEMPLATE)