Skip to content

Instantly share code, notes, and snippets.

View ankona's full-sized avatar
🏠
Working from home

Chris McBride ankona

🏠
Working from home
View GitHub Profile
@ankona
ankona / gen_config.py
Last active January 18, 2023 23:27
pseudocode for generic config loading from single datasource
from typing import Generic, TypeVar, Union, Optional, Dict, Type, Any
from enum import Enum
from pydantic import BaseModel
from fastapi import APIRouter, FastAPI
T = TypeVar('T')
class ConfigType(str, Enum):
app = "ac"
@ankona
ankona / simplecfg.py
Last active October 13, 2021 05:30
simple cfg
import os
from typing import Tuple, Dict
class TypeConverter(object):
def as_boolean(self, value: str) -> object:
bool_strings = ['true', 'on', 'yes', 'false', 'off', 'no']
if value.lower() in bool_strings[:len(bool_strings)//2]:
return True
if value.lower() in bool_strings[len(bool_strings)//2:]:
@ankona
ankona / fib.py
Last active October 7, 2021 21:38
determiine if input list is a valid subsection of the fibonacci sequence
from typing import List
from collections.abc import Iterable
def generate_fib(start=None, stop=None) -> List[int]:
last, value = 0, 1
while True:
if stop and value > stop:
break
if not start or value > start:
@ankona
ankona / parenthetic_expr.py
Last active October 1, 2021 20:56
Determine if the special characters in the incoming string are valid parenthetical expressions
def is_valid(s: str) -> bool:
"""
Determine if the special characters in the incoming string are valid parenthetical expressions
:param s:
:return:
"""
# ( [ ( ) ]
brackets_q = []
spec_lhs, spec_rhs = ['(', '{', '['], [')', '}', ']']
@ankona
ankona / n_queens.py
Created September 15, 2021 02:08
scoring an n-queens board
def n_queens_attacks(board_state: str) -> int:
max_attack_num = 28
attacks = 0
# count horizontal attacks
c = Counter(board_state)
overlap = {k: v for k, v in c.items() if v > 1}
for k, v in overlap.items():
v_prime = v - 1
@ankona
ankona / postman_auth_req.js
Created July 20, 2021 19:34
postman pre-request script for refreshing auth token
const tokenUrl = 'https://signin.XXX.com/connect/token';
const clientId = '<client-id>';
const clientSecret = '<client-pw>';
const username = 'domain\\<your-uid-here>'; // insert
const pw = pm.globals.get("mypw");
const grant_type = 'password';
const scopes = 'openid email profile exprofile roles xxx-api';
const getTokenRequest = {
@ankona
ankona / CS7280.yml
Last active May 21, 2021 03:34
Conda Env Config For CS7280
# Execute using: conda env create -f CS7280.yml
name: CS7280
dependencies:
- python=3.9.5
- matplotlib=3.3.4
- numpy=1.20.2
- scipy=1.6.2
- networkx=2.5.1
- seaborn=0.11.1
- conda-forge::nb_conda
@ankona
ankona / get_query_plans.sql
Created May 4, 2021 15:51
get some poorly performing queries & their query plans
-- Thanks to: https://blobeater.blog/2019/11/20/execution-plans-in-azure-sql-database/
SELECT top 10 (total_logical_reads/execution_count) as ReadsPerExec,
(total_logical_writes/execution_count) as WritesPerExec,
(total_physical_reads/execution_count) PhyReadsPerExec,
Execution_count, sql_handle, plan_handle, total_worker_time
FROM sys.dm_exec_query_stats
ORDER BY (total_logical_reads + total_logical_writes) Desc
SELECT * FROM sys.dm_exec_query_plan (0x060028007491E823E0C7342EC101000001000000000000000000000000000000000000000000000000000000)
@ankona
ankona / morphing.py
Created February 19, 2021 04:37
updated version of morphing.py for cs6475
"""Morphing one image to another based on specified control points."""
import os
import datetime
import numpy as np
import cv2
# from matplotlib.tri.delaunay import delaunay # for triangulation
# from matplotlib.tri import Triangulation
from scipy.spatial import Delaunay
@ankona
ankona / Userscript.user.js
Last active February 6, 2021 04:38
tampermonkey - allow wider canvas video resize
// ==UserScript==
// @name Canvas Video Resize
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Allow the video to resize as large as browser resizes.
// @author You
// @match https://gatech.instructure.com/courses/*
// @grant none
// ==/UserScript==