Skip to content

Instantly share code, notes, and snippets.

Tyler Neylon tylerneylon

Block or report user

Report or block tylerneylon

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@tylerneylon
tylerneylon / prec_95_example.ipynb
Created May 30, 2019
Example of visualizing and extracting classifier cutoff values to meet certain precision-recall objectives.
View prec_95_example.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View prec_recall.py
# Have 1d array-likes y_true and y_pred.
# y_true is expected to be 0/1,
# and y_pred is expected to have floats in [0, 1].
#
# I learned how to do this from here:
# https://scikit-learn.org/stable/auto_examples/model_selection/plot_precision_recall.html
from sklearn.metrics import average_precision_score
from sklearn.metrics import precision_recall_curve
@tylerneylon
tylerneylon / pre-commit
Last active Jul 26, 2018
git pre-commit hook to help support github-based code reviews of Jupyter notebooks in Python.
View pre-commit
#!/bin/bash
#
# Convert all new Jupyter notebooks to straight Python files for easier code
# reviews.
#
for file in $(git diff --cached --name-only); do
if [[ $file == *.ipynb ]]; then
jupyter nbconvert --to script $file
git add ${file%.*}.py
@tylerneylon
tylerneylon / rwlock.py
Last active Oct 13, 2019
A simple read-write lock implementation in Python.
View rwlock.py
# -*- coding: utf-8 -*-
""" rwlock.py
A class to implement read-write locks on top of the standard threading
library.
This is implemented with two mutexes (threading.Lock instances) as per this
wikipedia pseudocode:
https://en.wikipedia.org/wiki/Readers%E2%80%93writer_lock#Using_two_mutexes
@tylerneylon
tylerneylon / wordvec_example.py
Created Jan 12, 2018
Quick reference on how to work with pre-trained word2vec vectors in Python.
View wordvec_example.py
# wordvec_example.py
#
# This file shows one way to work with word2vec data in Python.
#
# Setup:
#
# 1. Install gensim:
#
# pip install gensim
#
@tylerneylon
tylerneylon / cow.c
Created Sep 4, 2017
An example Lua module written in C.
View cow.c
// A Lua module written in C.
//
// This module enables terminal-based ASCII art
// of a loquacious bovine nature.
//
#include <stdio.h>
#include <stdlib.h>
#include "lua.h"
@tylerneylon
tylerneylon / lua_interp.c
Last active Sep 4, 2017
A bare-bones Lua interpreter, in C.
View lua_interp.c
// A bare-bones Lua interpreter, in C.
#include <stdio.h>
#include <string.h>
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
int main() {
@tylerneylon
tylerneylon / whatisit.py
Created Mar 26, 2017
20 shortish lines that do something fun.
View whatisit.py
import itertools, os, sys
it, chars = 20, '.-=*x#X'
sys.stdout.write('\x1b[?25l')
w = int(os.popen('tput cols').read())
h = int(os.popen('tput lines').read()) - 1
x_max, y_max = float(w) / (2.0 * h) * 1.2, 1.2
for j in itertools.count(1):
sys.stdout.write('\x1b[1;1H')
@tylerneylon
tylerneylon / mnist.py
Last active May 4, 2019
A function to load numpy arrays from the MNIST data files.
View mnist.py
""" A function that can read MNIST's idx file format into numpy arrays.
The MNIST data files can be downloaded from here:
http://yann.lecun.com/exdb/mnist/
This relies on the fact that the MNIST dataset consistently uses
unsigned char types with their data segments.
"""
@tylerneylon
tylerneylon / colortable.sh
Created Jul 26, 2016
Terminal-based color table
View colortable.sh
# A bash function to print out a table of
# colors supported by your terminal.
colortable() {
tput setaf 0
for i in $(seq 0 $(tput colors)); do
tput setab $i
printf %4d $i
done
echo
You can’t perform that action at this time.