Skip to content

Instantly share code, notes, and snippets.


Philipp phisad

  • Berlin
View GitHub Profile
phisad /
Created Mar 15, 2019
Show many images on a grid like plot
from matplotlib import pyplot as plt
import numpy as np
def show_many(images, max_rows, max_cols, figsize=(20, 20), titles = None, titles_hspace=.1, plot_title = None):
fig = plt.figure(figsize=figsize, dpi=300)
for idx, image in enumerate(images):
row = idx // max_cols
col = idx % max_cols
phisad /
Created Mar 15, 2019
How to encode and pad texts for machine learning using Keras
from tensorflow.keras.preprocessing.sequence import pad_sequences
from tensorflow.keras.preprocessing.text import hashing_trick
def preprocessing(questions, questions_max_length, vocabulary_size):
Stateless preprocessing the text questions to a one-hot encoding and pads to max length questions.
The one-hot encodings max value is the vocabulary size.
The padding is attached at the end of each question up to the maximal question length.
phisad / equals-code-template.xml
Last active Mar 13, 2019
Eclipse code template for equals hash toString with apache commons lang3
View equals-code-template.xml
public boolean equals(Object aObj) {
if(!(aObj instanceof ${enclosing_type})) {
return false;
phisad /
Created Mar 6, 2019
Keras disconnected graphs example when using multiple models
def test_connected_models(self):
input1 = Input(shape=(100,))
dense1 = Dense(1)(input1)
model1 = Model(input1, dense1)
input2 = Input(shape=(200,))
dense2 = Dense(2)(input2)
model2 = Model(input2, dense2)
# This will work, because there are no intermediate Inputs.
phisad /
Created Feb 28, 2019
Primefaces 6.2 tabs with c:forEach
package de.phisad.mybudget.views.budgetplan;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
public class Tab {
private String name;
public Tab(String name) {
phisad / index.html
Created Jan 30, 2019
JSF welcome file for root context with redirect to landing page (somehow only HTML worked, but not XHTML)
View index.html
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<meta http-equiv="refresh" content="0; URL=landing_page.xhtml" ></meta>
phisad /
Last active Jan 18, 2019
Tensorflow gpu starter (tensorflow-gpu 1.12 with CUDA 10.0)
import os
import tensorflow as tf;
# Just disables the warning, doesn't enable AVX/FMA
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
def main():
result = tf.reduce_sum(tf.random_normal([1000,1000]))