Skip to content

Instantly share code, notes, and snippets.

View tommct's full-sized avatar

Tom McTavish tommct

View GitHub Profile
@tommct
tommct / Install_Python.md
Last active April 29, 2024 18:29
Install Python MacOS 14, Pyenv
@tommct
tommct / README.md
Last active November 9, 2023 20:00
FreeTDS and pyodbc on Mac OS X 10.8 via Homebrew

After spending many hours trying to get FreeTDS and unixodbc to run on a Mac OS X 10.8 system with the python module, pyodbc, I eventually came to this recipe, which is remarkably simple thanks to homebrew. I also found unixodbc was unnecessary and I couldn't get it to play well with FreeTDS, so this install does not include unixodbc. See also http://www.acloudtree.com/how-to-install-freetds-and-unixodbc-on-osx-using-homebrew-for-use-with-ruby-php-and-perl/ and http://www.cerebralmastication.com/2013/01/installing-debugging-odbc-on-mac-os-x/.

Prerequisites: Be sure you have XCode and the Commandline Tools for XCode installed from Apple. Also install homebrew followed with brew update and brew doctor.

Install FreeTDS:

brew install freetds

Test your install:

@tommct
tommct / Matrix Multiplication Review.ipynb
Last active May 13, 2023 00:25
Intuitions into what matrix multiplications are really and why we employ them in machine learning.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@tommct
tommct / MNIST_PCA.ipynb
Created April 30, 2021 23:30
PCA exploration in Python with the MNIST database
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@tommct
tommct / interactive_display_pandas.ipynb
Created June 11, 2022 22:32
Update the display of a Pandas DataFrame interactively in a Jupyter Notebook using Jupyter Widgets
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@tommct
tommct / README.md
Last active January 9, 2022 09:02
Instructions for downloading Jupyter Notebooks from Coursera

From an open Jupyter Notebook homework assignment, select "Coursera" to take you to the home page. Make a new notebook and fill it with the following and excute the cell with:

%%bash
tar cvfz hw.tar.gz .

This may take a little while to run depending on the packages. Select "Coursera" again to take you to the Home directory. Check the hw.tar.gz file and then Download. After the file is downloaded, delete it.

@tommct
tommct / transformercontext.py
Created July 2, 2021 17:18
Allows for the retrieval of all or parts of the transformations in a sklearn Pipeline, as well as the ability to dynamically bypass parts of the pipeline.
import contextlib
from functools import partial
from sklearn.pipeline import Pipeline
@contextlib.contextmanager
def intermediate_transforms(pipe: Pipeline, keys: list=[], bypass_list: list=[]):
"""Allows for the retrieval of all or parts of the transformations in a
sklearn Pipeline, as well as the ability to dynamically bypass parts of
the pipeline.
@tommct
tommct / dijkstra.ipynb
Last active April 30, 2021 17:06
Generic Dijkstra's shortest paths implementation in Python using a priority queue with callback functionality as it visits nodes.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@tommct
tommct / walkcollection.py
Created April 30, 2021 16:39
Walk a collection, like a JSON object, using a callback.
import logging
from collections.abc import Iterable
def is_container(obj):
return isinstance(obj, Iterable) and not isinstance(obj, (str, bytes, bytearray))
# https://stackoverflow.com/a/54000999/394430
def walk_collection(obj, callback=None, _path: list=[], **kwargs):
"""Walk an arbitrarily nested structure of lists and/or dicts such as would be made when
reading JSON as an object. Walking is performed in a depth-first search manner.
@tommct
tommct / README.md
Last active March 15, 2021 17:39
Tableau Box Plots and Histograms

This is a recipe for making box plots overlaying histograms in Tableau version 9.3. It largely borrows from http://vizpainter.com/some-tableau-tips-options-for-box-and-whisker/ and http://vizdiff.blogspot.com/2015/11/overlaying-histogram-with-box-and.html.

  1. Create a fixed continuous variable for number of objects per dimension. For example, the number of unique assignments per user:

     [Assignments Per User] = {FIXED [Userid] : COUNTD([Assignmentid])}
    
  2. Set the variable's Default Aggregation to COUNT.

  3. Drag the variable from Measures to the columns shelf.

  4. Set it to "Dimension" instead of CNT().