Skip to content

Instantly share code, notes, and snippets.

/* This is bad. Reaaly bad. It's a really, really bad hack. If you're an employee of
* Intertrode Communication, then I'm really, really sorry that you have to maintain
* this. I was honestly planning on removing this tomorrow, but I've been known to
* forget things like this. It happens.
*
* So here's the thing. I can't seem to figure out why the AccountId variable isn't
* set. I've looked and looked, but I gotta leave now. Anyway, I've found that I can
* just grab the AccountID from the debugging logs. I suppose that to fix it, you'd
* have to locate where it's clearing out the ID.
*
@ivangeorgiev
ivangeorgiev / test_users_url.py
Created April 29, 2023 12:54
pytest assertion helper
from operator import itemgetter
import pytest
from django.urls import reverse
from django.contrib.auth.models import User
from rest_framework import status
def assert_response_userlist_equals(response, users):
@ivangeorgiev
ivangeorgiev / get_access_token.py
Last active April 26, 2023 07:52
Get Access Token for Managed Identity from Azure App Service
import requests
from os import environ
key_vault_name = "<key-vault-name-here>"
secret_name = "<secret-name-here>"
token_params = {"resource": "https://vault.azure.net", "api-version": "2019-08-01"}
token_response = requests.get(
environ["IDENTITY_ENDPOINT"],
params=token_params,
@ivangeorgiev
ivangeorgiev / loop-over-data-file.postman_collection.json
Last active March 24, 2023 07:44
Loop Over Data File Postman Collection
{
"info": {
"_postman_id": "ef0a1444-9fe4-4798-91ce-5febefd02bba",
"name": "Loop Over Data File",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
"_exporter_id": "7243476"
},
"item": [
{
"name": "Do Post",
@ivangeorgiev
ivangeorgiev / smallest_window_to_sort.py
Last active March 14, 2023 18:52
Parameterize Python unittest tests
'''
# Smallest window to sort kata
## Kata
Given an array of integers that are out of order, determine the bounds of the smallest
window that must be sorted in order for the entire array to be sorted. For example,
given `[ 3 , 7 , 5 , 6 , 9]` , you should return `( 1 , 3 )` .
## Test cases:
@ivangeorgiev
ivangeorgiev / _auth.py
Created January 24, 2023 18:51
Simple Authentication Helper - Python
"""
Synopsis
---------
```python
scheme = (
Scheme()
.add_permission(Permission("canteen.eat.fruit"))
import time
def print_fib(number: int) -> None:
def fib(n: int) -> int:
if n == 1:
return 1
if n == 2:
return 1
return fib(n-1) + fib(n-2)
print(f'fib({number}) is {fib(number)}')
@ivangeorgiev
ivangeorgiev / README.md
Last active January 11, 2023 15:06
Python Subclass Factory

Python Subclass Factory

How to implement subclass-based plugin architecture? How to handle polymorphism from persisted data?

@ivangeorgiev
ivangeorgiev / README.md
Last active October 21, 2022 15:00
Dynamic Method Binding in Python

Dynamic Method Binding in Python

@ivangeorgiev
ivangeorgiev / README.adoc
Last active October 21, 2022 13:49
Track created class instances in registry

Class Instance Registry with Python Class Decorator

Getting the source code:

$ git clone https://gist.github.com/ivangeorgiev/204c8e0310c2a7eea07970eae824f3a1 class-decorator-example
...
$ cd class-decorator-example