Skip to content

Instantly share code, notes, and snippets.

View WillKoehrsen's full-sized avatar
🌆
All watched over by machines of loving grace

Will Koehrsen WillKoehrsen

🌆
All watched over by machines of loving grace
View GitHub Profile
from bs4 import BeautifulSoup
# Create a soup and find the table
soup = BeautifulSoup(open(f'stats.html', 'r'))
table = soup.find_all(attrs={'class': "sortableTable-row js-statsTableRow"})
entry = table[0]
# Reading time
read_time = int(entry.find_all(attrs={'class': 'readingTime'})[0].get('title').split(' ')[0])
# Unlisted vs published
type = 'unlisted' if len(entry.find_all(text=' Unlisted')) > 0 else 'published'
# Publication
publication = entry.find_all(attrs={'class': 'sortableTable-text'})

Default Cell

Adds and runs a default cell at the top of each new notebook. To change the default cell, edit the main.js file in the code:

Jupyter.notebook.insert_cell_above('code', 0).set_text(``)

Set the text to whatever you would like.

This extension also adds a button to the toolbar allowing you to insert and run the

define([
'base/js/namespace',
'base/js/events'
], function(Jupyter, events) {
// Adds a cell above current cell (will be top if no cells)
var add_cell = function() {
Jupyter.notebook.
insert_cell_above('code').
// Define default cell here
Type: Jupyter Notebook Extension
Compatibility: 3.x, 4.x, 5.x, 6.x
Name: Default cell
Main: main.js
Link: README.md
Description: |
Adds and runs a default cell at the top of each new notebook.
Also adds a button to insert and run the default cell above the current cell.
Helpful for commonly used imports.
def report_stats(text, channel):
"""Report training stats"""
r = slack.chat.post_message(channel=channel, text=text,
username='Training Report',
icon_emoji=':clipboard:')
class SlackUpdate(Callback):
"""Custom Keras callback that posts to Slack while training a neural network"""
def __init__(self, channel):
# Observations from multiple trips
c = np.array([[3, 2, 1],
[2, 3, 1],
[3, 2, 1],
[2, 3, 1]])
with pm.Model() as model:
# Parameters are a dirichlet distribution
parameters = pm.Dirichlet('parameters', a=alphas, shape=3)
# Observed data is a multinomial distribution
# Sample from the posterior
with model:
samples = pm.sample_ppc(trace, samples = 1000)
with model:
# Sample from the posterior
trace = pm.sample(draws=1000, chains=2, tune=500,
discard_tuned_samples=True)
import pymc3 as pm
import numpy as np
alphas = np.array([1, 1, 1])
c = np.array([3, 2, 1])
# Create model
with pm.Model() as model:
# Parameters of the Multinomial are from a Dirichlet
parameters = pm.Dirichlet('parameters', a=alphas, shape=3)