Skip to content

Instantly share code, notes, and snippets.

View ianozsvald's full-sized avatar

Ian Ozsvald ianozsvald

View GitHub Profile
@ianozsvald
ianozsvald / gist:f373f4278a303bfd5879293831298c45
Created June 27, 2020 21:53
Take bootstrap sample of array of items (e.g. strings) to calculate CI
# take a bootstrap sample to calculate CI on counts of items
def bootstrap_sample_on_array(items, quantiles=[0.025, 0.975], n_bootstrap_samples = 1000):
all_counts = []
for n in range(n_bootstrap_samples):
sample_ids = np.random.randint(low=0, high=items.shape[0], size=items.shape[0])
sample = items[sample_ids]
uniq, cnts = np.unique(sample, return_counts=True)
c = dict(zip(uniq, cnts))
all_counts.append(c)
all_counts = pd.DataFrame(all_counts).fillna(0)
"""Hackish script to convert a notebook into
Note that the content of markdown cells is not translated: it is assumed to
hold asciidoc content instead (even if it does not render correctly in the
browser editing the notebook file).
This script could be improved to use pandoc to handle the conversion instead.
Sample usage:
@ianozsvald
ianozsvald / gist:4621775
Created January 24, 2013 13:47
Shell script to start a local mongo instance using mongo.conf, then tail the log from that file
#!/bin/sh
echo "Starting mongo"
mongod --config=./mongodb.conf &
sleep 2
# tail the log named in the config file
LOG_PATH=`grep -o "^logpath=.*" mongodb.conf | cut -b 9-`
echo "Tailing" $LOG_PATH
tail -f $LOG_PATH
@ianozsvald
ianozsvald / alchemy_call_limit.py
Created January 5, 2013 23:12
Call the AlchemyAPI's GetAPIKeyInfo end point to ask how many API calls we have left today
"""Query AlchemyAPI to determine number of API calls still available"""
# -*- coding: utf-8 -*-
import json
import requests
def get_api_key():
# Load API key (40 HEX character key) from local file
key = open('api_key.txt').readline().strip()
return key