Skip to content

Instantly share code, notes, and snippets.

@breeko
breeko / utils.py
Created March 18, 2019 10:49
Helper functions for aws s3
import boto3
import requests
from urllib.parse import urlparse
import os
import urllib.request
import shutil
def download_url(url, file_name):
@breeko
breeko / train.py
Last active November 4, 2018 22:34
Training function for GAN
def train(gan,
num_iters,
batch_size=128,
print_every=1,
epochs=1,
min_disc_acc = 0.5,
min_gan_acc = 0.2,
normal_noise=True,
save_example_name=None,
save_model_name=None,
@breeko
breeko / train.py
Created November 4, 2018 19:58
Training function for GAN
def train(gan,
num_iters,
batch_size=128,
print_every=1,
epochs=1,
min_disc_acc = 0.5,
min_gan_acc = 0.2,
normal_noise=True,
save_example_name=None,
save_model_name=None,
@breeko
breeko / create_vae.py
Last active October 26, 2018 10:52
Creates a variational auto encoder
import matplotlib.pyplot as plt
from keras.layers import Input, Dense, Lambda, Flatten, Reshape
from keras.models import Model
from keras import backend as K
from keras.callbacks import EarlyStopping
from keras import objectives
import numpy as np
from itertools import product
@breeko
breeko / gans-in-action-ch3.py
Last active October 19, 2018 10:17
Recreation of GANs in Action Chapter 3 Variational Auto Encoder
# 2.8 Variational autoencoder (VAE)
import matplotlib.pyplot as plt
import matplotlib as mpl
from keras.layers import Input, Dense, Lambda, Flatten, Reshape
from keras.models import Model
from keras import backend as K
from keras.callbacks import EarlyStopping
@breeko
breeko / db_utils.py
Last active September 8, 2018 18:29
Lambda Architecture Simple Example
import os
from datetime import datetime as dt
from dateutil import parser
"""
logs
botrank
[user]
good
summary
@breeko
breeko / get_records_filtered.py
Created September 8, 2018 17:39
Lambda architecture database returning filtered records
import os
from datetime import datetime as dt
from dateutil import parser
### HELPERS
class NoYearHandlingParserInfo(parser.parserinfo):
yearFirst=True
def convertyear(self, year, *args, **kwargs):
""" dateutils.parser.parse parses 1 as 2001. This corrects it to parse 1 as in 1AD """
return int(year)
@breeko
breeko / Validator.js
Created July 22, 2018 13:42
Validator for OpenCalc
//@flow
import CalcUtils from "./CalculatorUtils";
import {lastOrNull, isInArray} from './Utils';
import {DECIMAL, Operation} from "../core/Operations";
import {OperationType, OperationSubType, OperationArgs} from '../core/OperationTypes';
export default class Validator {
static getLastEffectiveOperator(queue: Array<Operation>): Operation {
@breeko
breeko / getDisplay.js
Last active July 22, 2018 03:03
getDisplay and evaluate for OpenCalc
getResult(): string {
const numbers: Array<Operation> = this.queue.filter(op => op.operationType === OperationType.Constant);
const operatorsWithParenthesis = CalcUtils.getOperatorsWithParenthesis(this.queue);
const evaluatedOps = this.evaluateParenthesis(operatorsWithParenthesis);
try {
const out = this.evaluate(numbers, evaluatedOps, null);
if (out !== null && out !== undefined) {
return numberWithCommas(out.toString());
} else {
@breeko
breeko / getDisplay.js
Created July 22, 2018 02:54
getDisplay and evaluate for OpenCalc
getDisplay(): string {
if (this.queue.length === 0) {
return ' '
}
return this.queue.map(x => (
x.operationType == OperationType.Constant &&
!x.operationArgs.has(OperationArgs.PrintAsString)) ?
numberWithCommas(x.stringVal, false) :
x.stringVal).join(' ')
}