Skip to content

Instantly share code, notes, and snippets.

View gre's full-sized avatar
3 cups required

@greweb gre

3 cups required
View GitHub Profile
@gre
gre / easing.js
Last active April 23, 2024 04:20
Simple Easing Functions in Javascript - see https://github.com/gre/bezier-easing
/*
* This work is free. You can redistribute it and/or modify it under the
* terms of the Do What The Fuck You Want To Public License, Version 2,
* as published by Sam Hocevar. See the COPYING file for more details.
*/
/*
* Easing Functions - inspired from http://gizma.com/easing/
* only considering the t value for the range [0, 1] => [0, 1]
*/
EasingFunctions = {
@gre
gre / day1.rs
Last active December 1, 2023 10:52
advent of code 2023
fn day1(input: &str) -> usize {
let digits = vec!["one", "two", "three", "four", "five", "six", "seven", "eight", "nine"];
let digits_rev = vec!["eno", "owt", "eerht", "ruof", "evif", "xis", "neves", "thgie", "enin"];
let values = vec!['1','2','3','4','5','6','7','8','9'];
input.lines().map(|line| {
let regular = line.chars().collect::<Vec<char>>();
let reversed = line.chars().rev().collect::<Vec<char>>();
let mut s = String::new();
for (chars, digits) in vec![(regular, &digits), (reversed, &digits_rev)] {
use std::f64::consts::PI;
use svg::node::element::path::Data;
use svg::node::element::{Group, Image, Path};
fn heart_function(t: f64) -> (f64, f64) {
let x = 16.0 * f64::sin(t).powi(3);
let y = -13.0 * f64::cos(t)
+ 5.0 * f64::cos(2.0 * t)
+ 2.0 * f64::cos(3.0 * t)
+ f64::cos(4.0 * t);
@gre
gre / 0-README.md
Last active January 19, 2023 08:08
Current @greweb's set up to make a Plottable SVG from data (in TS, JS, Rust)

Usage

makeSVG({
  width: 100,
  height: 100,
  layers: [
    {
      color: "#e22",
 name: "Diamine Brilliant Red",
@gre
gre / scrollparent.js
Created August 3, 2016 11:27
get first parent scrollable container of a dom element
// more minimal version of https://github.com/olahol/scrollparent.js/blob/master/scrollparent.js
const regex = /(auto|scroll)/;
const style = (node, prop) =>
getComputedStyle(node, null).getPropertyValue(prop);
const scroll = (node) =>
regex.test(
style(node, "overflow") +
style(node, "overflow-y") +
@gre
gre / EasingFunctions.json
Last active January 11, 2023 10:28
DEPRECATED Please use http://github.com/gre/bezier-easing for latest vrrsion.
{
"ease": [0.25, 0.1, 0.25, 1.0],
"linear": [0.00, 0.0, 1.00, 1.0],
"ease-in": [0.42, 0.0, 1.00, 1.0],
"ease-out": [0.00, 0.0, 0.58, 1.0],
"ease-in-out": [0.42, 0.0, 0.58, 1.0]
}
@gre
gre / timelapse
Last active August 28, 2022 17:18
#!/bin/sh
# usage: timelapse <inputvid> <outputvid> <N>
# where <N> is a number with which the video will speed up by 2^(N+1)
set -x
set -e
input=$1
output=$2
tmp=`mktemp -d`
@gre
gre / perf.rs
Last active August 14, 2022 11:46
Very simple helpers to record performance
use instant::Instant;
use serde::ser::SerializeStruct;
use serde::{Serialize};
use std::collections::HashMap;
// Helpers for measuring performance
struct Span {
label: String,
start: Instant,
stop: Instant,
// need libs: rand + bs58
use rand::rngs::StdRng;
fn rng_from_fxhash(hash: String) -> impl Rng {
let mut bs = [0; 32];
let max_chars = 43; // hack to not overflow the bs array
bs58::decode(
hash.chars().skip(2).take(max_chars).collect::<String>(),
)
.into(&mut bs)
@gre
gre / article.md
Last active July 26, 2022 15:00

What is GL-Transitions?

The GL-Transitions.com initiative aims to build an Open Collection of GLSL Transitions. It aims to be highly community-driven and free-software.