Skip to content

Instantly share code, notes, and snippets.

View a-poor's full-sized avatar

Austin Poor a-poor

View GitHub Profile
@a-poor
a-poor / trycatch.jl
Last active April 9, 2021 15:44
A small macro for wrapping an expression in a `try/catch` block.
"""
@trycatch expr
Convenience macro which wraps an expression in a `try/catch` block.
If the expression throws an error, it will be printed with the
`@error` macro.
# Examples
julia> @trycatch 1 + 1
2
@a-poor
a-poor / Dockerfile
Last active September 23, 2020 13:38
# Using a python base image
FROM python:3.8
# Set working directory to be /app
WORKDIR /app
# Copy flask app into the container
COPY app.py /app
# Install Flask
@a-poor
a-poor / app.py
Created September 22, 2020 21:55
A super simple flask app
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello, world!"
if __name__ == "__main__":
app.run(debug=True,host="0.0.0.0",port=5000)
version: "3.8"
services:
jupyter:
image: jupyter/datascience-notebook
ports:
- "8888:8888"
environment:
- JUPYTER_ENABLE_LAB=yes
volumes:
- .:/home/jovyan/work
@profile
def read_books(urls):
"""For each url in urls,
load the book and count the words"""
# Create a place to store word counts
word_counts = {}
# For each book: load it, count words, store the counts
for title, path in urls.items():
book = get_book(path)
words = split_words(book)
Filename: script.py
Line # Mem usage Increment Line Contents
================================================
19 38.426 MiB 38.426 MiB @profile
20 def read_books(urls):
21 """For each url in urls,
22 load the book and count the words"""
23 # Create a place to store word counts
24 38.426 MiB 0.000 MiB word_counts = {}
Wrote profile results to script-profile.py.lprof
Timer unit: 1e-06 s
Total time: 5.62982 s
File: script-profile.py
Function: read_books at line 19
Line # Hits Time Per Hit % Time Line Contents
========================================================
19 @profile
import re
from collections import Counter
import urllib.request
def get_book(url):
"""Load text from a URL"""
with urllib.request.urlopen(url) as response:
text = response.read().decode(errors='ignore')
return text.lower()
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import jinja2
from IPython.display import display_svg
data = {
"title":"Time-Price Comparison",
"subtitle":"Scatter plot of time vs price.",
"data":[
{"time":2,"price":1,"callout":False},
{"time":3,"price":2,"callout":False},
{"time":4,"price":3,"callout":True},