Skip to content

Instantly share code, notes, and snippets.

View monperrus's full-sized avatar

Martin Monperrus monperrus

View GitHub Profile
@monperrus
monperrus / terms.txt
Created October 19, 2025 08:08
Immunefi – Security Researchers Terms & Conditions Oct 19 2025
Immunefi -- Security Researchers Terms & Conditions (Clickwrap
Agreement)
As a condition of your participation in Immunefi's Bug Bounty Programs,
including the submission of bug reports, you agree to be bound by the
following terms and conditions.  If you do not agree to these terms and
conditions you should not submit any bug report or access the Immunefi
Platform for any purpose.
1. Definitions
@monperrus
monperrus / colors.py
Created March 20, 2025 14:27
a python program that outputs a colored loren ipsum with ASC II color sequences.
import random
def get_random_color_code():
"""Generate a random ANSI color code between 31-36 (red, green,
yellow, blue, magenta, cyan)"""
return random.randint(31, 36)
def colorize_text(text, color_code):
"""Apply ANSI color code to text"""
return f"\033[{color_code}m{text}\033[0m"
@monperrus
monperrus / document_file.py
Created March 16, 2025 10:30
write a python program that parses another python program, summarizes the full file, replace the module docstring and rewrite the program
import ast
import astor
class DocstringReplacer(ast.NodeTransformer):
"""AST Node Transformer to replace module docstring."""
def visit_Module(self, node):
"""Visit Module node and replace docstring."""
# Replace docstring
@monperrus
monperrus / pace.py
Created March 16, 2025 10:30
a python program to compute pace min/kilo from a tcx file
import xml.etree.ElementTree as ET
from datetime import datetime
import math
import sys
def parse_tcx_file(tcx_file):
"""Parse TCX file and return trackpoints with time and distance"""
# Create namespace dictionary for TCX format
ns = {'ns': 'http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v2'}
@monperrus
monperrus / merge-laps.py
Created March 16, 2025 10:30
a python script to merge all activities in a tcx file
import xml.etree.ElementTree as ET
from datetime import datetime, timedelta
import sys
def merge_tcx_activities(input_file, output_file):
# Parse the input TCX file
tree = ET.parse(input_file)
root = tree.getroot()
nspace = root.tag.split('}')[0].strip('{')
@monperrus
monperrus / in_canada.py
Created March 16, 2025 10:30
go over all tx files, if the tcx coordinates are in canada, print the file name
import os
import xml.etree.ElementTree as ET
import glob
def is_in_canada(lat, lon):
# Rough boundaries for Canada
# Latitude: Between 41.7° and 83.1° N
# Longitude: Between -141.0° and -52.6° W
return (41.7 <= float(lat) <= 83.1) and (-141.0 <= float(lon) <= -52.6)
@monperrus
monperrus / repos.py
Created March 16, 2025 10:30
iterate over all repos of a github organization in python
from github import Github
# First create a Github instance using an access token
g = Github("98b9ad24ffc7df18d14c9943eef3700e1b3958c5")
# Then get the organization by its name
org = g.get_organization("chains-project")
# Then iterate over all repos in the organization
for repo in org.get_repos():
@monperrus
monperrus / t-sne.py
Created March 16, 2025 10:30
t-sne visualization in python, with tooltips on points
import numpy as np
from sklearn.manifold import TSNE
import plotly.express as px
import pandas as pd
import glob
import json
# Sample data - replace with your own dataset
# data = np.random.rand(100, 20) # 100 samples, 20 features
@monperrus
monperrus / example-hash.py
Created March 16, 2025 10:30
python compute a hash of file and sign it with cryptography.hazmat
import os
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.asymmetric import rsa, padding
from cryptography.hazmat.primitives.serialization import (
Encoding, PrivateFormat, PublicFormat, NoEncryption
)
def generate_key_pair():
"""Generate an RSA key pair."""
private_key = rsa.generate_private_key(
@monperrus
monperrus / example-fastapi.py
Created March 16, 2025 10:30
a running example of a fastapi server
# fully functional example of fastapi
# # Create an item
# curl -X POST "http://localhost:8000/items/" -H "Content-Type: application/json" -d '{"id": 1, "name": "Test Item", "price": 9.99}'
# # Get all items
# curl "http://localhost:8000/items/"
# # Get specific item
# curl "http://localhost:8000/items/1"