Skip to content

Instantly share code, notes, and snippets.

View kevashcraft's full-sized avatar

Kevin Ashcraft kevashcraft

View GitHub Profile
@kevashcraft
kevashcraft / TFDataset-Take.py
Created February 7, 2020 18:42
Iterating Through TF Dataset
# if dataset is not batched
# this will take 1 example
with (ambient, target), label in dataset.take(1):
print("ambient shape", ambient.shape)
print("target shape", target.shape)
print("label shape", label.shape)
ambient_array = ambient.numpy()
target_array = target.numpy()
label_array = label.numpy()
@kevashcraft
kevashcraft / Read-TFRecord.py
Created February 7, 2020 18:37
Read TFRecord File into TF Dataset
# Read a TFRecord file into a TF Dataset
def map_fn(serialized_example):
feature = {
'label': tf.io.FixedLenFeature([1], tf.int64),
'ambient': tf.io.FixedLenFeature([16000], tf.float32),
'target': tf.io.FixedLenFeature([4000], tf.float32)
}
example = tf.io.parse_single_example(serialized_example, feature)
ambient = tf.expand_dims(example['ambient'], 1)
target = tf.expand_dims(example['target'], 1)
@kevashcraft
kevashcraft / TFRecord-Writer.py
Last active February 7, 2020 18:49
Writing a TFRecord File
# Write a ambient, target, and label data to a TFRecords file
with tf.io.TFRecordWriter('examples.tfrecord') as training_file:
for ambient, target, label in batch: # batch is a list of (ambient, target, label) tuples
features = {
'label': tf.train.Feature(int64_list=tf.train.Int64List(value=[label])),
'ambient': tf.train.Feature(float_list=tf.train.FloatList(value=ambient.tolist())), # ambient is a 1-D np array
'target': tf.train.Feature(float_list=tf.train.FloatList(value=target.tolist())) # target is a 1-D np array
}
example_proto = tf.train.Example(features=tf.train.Features(feature=features))
training_file.write(example_proto.SerializeToString())
@kevashcraft
kevashcraft / TFrecord-Reader.py
Created February 4, 2020 16:36
Reading a TFRecord File
label_size = 1 # the length of the previously written label
feature_size = 256 # the length of the previously written feature lists
def map_fn(serialized_example):
feature = {
'label': tf.io.FixedLenFeature([label_)size], tf.int64),
'features': tf.io.FixedLenFeature([feature_size], tf.float32)
}
example = tf.io.parse_single_example(serialized_example, feature)
features = example['features']
label = tf.cast(example['label'], tf.int32)
@kevashcraft
kevashcraft / TFRecord-Writer.py
Last active February 4, 2020 16:32
Writing a TFRecord File
with tf.io.TFRecordWriter('examples.tfrecord') as training_file:
for features, label in batch:
features = {
'label': tf.train.Feature(int64_list=tf.train.Int64List(value=[label])),
'features': tf.train.Feature(float_list=tf.train.FloatList(value=features)) # expects list, so if numpy use .tolist() and ensure it's 1-D
}
example_proto = tf.train.Example(features=tf.train.Features(feature=features))
training_file.write(example_proto.SerializeToString())
@kevashcraft
kevashcraft / favicon.sh
Created July 11, 2019 22:55
Create ico from png
convert logo.png -define icon:auto-resize=64,48,32,16 logo.ico
clearInterval(aa)
function mv() {
var found_one = false
var primary = 0
let el = document.querySelectorAll('.mlbtv-media-player')[primary]
let has_ads = !!el.querySelector('.interruption-link')
if (!has_ads) {
el.querySelector('video').muted = false
@kevashcraft
kevashcraft / retrieve.py
Created June 18, 2018 17:18
Retrieve Stock Market Data from the AlphaVantage API
from urllib.request import urlopen
import yaml
def retrieve(symbol=None):
with open('config.yml') as f:
config = yaml.load(f)
params = {
'function': 'TIME_SERIES_DAILY',
'symbol': symbol,
@kevashcraft
kevashcraft / K8s-DigitalOcean-CoreOS.md
Last active September 18, 2020 05:47
How to Setup Kubernetes on DigitalOcean with CoreOS

Kubernetes on DigitalOcean with CoreOS

Let's look at an example of how to launch a Kubernetes cluster from scratch on DigitalOcean, including kubeadm, an Nginx Ingress controller, and Letsencrypt certificates.

Overview

Environment

We'll be creating a four-node cluster (k8s-master, k8s-000...k8s-002), load balancer, and ssl certificates.

Table of Contents

  1. Install Kubernetes
@kevashcraft
kevashcraft / 00-WordPress-on-CoreOS.md
Last active January 19, 2018 17:15
Setup WordPress with Docker-Compose on CoreOS

Setup WordPress with Docker-Compose on CoreOS

Setup Steps

  1. Create docker-compose.yml in /home/core/, replacing the $variables with your values
  2. Create nginx.tmpl in /var/lib/docker/volumes/wpserver_nginx_templates/_data/
  3. Create wp-server.service in /etc/systemd/system/
  4. Run sudo systemctl daemon-reload to load the new service file
  5. Run sudo systemctl start wp-server to start the WordPress Server
  6. Run sudo systemctl status wp-server to make sure everything is running