This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import datetime, time | |
import re | |
# date lambdas | |
epoch = datetime.datetime.utcfromtimestamp(0) | |
unix_time_millis = lambda dt: int((dt - epoch).total_seconds() * 1000.0) | |
zulu_time = lambda s: unix_time_millis(datetime.datetime(*map(int, re.split('[^\d]', s)[:-1]))) | |
# zinnia data exported from the save feature |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
import java.util.concurrent.BlockingQueue; | |
import java.util.concurrent.ConcurrentHashMap; | |
import java.util.concurrent.LinkedBlockingQueue; | |
/** | |
* A BlockinqQueue in which consumers may block producers (temporarily) | |
* to prevent them from producing more items to consume. To allow a producer | |
* to continue operation, an element taken from this queue must be accepted, | |
* by calling {@link AccepterBlockingQueue#accept(ThreadUniqueObject)}. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// generate a bright (v = 0.98), mediumly saturated (s = 0.5) random color | |
var h=Math.random(),s=0.5,v=0.98, | |
golden_ratio_conjugate=0.6180339887, | |
f,p,q,t,r,g,b; | |
// subsequent calls to rand() follow a more uniform distribution with fibonacci hashing | |
// see http://cse.iitkgp.ac.in/~pb/algo1-pb-101111.pdf | |
h += golden_ratio_conjugate; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension UIColor { | |
/** | |
Initialize a new UIColor from a hex value | |
- parameter hex: The hex integer (0x______) representation of the color | |
*/ | |
convenience init(hex: Int) { | |
let components = ( | |
R: CGFloat((hex >> 16) & 0xff) / 255, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn.preprocessing import StandardScaler | |
def standardize_data(data, training_validation_split=0.2): | |
""" | |
standardize features by removing the mean and scaling to unit variance | |
:param data: the data desired to be scaled | |
:param training_validation_split: The percentage of data to save for validation | |
:return: the standardized features and scalar in the form (training, validation, scalar) | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from keras import backend as K | |
from keras import regularizers, constraints, initializers, activations | |
from keras.layers.recurrent import RNN, Layer, _generate_dropout_mask, _generate_dropout_ones | |
from keras.engine import InputSpec | |
from keras.legacy import interfaces | |
import warnings | |
# Copied from original keras source | |
def _time_distributed_dense(x, w, b=None, dropout=None, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
gentleimport is a context manager that patches | |
__import__ to allow for softly importing mocked modules. To use gentleimport, | |
with gentleimport(): | |
import typing | |
import asdf | |
typing.Any # this is a real object as typing was a found module | |
asdf # this is a mock module as asdf was not a real module |