Skip to content

Instantly share code, notes, and snippets.

View jbn's full-sized avatar

John B Nelson jbn

View GitHub Profile
@jbn
jbn / aiohttp_uptime_http_server.py
Created April 7, 2016 12:24
An example showing how to stream HTML in a aiohttp server.
import asyncio
from aiohttp import web
import subprocess
async def uptime_handler(request):
# http://HOST:PORT/?interval=90
interval = int(request.GET.get('interval', 1))
# Without the Content-Type, most (all?) browsers will not render
@jbn
jbn / step_spiral.py
Created May 22, 2016 15:59
Silly little step spiral in Python using itertools.
import itertools
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
def step_spiral(x_0=0, y_0=0):
point = (0, x_0, y_0)
yield point
from ftplib import FTP, error_perm, error_temp
# List passwords
passlist = ["azedaedaze" , "connerre" , "iazevbfhiazev"]
length = len(passlist)
# IP FTP
ftp = FTP('ftpperso.free.fr')
# User FTP
user = "esconnerre"
def get_zen_of_python():
import codecs, sys
out = sys.stdout
with open(os.devnull, "w") as tmp_out:
sys.stdout = tmp_out
from this import s as zen_of_python
sys.stdout = out
return codecs.encode(zen_of_python, 'rot_13')
@jbn
jbn / export_to_svg.py
Created April 9, 2017 21:57
Example for `imate` in Slack Channel
from IPython.display import SVG
from keras.utils.vis_utils import model_to_dot
from keras.models import Sequential
from keras.layers import Dense, Activation
model = Sequential([
Dense(32, input_shape=(784,)),
Activation('relu'),
Dense(10),
#!/bin/bash
# Sketch of an idea. If you've been commiting fixes too much recently, you
# should probably stop what your doing and think a bit. In teams, someone
# else tells you to do so. But, when your by yourself, broken glass can
# accumulate, until one day -- poof.
export MAX_FAILURES=3
export LAST_N_COMMITS=10
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
fig, ax = plt.subplots(4, 1, figsize=(10, 12), sharex=True, sharey=True)
plt.xkcd()
x = np.linspace(-10, 10, 1001)
np.random.seed(43)
ax[0].set_title("How People Think Laws Work")
@jbn
jbn / calendar.json
Created October 13, 2017 21:02
Example taken from http://json-schema.org/example/calendar.json, suitable for Medium embedding.
{
"$schema": "http://json-schema.org/draft-06/schema#",
"description": "A representation of an event",
"type": "object",
"required": [ "dtstart", "summary" ],
"properties": {
"dtstart": {
"format": "date-time",
"type": "string",
"description": "Event starting time"
@jbn
jbn / scatch.ipynb.tmpl
Created November 4, 2017 17:59
Scratch notebook
{
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
@jbn
jbn / .travis.yml
Last active November 8, 2017 17:58
language: python
python:
- "2.7"
- "3.3"
- "3.4"
- "3.5"
install:
- "pip install -r requirements.txt"
- "pip install coveralls nose"
script: