Skip to content

Instantly share code, notes, and snippets.

@nickgraffis
nickgraffis / _requestAnimationFrame.js
Created February 22, 2024 18:10
Request animation frame with progress, given a duration.
function _requestAnimationFrame(callback, duration) {
let start = null;
function step(timestamp) {
if (!start) start = timestamp;
const progressTime = timestamp - start;
const progressPercentage = Math.min(progressTime / duration, 1) * 100;
callback(progressTime, progressPercentage);
@nickgraffis
nickgraffis / regex.md
Last active January 25, 2023 04:08
Regex Info

Post About Rege

@nickgraffis
nickgraffis / zodiac-sprite.vue
Created July 8, 2022 15:59
A Vue 3 component that accepts a date, and displays a zodiac sprite 24 x 24 pixels.
<script setup>
import { ref, watch, toRefs, onBeforeMount } from 'vue';
const offset = ref('0px')
const props = defineProps({
date: Date
});
const { date } = toRefs(props);
for k in $(git branch --format="%(refname:short)" --merged master); do
if (($(git log -1 --since='1 month ago' -s $k|wc -l)==0)); then
echo git branch -d $k
fi
done
# for remote branches
for k in $(git branch -r --format="%(refname:short)" --merged master); do
if (($(git log -1 --since='1 month ago' -s $k|wc -l)==0)); then
const hexToHSL = (hex) => {
var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
var r = parseInt(result[1], 16);
var g = parseInt(result[2], 16);
var b = parseInt(result[3], 16);
r /= 255, g /= 255, b /= 255;
var max = Math.max(r, g, b), min = Math.min(r, g, b);
var h, s, l = (max + min) / 2;
if(max == min){
h = s = 0; // achromatic
@nickgraffis
nickgraffis / markdown-it-shiki.ts
Created August 28, 2021 21:26
A markdown plugin for shake syntax highlighting
import { getHighlighter, HighlighterOptions, Highlighter, ILanguageRegistration, IShikiTheme, IThemeRegistration } from 'shiki'
import Debug from 'debug'
const debug = Debug('markdown-it-shiki')
export interface DarkModeThemes {
dark: IThemeRegistration
light: IThemeRegistration
}
@nickgraffis
nickgraffis / arrayEquals.js
Created May 29, 2021 05:18
Array prototype to check if two arrays are equal
Array.prototype.equals = function (array) {
if (!array)
return false;
if (this.length != array.length)
return false;
for (var i = 0, l=this.length; i < l; i++) {
if (this[i] instanceof Array && array[i] instanceof Array) {
if (!this[i].equals(array[i]))