Skip to content

Instantly share code, notes, and snippets.

View FirefoxMetzger's full-sized avatar

Sebastian Wallkötter FirefoxMetzger

View GitHub Profile
@FirefoxMetzger
FirefoxMetzger / model_comparison.py
Last active April 1, 2018 09:44
Comparing two small networks using dense layers. According to Keras' documentation both should be identical
from keras.models import Sequential
from keras.layers import Dense, Flatten
model1 = Sequential()
model1.add(Dense(1, input_shape=(10,10)))
model2 = Sequential()
model2.add(Flatten(input_shape=(10,10)))
model2.add(Dense(1))
@FirefoxMetzger
FirefoxMetzger / parser.py
Created April 5, 2018 21:14
A small parser with some visualization for go .sgf replays
import numpy as np
import sgf # pip install sgf -- simple parser for the file format
def decode_position(pos_string):
# position in .sgf is char[2] and row-first, e.g. "fd"
positions = "abcdefghijklmnopqrs"
x = positions.index(pos_string[0])
y = positions.index(pos_string[1])
return y, x
import numpy as np
import sgf # pip install sgf -- simple parser for the file format
import timeit
def decode_position(pos_string):
# position in .sgf is char[2] and row-first, e.g. "fd"
positions = "abcdefghijklmnopqrs"
x = positions.index(pos_string[0])
y = positions.index(pos_string[1])
return y, x
@FirefoxMetzger
FirefoxMetzger / shield.py
Created April 8, 2018 12:54
Solution for the first question of the Google Code Jam 2018. (It passes the first round of tests, but is to slow for the second; thus requires runtime optimization. Can you see what could be changed? :) )
from collections import deque
import sys
def get_damage(sequence):
current_strength = 1
damage = 0
for char in sequence:
if char == "C":
current_strength *= 2
@FirefoxMetzger
FirefoxMetzger / trouble_sort.py
Created April 10, 2018 20:49
My answer to the second problem of the Code Jam. It has a small error: Instead of printing "Case #1:" it's printing "Case 1:" ... small things :D
import sys
def trouble_sort(L):
# in place sorting
done = False
while not done:
done = True
for idx in range(len(L) - 2):
if L[idx] > L[idx + 2]:
done = False
@FirefoxMetzger
FirefoxMetzger / DNA_visualizer_optimization_1.py
Created April 14, 2018 13:00
The code from https://codereview.stackexchange.com/questions/192027/genetic-sequence-visualizer-generating-large-images slightly optimized. It avoids storing things that can easily be computed on the fly saving 40x memory.
#!/usr/bin/env python3
# Python3
#
# Run from command line
#
import logging
from argparse import ArgumentParser
from copy import deepcopy, copy
from datetime import timedelta
@FirefoxMetzger
FirefoxMetzger / DNA_visualizer_optimization_2.py
Created April 14, 2018 13:19
Code from: https://codereview.stackexchange.com/questions/192027/genetic-sequence-visualizer-generating-large-images ; No longer uses `largearray` and removed timing statements (can be done better with cpython)
#!/usr/bin/env python3
# Python3
import logging
from argparse import ArgumentParser
from os import remove
from os.path import exists
from re import sub
from time import time
@FirefoxMetzger
FirefoxMetzger / config.cfg
Created April 16, 2018 20:57
A stub config to create self-signed SSL certificates with IP SANs via openssl
[ req ]
default_bits = 2048
distinguished_name = req_distinguished_name
x509_extensions = v3_ca # The extentions to add to the self signed cert
string_mask = utf8only
[ req_distinguished_name ]
countryName = Country Name (2 letter code)
countryName_default = AU
countryName_min = 2
@FirefoxMetzger
FirefoxMetzger / index.html
Last active December 17, 2018 20:18
plumbing between MTurk and Questback
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Redirecting to the Survey ...</title>
<!--[if IE]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
AWS_ACCESS_KEY_ID = "YOUR KEY ID HERE"
AWS_SECRET_ACCESS_KEY = "YOUR SECRET KEY HERE"
USE_SANDBOX = False