Skip to content

Instantly share code, notes, and snippets.

View astromme's full-sized avatar

Andrew Stromme astromme

View GitHub Profile
@astromme
astromme / permutations.kt
Created January 5, 2022 17:29
Kotlin extension implementation of Heap's Algorithm for generating permutations
import kotlin.system.measureTimeMillis
fun test_permutations() {
val list = listOf<Int>(1, 2, 3)
val truth_permutations = listOf<List<Int>>(
listOf<Int>(1, 2, 3),
listOf<Int>(2, 1, 3),
listOf<Int>(3, 1, 2),
listOf<Int>(1, 3, 2),
listOf<Int>(2, 3, 1),
@astromme
astromme / convert_for_screensaver.sh
Created January 23, 2021 21:56
Creates many copies of images in the correct format so that the mac screensaver shows them for a longer duration.
#!/bin/bash
# assuming convert.sh is in the folder you want the new images to be in,
# and the source images are one level up, then run with:
# ./convert_for_screensaver.sh ../*.{JPG,jpg}
# each copy shows for about 5 seconds, so 120 copies is about 6 minutes per slide
copies=120
num=1
#!/bin/bash
# assuming convert.sh is in the folder you want the new images to be in,
# and the source images are one level up, then run with:
# ./convert.sh ../*.{JPG,jpg}
# each copy shows for about 5 seconds, so 120 copies is about 6 minutes per slide
copies=120
# my external monitor is 2560x1440. change this as needed for full-bleed images
import tensorflow as tf
## Tensorflow image translation op
# images: A tensor of shape (num_images, num_rows, num_columns, num_channels) (NHWC),
# (num_rows, num_columns, num_channels) (HWC), or (num_rows, num_columns) (HW).
# tx: The translation in the x direction.
# ty: The translation in the y direction.
# interpolation: If x or y are not integers, interpolation comes into play. Options are 'NEAREST' or 'BILINEAR'
def tf_image_translate(images, tx, ty, interpolation='NEAREST'):
# got these parameters from solving the equations for pixel translations
@astromme
astromme / livereload.js
Created July 9, 2017 17:33
Code to auto reload a chrome extension during development by watching a livereload server
// Credit goes to https://github.com/yeoman/generator-chrome-extension
// Reload client for Chrome Apps & Extensions.
// The reload client has a compatibility with livereload.
// WARNING: only supports reload command.
var LIVERELOAD_HOST = 'localhost:';
var LIVERELOAD_PORT = 35729;
var connection = new WebSocket('ws://' + LIVERELOAD_HOST + LIVERELOAD_PORT + '/livereload');
connection.onerror = function (error) {
@astromme
astromme / generate_points.py
Created June 16, 2017 01:04
Generate random points within quad
import random
import numpy as np
from shapely.geometry import Point
from shapely.geometry.polygon import Polygon
points = [
[0, 0],
[0, 1],
[1, 0],
[1, 1]
@astromme
astromme / convert_to_mp3.sh
Last active August 29, 2015 14:17
Parallel Convert Files to MP3 with FFMPEG
#!/bin/bash
INPUT_DIR="."
INPUT_FILE_EXTENSION=".flac"
BITRATE="320k"
OUTPUT_DIR="MP3"
OUTPUT_FILE_EXTENSION=".mp3"
N_PARALLEL=4
find "$INPUT_DIR" -print0 | xargs -0 -n 1 -P $N_PARALLEL sh -c 'ffmpeg -i "$1" -ab $BITRATE "$OUTPUT_DIR/${1%$INPUT_FILE_EXTENSION}$OUTPUT_FILE_EXTENSION"' sh