This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" box_drawing.py | |
The main function here is add_box_char(), which provides a user-friendly | |
interface to render line-drawings, often referred to as "box-drawing," in a | |
terminal. | |
Here are the box-drawing characters used, along with their direction sets; | |
the direction set is the key input to add_box_char(): | |
─ 0x2500 {'right', 'left'} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
""" cryptogram.py | |
A small tool to help you solve your cryptogram for Python 3. | |
Usage: | |
./cryptogram.py <cryptogram_text> | |
From there you'll get a prompt until you've solved the puzzle at hand |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# wordvec_example.py | |
# | |
# This file shows one way to work with word2vec data in Python. | |
# | |
# Setup: | |
# | |
# 1. Install gensim: | |
# | |
# pip install gensim | |
# |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A bare-bones Lua interpreter, in C. | |
#include <stdio.h> | |
#include <string.h> | |
#include "lua.h" | |
#include "lauxlib.h" | |
#include "lualib.h" | |
int main() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |