Skip to content

Instantly share code, notes, and snippets.

@rajrao
rajrao / fastmcp_3x_key_based_auth.py
Last active February 13, 2026 15:48
Key based auth for FastMCP 3.0
import logging
import os
from fastmcp.server.middleware import Middleware, MiddlewareContext
from fastmcp.server.dependencies import get_http_headers
from starlette.responses import JSONResponse
_logger = logging.getLogger(__name__)
class AuthKeyMiddleware(Middleware):
@rajrao
rajrao / calendar_instructions_and_examples.md
Created February 8, 2026 22:43
From powerbi-modeling-mcp.exe (0.19.1) calendar_instructions_and_examples.md
name description uriTemplate
Calendar Instructions and Examples
Guidelines for creating Power BI calendar objects
resource://calendar_instructions_and_examples

Calendar Column Groups Guide

This guide explains how to define calendar column groups in a Power BI date table so time intelligence works as expected and consistently across models.

Concepts

Mermaid

    F[👆 First Touch<br/>26.7%]:::green 
    L[📝 Lead Creation<br/>26.7%]:::orange 
    O[💼 Opportunity Creation<br/>26.7%]:::purple 
    
    M1[🔄 Middle Touches<br/>10%]:::red
    I1[📢 Impression<br/>10%]:::blue 
    M2[🔄 Middle Touches<br/>10%]:::red
 I2[📢 Impression10%]:::blue 
@rajrao
rajrao / python_request_debugging.py
Last active November 25, 2024 22:21
Python 3.x debug data being sent as part of a request and the response info
from requests_toolbelt.utils import dump
headers = {'Content-Type': 'application/json'}
response = requests.post(
url,
headers=headers,
json=jdata,
)
print(dump.dump_all(response).decode("utf-8"))
@rajrao
rajrao / current_working_directory.py
Created June 28, 2024 13:45
Current Working Directory
import os
cur_working_dir = os.path.join(os.getcwd(), os.path.dirname(__file__))
print(cur_working_dir)
import timeit
from pprint import pprint
setup = '''
from string import Template
s = "the quick brown fox JUMPED OVER THE"
t = "LAZY DOG'S BACK 1234567890"
'''
iter = 1
baseline = timeit.timeit("f'{s} {t}'", setup, number=iter)

The following query allows you to search for a requestid and get a link to the event (which is obtained by adding @log to the query)

fields @timestamp as Timestamp, @message, @logStream as LogStream, @log
| filter(@requestId = '09d10d9b-e8e0-46fa-ad9e-01a00c87d221')
| sort @timestamp desc
| limit 10

Get stats about a certain kind of message

def get_backoff_w_jitter(attempt: int, max_backoff: int = 20) -> int:
"""returns the wait time for a backoff for attempt # attempt
algorithm: truncated binary exponential backoff with jitter
src: https://docs.aws.amazon.com/sdkref/latest/guide/feature-retry-behavior.html
Arguments:
attempt -- the attempt # for calculating the backoff. a number >= 0
Returns:
the backoff amount (usually used as seconds to sleep)
@rajrao
rajrao / exponential_backoff_with_jitter.py
Created October 19, 2023 04:52
Exponential Backoff with Jitter as used by Airflow Sensors
# based on https://github.com/apache/airflow/blob/9ac742885ffb83c15f7e3dc910b0cf9df073407a/airflow/sensors/base.py#L251C13-L251C13
import hashlib
from datetime import datetime, timedelta
from time import sleep
poke_interval = 5 # Time in seconds that the job should wait in between each tries
timeout = 60 # Time, in seconds before the task times out and fails.
started_at = datetime.now()
sleep(1)
exponential_backoff = True
@rajrao
rajrao / SpiralUsingTurtle.py
Created October 1, 2023 11:24
Spiral using turle
# from https://twitter.com/clcoding/status/1708436006154785209?t=WNPxLM7Ox33QEVxUfRH-5w&s=19
import random
import turtle
colors = ['red', 'cyan', 'pink', 'yellow', 'green', 'orange']
t = turtle.Turtle()
t.speed(10)
turtle.bgcolor("black")
length=100
angle=50