Skip to content

Instantly share code, notes, and snippets.

Avatar

Kevin Ashcraft kevashcraft

View GitHub Profile
@kevashcraft
kevashcraft / K8s-DigitalOcean-CoreOS.md
Last active May 6, 2020
How to Setup Kubernetes on DigitalOcean with CoreOS
View K8s-DigitalOcean-CoreOS.md

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 / TFRecord-Writer.py
Last active Feb 7, 2020
Writing a TFRecord File
View TFRecord-Writer.py
# 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 / TFDataset-Take.py
Created Feb 7, 2020
Iterating Through TF Dataset
View TFDataset-Take.py
# 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 Feb 7, 2020
Read TFRecord File into TF Dataset
View Read-TFRecord.py
# 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-Reader.py
Created Feb 4, 2020
Reading a TFRecord File
View TFrecord-Reader.py
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 Feb 4, 2020
Writing a TFRecord File
View TFRecord-Writer.py
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 Jul 11, 2019
Create ico from png
View favicon.sh
convert logo.png -define icon:auto-resize=64,48,32,16 logo.ico
View ad-muter.js
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 / daily_backup
Last active Dec 2, 2018
Recursive backup w rsync - bash script
View daily_backup
#!/bin/bash
DESTINATION="/Backup"
SOURCE="/var/www"
#Todays date in ISO-8601 format:
DAY0=`date -I`
#Previous backup date:
@kevashcraft
kevashcraft / retrieve.py
Created Jun 18, 2018
Retrieve Stock Market Data from the AlphaVantage API
View retrieve.py
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,
You can’t perform that action at this time.