Skip to content

Instantly share code, notes, and snippets.

View RaiAnsar's full-sized avatar
🤨
Focusing

Rai Ansar RaiAnsar

🤨
Focusing
View GitHub Profile
@RaiAnsar
RaiAnsar / README.md
Last active November 19, 2026 03:17
Check a website migration 301 redirect map from a CSV (Python, stdlib only)

Check a migration redirect map before and after launch

When a site moves host, platform or URL structure, each old URL needs a 301 straight to its new address. The usual failures are quiet: a 302 left in from testing, a chain of three hops through an old HTTP rule, a redirect that lands on the home page, or a new page that returns 404. Search engines and visitors both pay for those.

check_redirects.py reads a two-column CSV (old_url,new_url), requests every old URL without following redirects, then follows the chain itself and labels each row OK, CHAIN, TEMP, WRONG, NO-REDIR or BROKEN. It exits 1 if anything is not OK, so it can run in CI after a deploy. Standard library only, Python 3.8+.

python3 check_redirects.py redirects.example.csv
@RaiAnsar
RaiAnsar / README.md
Created October 21, 2026 22:03
Even-pace race splits that add up exactly to the finish time (Python)

Race splits that add up to your finish time

A pace calculator that rounds each split on its own drifts. For a 4:00:00 marathon split every 5 km, each split is 28:26.16; eight rounded 28:26 splits plus a rounded 12:29 for the last 2.195 km come to 3:59:57, three seconds short.

The fix is to round the elapsed time at each checkpoint (finish time x checkpoint distance / race distance) and take each split as the gap between checkpoints. Splits then alternate between 28:26 and 28:27 and the last checkpoint is exactly 4:00:00.

even_splits.py has the pace maths (per km, per mile, km/h, mph) and the split table, with checks for the marathon example. No dependencies.

The split tables and printable pace bands on Race Pace Planner give the same checkpoint times, and also cover negative and positive splits and run/walk plans for any distance.

@RaiAnsar
RaiAnsar / README.md
Created October 21, 2026 22:02
Validate Australian ABN and ACN check digits in Python and JavaScript

ABN and ACN check digit validation (Python and JavaScript)

Two small functions that tell you whether an Australian Business Number (11 digits) or Australian Company Number (9 digits) is well formed, before you call any API. Spaces and dashes are accepted, so 51 824 753 556 and 51824753556 both work.

A number that passes is only correctly formed. It can still be cancelled, belong to someone else or not be registered for GST. To check the live record, use the Australian Business Register, or [verifyabn.com](https://verify

@RaiAnsar
RaiAnsar / dhl-price-override.php
Last active August 9, 2025 01:17
DHL Labels Price Override
<?php
/**
* Plugin Name: MT DHL Label Price Override
* Description: Overrides product prices on DHL labels for specific countries
* Version: 2.0.0
* Author: Rai Ansar
*/
if (!defined('ABSPATH')) {
exit;
@RaiAnsar
RaiAnsar / BUILD_YOUR_OWN_MCP_SERVER.md
Created June 10, 2025 21:38
Claude_Code-Gemini-MCP

Building Your Own MCP Server for Claude Code

This guide will walk you through creating a custom MCP (Model Context Protocol) server that integrates with Claude Code, allowing you to extend Claude's capabilities with external tools, APIs, or even other AI models.

What is MCP?

MCP (Model Context Protocol) is a protocol that allows Claude to communicate with external servers to access tools and capabilities beyond its built-in features. Think of it as a plugin system for Claude.

Prerequisites