Skip to content

Instantly share code, notes, and snippets.

View SeanTater's full-sized avatar

Sean Gallagher SeanTater

View GitHub Profile
@SeanTater
SeanTater / intro.md
Last active December 22, 2024 01:23
Building your first FastAPI service with UV
@SeanTater
SeanTater / suggest-query.sql
Created January 18, 2021 01:02
Automate joins by using database schemata as a graph
-- Just as a heads up this is an experiment, not a practical script.
-- This almost always ends up in infinite loops
-- It might do a lot more compute than necessary
-- It doesn't recognize you might need more than one column to join on or it might not be as easy as =
-- But that's all beside the point.
-- What we want to show is that you can use SQL to plan how you should design your next SQL query
-- by having it use the schema (in this case fabricated) to traverse a graph.
-- Fascinating? Maybe not. But probably more practical than you expect for really really complex
-- schemata like giant businesses are prone to have.
@SeanTater
SeanTater / shownn-periodic.py
Created January 8, 2021 23:54
Create an intriguing video of a network fitting an image as f(x,y)->(r,g,b), using periodic activations
#!/usr/bin/env python3
"""
Create a video of a neural network's best estimate of a basic 2D image.
Every frame is one epoch, and the results are saved to an MKV as VP8.
In particular, this helps highlight what kinds of errors you can expect
to see from your network based on it's representation of an easily
understandable model.
This is not by any means a good CV model and it's not intended for vision.
@SeanTater
SeanTater / shownn.py
Last active January 8, 2021 17:06
Visualize neural network training, using an image as a feature space and generating a video of epochs
#!/usr/bin/env python3
"""
Create a video of a neural network's best estimate of a basic 2D image.
Every frame is one epoch, and the results are saved to an MKV as VP8.
In particular, this helps highlight what kinds of errors you can expect
to see from your network based on it's representation of an easily
understandable model.
This is not by any means a good CV model and it's not intended for vision.
@SeanTater
SeanTater / Result.py
Created August 20, 2020 11:12
Basic example of using a Monad for handling Python exceptions
class Result:
def __init__(self, ok, err):
""" Do not use this constructor. Use ok() or err(). """
self._ok, self._err = ok, err
@staticmethod
def ok(self, ok):
""" Create a new successful result """
return Result(ok, None)
@SeanTater
SeanTater / windowing-strides.py
Created May 5, 2019 14:45
Memory efficient numpy windowing using np.lib.stride_tricks.as_strided()
#!/usr/bin/env python3.7
import numpy as np
from matplotlib import pyplot
from sklearn.linear_model import SGDRegressor
L = 100
W = 20
D = 8
noise = np.random.uniform(-0.1, 0.1, L)
signal = np.sin(np.linspace(0, 10, L))
@SeanTater
SeanTater / albemarle-target.hs
Last active April 28, 2016 20:10
This is what I want to be able to compile with Albemarle in the future
{-# LANGUAGE OverloadedStrings, NoImplicitPrelude #-}
import ClassyPrelude
import qualified Data.Text as Text
import qualified Data.ByteString as Bytes
import qualified Network.Download as Download
import NLP.Albemarle (Examples, Scrape, Tokens, Phrases, LSI)
main = do
-- Lines in a (many GB) text file, autodetecting encoding
let many_docs = sourceFile "mystuff.txt" $= Scrape.decode =$= Scrape.safeLines
@SeanTater
SeanTater / sentence_cosine_sim.py
Created April 4, 2016 14:19
Marcia Price's Cosine Similarity
# -*- coding: utf-8 -*-
"""
Updated on Sunday April 3 2016
@author: Marcia Price
In Python 2.7 Version
The print lines that are commented out were used for testing and
comprehension, ie to understand how the functions worked.
"""
@SeanTater
SeanTater / Stream.py
Last active March 3, 2016 16:25
A very elementary implementation of lazy streams in Python
# Copyright (C) Sean Gallagher. All rights reserved. Distributed under the Apache 2 License.
# A very simple Monad (kinda)
''' A very elementary sketch of a Stream in Python.
'''
class Stream(object):
_gen = None
def __init__(self, gen):
self._gen = gen
@SeanTater
SeanTater / csv2sqlite.py
Created April 30, 2015 13:59
Standards-compliant CSV import for SQLite3
#!/usr/bin/env python3
import csv
import sqlite3
import argparse
import sys
import time
# Command line arguments
p = argparse.ArgumentParser(
description="Load a CSV into an SQLite database",