Skip to content

Instantly share code, notes, and snippets.

@ahoereth
ahoereth / flatten.py
Created July 3, 2017 08:46
Python flatten
def flatten(x, depth=-1):
"""Flattens a list of lists into a single list."""
if depth == 0:
return x
if isinstance(x, list):
result = []
for el in x:
if hasattr(el, '__iter__') and not isinstance(el, str):
result.extend(flatten(el, depth - 1))
else:
@ahoereth
ahoereth / sheetmail.gs
Created June 20, 2017 07:46
Sending mails from Google Sheets
// This constant is written in column C for rows for which an email
// has been sent successfully.
var EMAIL_SENT = "EMAIL_SENT";
var RESULTCOL = 15; // O
var ASSIGNMENT = "09 - Blindwalk";
var SUBJECT = "[MATLAB] Assignment " + ASSIGNMENT;
var messages = {
'1': "You successfully passed assignment " + ASSIGNMENT + ". Congrats!\n",
'1?': "You passed assignment " + ASSIGNMENT + ". We want to note that it was a rather close call. If you want more specific feedback come up to us in class/after lecture or send an email.\n",
@ahoereth
ahoereth / awstf.py
Last active June 28, 2018 17:44
Find cheapest p2.xlarge spot instance availability zone and provide docker-machine command to lunch it with a ready-to-use nvidia-docker AMI.
#!/usr/bin/env python3
"""Script locating the cheapest AWS GPU compute spot instance for docker."""
from argparse import ArgumentParser
from datetime import datetime, timedelta
from itertools import groupby
from operator import itemgetter
import boto3
import numpy as np
@ahoereth
ahoereth / tf_kernel_images.py
Last active May 10, 2017 13:20 — forked from kukuruza/gist_cifar10_train.py
Tensorflow: visualize convolutional features (conv1) in Cifar10 model
def kernel_images(name, x, pad=1, max_images=-1, summarize=True):
"""Create image summaries of 2d convolution kernel weights."""
def factorization(n):
"""Calculates kernel grid dimensions."""
for i in range(int(sqrt(float(n))), 0, -1):
if n % i == 0:
return i, n // i
with tf.name_scope(name):
@ahoereth
ahoereth / gist:6aa36d3553ef7ec27b3591fdbbe8f940
Last active November 21, 2016 12:07
Chrome Search Engines
I'm Feeling Lucky : go : {google:baseURL}search?gfns=1&sourceid=navclient&q=%s
DuckDuckGo Cheat Sheets : cheat : https://duckduckgo.com/?q=cheat+sheet+%s&iax=1
Down For Everyone Or Just Me : down : http://downforeveryoneorjustme.com/%s
OpenCV 3.1 : cv : http://docs.opencv.org/3.1.0/search/all_5.html?%s
@ahoereth
ahoereth / DataTable.js
Created August 23, 2016 13:40
Simplified react-mdl DataTable for immutablejs props. https://tleunen.github.io/react-mdl/components/datatable/
import React, { PropTypes } from 'react';
import ImmutableTypes from 'react-immutable-proptypes';
import classNames from 'classnames';
class DataTable extends React.Component {
renderCell({ name, numeric }, row) {
const className = !numeric ? 'mdl-data-table__cell--non-numeric' : '';
return <td key={name} className={className}>{row.get(name, '')}</td>;
}
@ahoereth
ahoereth / geoname2json.py
Created July 29, 2016 13:26
Converts country 'geoname' data from http://www.geonames.org/export/ to JSON.
import os
import sys
import csv
import json
filename = sys.argv[1]
name, _ = os.path.splitext(filename)
header = ['geonameid', 'name', 'asciiname', 'alternatenames',
'latitude', 'longitude', 'featureclass', 'featurecode',
@ahoereth
ahoereth / .block
Created June 28, 2016 21:34 — forked from mbostock/.block
Zoomable Circle Packing
license: gpl-3.0
@ahoereth
ahoereth / meteor_reactive_var.html
Last active July 29, 2017 18:10
Minimal meteor reactive variable example. http://meteorpad.com/pad/kajGdYLfTrEkE5NtL
<template name="meteor_reactive_var">
<div>{{count}}</div>
<button>Increment Count</button>
</template>