This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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('{') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
""" | |
dbus-send --session --dest=com.example.HelloService \ | |
--type=method_call --print-reply \ | |
/com/example/HelloService org.freedesktop.DBus.Introspectable.Introspect | |
dbus-send --session --dest=com.example.HelloService \ | |
--type=method_call --print-reply \ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask, request, jsonify | |
from datetime import datetime | |
app = Flask(__name__) | |
@app.route('/') | |
def root(): | |
return jsonify({ | |
'message': 'Welcome to the Hello Service', | |
'endpoints': { |
NewerOlder