Skip to content

Instantly share code, notes, and snippets.

View bahostetterlewis's full-sized avatar

Barrett bahostetterlewis

  • Zscaler
  • Chico, California
View GitHub Profile
@bahostetterlewis
bahostetterlewis / Levenshtein-Damerau
Last active December 12, 2015 08:38
Levenshtein-Damerau, found originally in my sublime text 2 gist account (giststhebearbear) This is a memory/time optimized solution of the Levenshtein-Damerou distance algorithm. There are some non idiomatic things in the code, but it is pure standard python and can be used freely by anyone.
def leven(s1, s2, maxDistance):
# get smallest string so our rows are minimized
s1, s2 = (s1, s2) if len(s1) <= len(s2) else (s2, s1)
# set lengths
l1, l2 = len(s1), len(s2)
# We are simulatng an NM matrix where n is the longer string
# and m is the shorter string. By doing this we can minimize
# memory usage to O(M).
# Since we are simulating the matrix we only maintain two rows
@bahostetterlewis
bahostetterlewis / undo-redo-proof.py
Last active December 14, 2015 11:19
Proof of concept for an undo and redo function using python functions. This is for use in the pyrrhic-ree project. By using properties it is possible to build the undo stack just by setting the string. Once a stack is built calling the undo function builds a redo stack that is emptied once a person decides to type manually. I don't think there i…
class Proof:
def __init__(self):
self._redo = []
self._undo = []
self._mystr = ''
def mystr():
def fget(self):
return self._mystr
import win32api, win32con, time
def click(x, y):
win32api.SetCursor((X,y))
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,x,y,0,0)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,x,y,0,0)
def clean():
click(1050, 200)
click(1050, 220)
@bahostetterlewis
bahostetterlewis / pingalert.py
Last active December 16, 2015 16:49
My internet sucks and randomly cuts out. This lets me know when I'm connected again. simple and sweet so I don't have to ever type ping again.
import winsound
from subprocess import call, DEVNULL
print('Begin Ping Alert')
while call(["ping", "google.com"], stdout=DEVNULL, stderr=DEVNULL) != 0:
print('No net yet :(')
print('Web Back!!!')
@bahostetterlewis
bahostetterlewis / git_aliases.txt
Last active December 17, 2015 00:19
useful git shit
git config --global alias.ignorechanges = update-index --assume-unchanged
git config --global alias.noticechanges = update-index --no-assume-unchanged
@bahostetterlewis
bahostetterlewis / update-pip-advanced.py
Last active September 29, 2016 07:45
Update all pip packages!
#!/usr/bin/env python
import os
import pip
dists = []
for dist in pip.get_installed_distributions():
dists.append(dist.project_name)
for dist_name in sorted(dists, key=lambda s: s.lower()):
@bahostetterlewis
bahostetterlewis / main.py
Last active December 27, 2015 18:09
AI Question 2 multivariat regression CSCI 580
xs, ys, ws = [None, [1, 1, 2], [1, 2, -1], [1, 5, -2], [1, 3, -1], [1, 8, 2]], [None, -13, -4, 5, 0, 1], [1, 1, 1]
alpha = .01
def h(j):
return (ws[0] * xs[j][0]) + (ws[1] * xs[j][1]) + (ws[2] * xs[j][2])
def inner(inner_i):
return (xs[inner_j][inner_i] * (ys[inner_j] - hs[inner_j]) for inner_j in range(1, len(xs)))
@bahostetterlewis
bahostetterlewis / func_member_ptrs.cpp
Last active August 29, 2015 13:56
Creating a map of member functions example
#include <iostream>
#include <map>
using namespace std;
class node{
public:
node(int val){this->val = val; }
int val;
};
@bahostetterlewis
bahostetterlewis / shared_folder_mount
Created January 20, 2015 18:59
This is how to mount a shared folder with write permissions in Ubuntu
sudo mount -t vboxsf -o rw,uid=1000,gid=1000,dmode=755,fmode=644 <sf name> <mount point>