Skip to content

Instantly share code, notes, and snippets.

@pfirpfel
pfirpfel / index.html
Last active April 20, 2021 12:42
Wavy knot
<html>
<head>
<title>Wavy Clip Mask</title>
</head>
<body>
<input id="karma" type="range" min="0" max="100" value="50" style="width: 500px;"/>
<br>
<canvas id="canvas"></canvas>
<script src="knot.js" type="text/javascript"></script>
<script src="wave.js" type="text/javascript"></script>
@pfirpfel
pfirpfel / mergeLineStrings.js
Last active June 23, 2017 13:01
mergeLineStrings
/**
* @param arr Array of LineStrings, see: https://tools.ietf.org/html/rfc7946#appendix-A.2
* @returns LineString
*/
function mergeLineStrings(arr){
return {
type: 'LineString',
coordinates: arr.map(ls => ls.coordinates).reduce((acc, cur) => acc.concat(cur.slice(1)))
};
}
@pfirpfel
pfirpfel / gifenc.sh
Last active November 21, 2017 11:02
Generate gif from video using ffmpeg
#!/bin/sh
#usage: ./gifenc.sh source.mkv target.gif
palette="/tmp/palette.png"
filters="fps=10,scale=800:-1:flags=lanczos"
ffmpeg -v warning -i $1 -vf "$filters,palettegen" -y $palette
ffmpeg -v warning -i $1 -i $palette -lavfi "$filters [x]; [x][1:v] paletteuse" -y $2
@pfirpfel
pfirpfel / wordiness.js
Last active February 7, 2021 18:36
MTG Wordiness
const allPrintings = require('./allPrintings') // download from https://mtgjson.com/downloads/all-files/#AllPrintings
// takes a while to load
const sets = Object.entries(allPrintings.data)
const setsToCheck = sets.filter(set => ['core', 'masters', 'expansion'].includes(set[1].type))
let wordiness = setsToCheck.map(set => {
let setSize = set[1].baseSetSize
let cards = set[1].cards.filter(card => Number.parseInt(card.number) <= setSize)
let words = cards.filter(c => typeof c.text !== 'undefined').reduce((acc, curr) => { return acc + curr.text.split(/\s/).length }, 0)
"""
Goal is to fill the empty spots in the initial tuple with positive integers
in a way that always four consecutive number have a product of 120.
"""
import numpy
initial = (None, None, 2, None, None, 4, None, None, None, None, None, 3, None, None) # tuple is immutable
possible_factors = [2, 3, 4, 5, 6, 10, 15] # all possible factors of 120 if there are 4 factors