Skip to content

Instantly share code, notes, and snippets.

View henchc's full-sized avatar

Christopher Hench henchc

View GitHub Profile
@henchc
henchc / autopep8-ipynb.py
Created March 15, 2017 21:32
converts ipython notebook code cells to PEP-8 compliant
# -*- coding: utf-8 -*-
# Author: Christopher Hench
# command line program makes ipynb PEP-8 compliant
import json
import autopep8
import sys
import re
file_path = sys.argv[1]
@henchc
henchc / flattenjsonLITE.R
Created July 18, 2017 19:07
flatten nested lists from jsonLITE (e.g. for CSV export) in R. This will join the nested lists with a semicolon separator.
f <- function(df) {
for (col in names(df)) {
if (is.list(df[[col]])) {
i <- 1
for (row in df[[col]]) {
df[[col]][i] <- paste(row, collapse = '; ')
i <- i + 1
}
@henchc
henchc / rm_scraping_tmp.sh
Created December 24, 2017 01:30
removes temporary files generated by selenium and chrome or firefox and kills zombie processes
rm -rf __pycache__
rm -rf /tmp/tmp*
rm -rf /tmp/rust*
rm -rf /tmp/mozilla*
rm -rf /tmp/.org*
pkill firefox
pkill chrome
pkill Xvfb
pkill python
from yaml import safe_load as load
import requests
url_requirements = "https://raw.githubusercontent.com/jupyterhub/mybinder.org-deploy/master/mybinder/requirements.yaml"
requirements = load(requests.get(url_requirements).text)
binderhub_dep = [ii for ii in requirements['dependencies'] if ii['name'] == 'binderhub'][0]
bhub_live = binderhub_dep['version'].split('-')[-1]
print(bhub_live)
url_helm_chart = "https://raw.githubusercontent.com/jupyterhub/mybinder.org-deploy/master/mybinder/values.yaml"
helm_chart = requests.get(url_helm_chart)
helm_chart = load(helm_chart.text)
r2d_live = helm_chart['binderhub']['config']['BinderHub']['build_image'].split(':')[-1]
print(r2d_live)
commit_info = {
'repo2docker': {},
'binderhub': {}
}
commit_info['binderhub']['live'] = bhub_live
commit_info['repo2docker']['live'] = r2d_live
print(commit_info)
url = "https://hub.docker.com/v2/repositories/jupyter/repo2docker/tags/"
resp = requests.get(url)
r2d_master = resp.json()['results'][0]['name']
print(r2d_master)
url_helm_chart = 'https://raw.githubusercontent.com/jupyterhub/helm-chart/gh-pages/index.yaml'
helm_chart_yaml = load(requests.get(url_helm_chart).text)
# sort by date created
updates_sorted = sorted(helm_chart_yaml['entries']['binderhub'], key=lambda k: k['created'])
bh_master = updates_sorted[-1]['version'].split('-')[-1]
print(bh_master)
# add to commit_info dictionary
commit_info['repo2docker']['latest'] = r2d_master
print('repo2docker', commit_info['repo2docker']['live'], commit_info['repo2docker']['latest'])
commit_info['binderhub']['latest'] = bh_master
print('binderhub', commit_info['binderhub']['live'], commit_info['binderhub']['latest'])
print(commit_info)
import os
TOKEN = os.environ.get('HENCHBOT_TOKEN')
for repo in ['binderhub', 'repo2docker']:
if commit_info[repo]['live'] != commit_info[repo]['latest']:
res = requests.post('https://api.github.com/repos/jupyterhub/mybinder.org-deploy/forks',
headers={'Authorization': 'token {}'.format(TOKEN)})