Skip to content

Instantly share code, notes, and snippets.

View e2thenegpii's full-sized avatar

Thomas Eldon Allred e2thenegpii

View GitHub Profile
@e2thenegpii
e2thenegpii / com_fetcher.cpp
Created September 17, 2022 17:35
Code invoke a generic com-esk object function and overload the return value in the case of a BSTR
#include <functional>
#include <memory>
#include <iostream>
#include <tuple>
static constexpr const char* strval = "The quick brown fox jumps over the lazy dog";
using BSTR = const char*;
struct foo1
{
@e2thenegpii
e2thenegpii / download.py
Created August 20, 2021 04:38
combine packaging and aiohttp to discover valid distributions
import asyncio
from contextlib import closing
from typing import Iterator, Dict, Set, AsyncIterator, Iterable, Mapping, Container
from urllib.parse import urlparse, urlunparse
from collections import defaultdict
from pprint import pprint
import aiohttp
from packaging.requirements import Requirement
@e2thenegpii
e2thenegpii / Dockerfile
Last active August 12, 2021 04:07
Build pythonnet for cp37-cp37m-linux_x86_64.whl
FROM mono:6.12.0 AS build
ENV PYTHONNET_VER=2.5.2
# Install all the things necessary to build pythonnet
RUN apt update && apt install python3.7 python3-pip python3.7-dev clang g++ gcc -y
# Setup the python environment
RUN python3 -m pip install -U pip setuptools wheel pycparser
# Build the pythonnet wheel
RUN python3 -m pip wheel pythonnet==$PYTHONNET_VER
@e2thenegpii
e2thenegpii / enumfun.py
Created November 20, 2020 02:34
A python enumeration usable as a singledispatch
"""
I often find myself parsing buffers that contain typed buffers of data.
Python enumerations are great. I love to use them to map symantic names
onto a collection of values. However they often are lacking in performing
actions based on the enumerant. Typically I have to do something like
the following
class foo(enum.Enum):
a = 1
b = 2
@e2thenegpii
e2thenegpii / example.cpp
Created September 2, 2020 04:15
pybind11 getting arguments in c++
#include <pybind11/pybind11.h>
namespace py = pybind11;
template<typename T>
T get_argument(const char* name, int& index, const py::args& args, const py::kwargs& kwargs)
{
if(kwargs.contains(name))
{
return kwargs[name].cast<T>();
@e2thenegpii
e2thenegpii / supplychain-interdiction.py
Last active June 29, 2020 02:59
Demonstration of a custom python package resource loader
# Needed for defining the finder
import importlib.machinery
# Needed to add our hook to the meta_path hook list
import sys
# To debug with pdb.set_trace() be sure to import the following before adding the meta_path
import pdb
import readline
#!/bin/bash
# http://www.nongnu.org/avr-libc/user-manual/install_tools.html
# For optimum compile time this should generally be set to the number of CPU cores your machine has
JOBCOUNT=4
# Build Linux toolchain
# A Linux AVR-GCC toolchain is required to build a Windows toolchain
# If the Linux toolchain has already been built then you can set this to 0
@e2thenegpii
e2thenegpii / password_proxy.py
Last active December 13, 2018 13:41
password proxy
import argparse
import getpass
def password_proxy(value):
password_proxy.prompt = 'Default password prompt:'
class _password_proxy(str):
def __new__(cls, value):
obj = str.__new__(cls, value)
obj._context = password_proxy
@e2thenegpii
e2thenegpii / tdameritrade.py
Last active November 17, 2018 18:12
small script to take price data from tdameritrade and put it into a gnucash mysql database intended to run on a mysql server without gnucash installed
#!/usr/bin/env python
#pip install piecash requests pandas_market_calendars MySQL
import argparse
import piecash
import requests
import datetime
import decimal
import pandas_market_calendars as mcal
import numpy as np
@e2thenegpii
e2thenegpii / main.c
Created May 4, 2018 04:24
String obsfucation via MMX instructions
#include <stdio.h>
#include <xmmintrin.h>
#include <stdint.h>
/**
* Converts a string from a format where bit 7 of 8 characters form the first
* byte in a uint64_t, bit 6 of 8 characters form the second byte and so on
* in a simple attempt to obsfucate strings encoded as integers.
*
* @param data The string to destripe