Skip to content

Instantly share code, notes, and snippets.

View Exchizz's full-sized avatar

Mathias Neerup Exchizz

View GitHub Profile
import requests
import json
import boto3
from bs4 import BeautifulSoup
from pprint import pprint
from datetime import datetime
# This code signs-in to Cost Explorer so that Reports can be created programmatically
# (At the moment of writing, this is not supported via officiel API)
# For some reasy, creating/updating reports requires different credentials than boto3-credentials obtains. Trying to create # a report fails with "status: 400".
@Exchizz
Exchizz / main.py
Created December 10, 2024 15:10
Assign Service Principal (application registration) subscription creator on enrollment account
import requests
from azure.identity import DefaultAzureCredential
# If you are trying to create a subscription in terraform running as a Service Principal, you might run into the following error:
# subscription.AliasClient#Create: Failure sending request: StatusCode=401 – Original Error: Code="UserNotAuthorized" Message="User is not authorized to create subscriptions on this enrollment account"
# Most help you'll find online will send you to this link:
# https://learn.microsoft.com/en-us/azure/cost-management-billing/manage/assign-roles-azure-service-principals
# This script grants a service principal access to a billing account using the Azure Management API
# This script assumes you are logged in locally (with az login) as a user with proper permissions.
@Exchizz
Exchizz / customenum.py
Created April 22, 2021 19:17
Python3.8 enum metaclass that supports inheritance (used in django 3.2)
class CustomMetaEnum(type):
def __new__(self, name, bases, namespace):
fields = {}
fields = {key:value for key, value in namespace.items() if isinstance(value, int)}
for base in bases:
fields.update(base._fields)
namespace['_fields'] = fields
@Exchizz
Exchizz / kafka_latency.py
Created February 13, 2020 13:42
kafka latency tester
#!/user/bin/python3.8
from kafka import KafkaConsumer, KafkaProducer, KafkaAdminClient
from datetime import datetime, date
from time import sleep, monotonic_ns
import argparse
import json
parser = argparse.ArgumentParser()
parser.add_argument("-b", "--kafka_broker", help="Set ip/hostname to kafka broker, host:port", type=str, required=True)
@Exchizz
Exchizz / logitec_spotlight_vibrator.py
Last active November 28, 2019 22:00
Logitech spotlight vibrator PoC written in python with pyusb
import usb.core
import usb.util
import sys
from pprint import pprint
# find our device with lsusb
# 046d:c53e
dev = usb.core.find(idVendor=0x046d, idProduct=0xc53e)
# was it found?
@Exchizz
Exchizz / downloadandextract.sh
Last active February 21, 2023 00:08
Proof-of-concept on how "docker-pull" works
#!/bin/bash
# Based on the following question from stack-exchange:
# https://devops.stackexchange.com/questions/2731/downloading-docker-images-from-docker-hub-without-using-docker
# Get token
TOKEN="$(curl --silent --header 'GET' "https://auth.docker.io/token?service=registry.docker.io&scope=repository:library/ubuntu:pull" | jq -r '.token')"
# Get manifest
echo "Manifest: "
#define _GNU_SOURCE
#include <sched.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
@Exchizz
Exchizz / docker-compose.yml
Created July 4, 2019 18:35
Docker haproxy
version: '2'
volumes:
mysql:
services:
gitlab_app:
image: gitlab/gitlab-ce:11.9.0-ce.0
#!/usr/bin/env python
from __future__ import print_function, absolute_import, division
import logging
import mysql.connector
from errno import ENOENT
from stat import S_IFDIR, S_IFREG
from time import time
#!/usr/local/bin/python
# Example of TCP's threeway handshake using python and scapy
# source: https://www.fir3net.com/Programming/Python/how-to-build-a-tcp-connection-in-scapy.html
# Requires:
# iptables -A OUTPUT -p tcp --tcp-flags RST RST -j DROP
# Otherwise the kernel will send a TCP RESET as the kernel is not aware of TCP connection going on.
from scapy.all import *