Skip to content

Instantly share code, notes, and snippets.

View worldoptimizer's full-sized avatar
💭
Homeoffice

Max Ziebell worldoptimizer

💭
Homeoffice
View GitHub Profile
@worldoptimizer
worldoptimizer / hypeDocument.syncHypeToAnime.js
Created September 18, 2020 19:51
Sync values animated in Anime.js to Hype
hypeDocument.syncHypeToAnime = function(anim){
var reverselookup = {'translateX': 'left', 'translateY': 'top'}
anim.animations.forEach(function(a){
if (!a.animatable.target.classList.contains('HYPE_element')) return;
if (['top','left','translateX', 'translateY', 'width','height','rotateZ','scaleX','scaleY','opacity','z-index'].includes(a.property)){
var hypeProp = reverselookup[a.property] || a.property;
hypeDocument.setElementProperty(a.animatable.target, hypeProp, parseFloat(a.currentValue) );
}
});
}
anime({
targets: '.circle',
translateX: '250px',
translateY: '150px',
backgroundColor: '#FFF',
rotateY: '360deg',
rotateX: '360deg',
easing: 'easeInOutQuad',
changeComplete: function(anim){
setInterval(function(){
var elm = document.querySelector((Math.random()>0.5)? '#leftKey' : '#rightKey');
elm.click();
}, 100);
/**
* Resolve variables in string using a variable lookup
*
* @param {string} str The string to resolve variables in.
* @param {object} variables The variables to resolve.
* @returns {string} The resolved string.
*/
function resolveVariablesInString(str, variables) {
if (typeof str === 'string') {
var matches = str.match(/\${.*?}|%{.*?}|✨{.*?}/g);
/**
* Converts a key and value to a string.
*
* @param {strin} key
* @param {string|number|boolean|object|function} value
* @param {string} indent
* @return {string}
*/
function keyToString(key, value, indent) {
var scrollSpeed = 0;
var isScrolling = false;
document.addEventListener('keydown', function(e) {
if (sidebar.classList.contains('open')) {
if (e.shiftKey && e.keyCode === 38) {
scrollSpeed *= 1.5;
function selfFullFilling(fn) {
let value;
return function() {
return value || (value = fn.apply(this, arguments));
};
}
const add = selfFullFilling(function(a, b) {
console.log("calculated!")
return a + b;
@worldoptimizer
worldoptimizer / getCommentsFromString.js
Created June 4, 2022 12:51
Extract the comments from a string.
/**
* Extract the comments from a string.
* @param {string} str - The string to extract the comments from.
* @returns {Array.<string>} - An array of comment strings.
*/
function getCommentsFromString(str) {
str = str.toString();
var start = str.indexOf("/*");
var end = str.indexOf("*/");
var result = [];
@worldoptimizer
worldoptimizer / createSequence.js
Created June 22, 2022 10:05
This function creates another function that can be used to loop through a set of steps.
/**
* This function creates another function that can be used to loop through a set of steps.
* This could be useful, for example, in creating animations or a set of instructions that need to be followed in order.
*
* @param {Array} arr - The array of steps to be looped through
* @param {number} i - The index to start at
* @param {function} callback - The function to be called on each step
* @param {string} key - The key to use for the object
* @returns {function} - A function that can be used to loop through the steps
*/
#!/usr/bin/python
# HypeTemplate.hype-export.py
# Export Script for Tumult Hype to produce offer a generic template system
#
# MIT License
# Copyright (c) 2022 Max Ziebell
#
import argparse