Skip to content

Instantly share code, notes, and snippets.

@dustinandrews
dustinandrews / bsp.py
Created October 24, 2019 21:26
Binary Space Partitioning didactic example in Python
# -*- coding: utf-8 -*-
"""
Pure Python 3.6 example of doing binary space partioning for rectangles
Note the example is meant to be illustrative rather than performant, idiomatic or compact
Copyright 2019 Dustin Andrews
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
@dustinandrews
dustinandrews / windows_screen_grab_and_scale.py
Last active June 14, 2017 18:26
A fast way to use win32ui and win32gui to capture screens from applications in Microsoft Windows and scale them using StretchBlt.
import win32ui
import win32gui
import win32con
import numpy as np
from matplotlib import pyplot as plt
"""
Search open windows programs for a title containing the search_str
and set hwnd
class Bandit:
def __init__(self,arms : int):
self.arms = []
for i in range(arms):
self.arms.append(np.random.rand())
self.action_count = arms
def step(self, action: int):
reward = 0
@dustinandrews
dustinandrews / NLTKClassifyTexts.py
Created May 3, 2017 23:04
This is my first foray into machine learning. Using Bag-of-words to train a sentiment classifier. The code is organized more or less like a notebook. Hopefully it's easy to follow.
from gensim.models.word2vec import Word2Vec
from gensim import corpora, models, similarities
from gensim.models.phrases import Phrases
import numpy as np
import logging
logging.basicConfig(format='%(asctime)s : %(levelname)s : %(message)s', level=logging.INFO)
from sklearn.metrics import roc_curve, auc
import matplotlib.pyplot as plt
import re
import codecs