Skip to content

Instantly share code, notes, and snippets.

View andreasvirkus's full-sized avatar
🙊
made you look

andreas andreasvirkus

🙊
made you look
View GitHub Profile
@andreasvirkus
andreasvirkus / pre-push
Created November 24, 2025 12:45
Place in .git/hooks/pre-push
#!/bin/bash
# Get the current branch name
current_branch=$(git rev-parse --abbrev-ref HEAD)
# Check if pushing to main branch
if [[ "$current_branch" = "main" ]]; then
echo "⚠️ You're about to push to the main branch!"
echo -e "Current branch: $current_branch\n"
<template>
<div class="otp-input my-4 flex justify-center gap-2 text-black">
<input
v-for="i of 6"
:key="i"
v-model="otp[i - 1]"
type="tel"
maxlength="1"
class="otp-field text-heading"
required
@andreasvirkus
andreasvirkus / audio-vis.js
Created June 3, 2025 07:00
Audio visualisation with p5.js - drop an MP3 file and then click the page to view the visualisation.
var canvas,
bgColor,
radialArcs = [],
fft,
soundFile,
soundSpectrum;
function setup() {
colorMode(HSB,360,100,100); // set colour mode of sketch to HSB (360 degress, 100%, 100%)
frameRate(60); // set framerate
export const EventBus = {
$on (eventType, callback) {
document.addEventListener(eventType, (ev) => callback(ev.detail))
},
$dispatch (eventType, data) {
const event = new CustomEvent(eventType, { detail: data })
document.dispatchEvent(event)
},
$off (eventType, callback) {
document.removeEventListener(eventType, callback)
function singularize(word) {
const endings = {
ves: 'fe',
ies: 'y',
i: 'us',
zes: 'ze',
ses: 's',
xes: 'x',
es: 'e',
s: ''
@andreasvirkus
andreasvirkus / movies
Created July 9, 2024 18:16
like... to watch or something
The Fountain
Eternal Sunshine of the Spotless Mind
Into the Wild
Ex Machina
Okja
Isle of Dogs
JoJo Rabbit
The Nice Guys
Mad Max: Fury Road
I am Sam
function resizeImage(el, width, height, quality) {
var canvas = document.createElement('canvas')
canvas.width = width
canvas.height = height
var context = canvas.getContext('2d')
context.drawImage(el, 0, 0, width, height)
try {
return canvas.toDataURL('image/jpeg', quality)
} catch (e) {
@andreasvirkus
andreasvirkus / Modal.vue
Last active September 10, 2022 22:03
Simple Vue modal component
<template>
<transition-fade :duration="200">
<div
v-if="show"
:class="$style.backdrop"
@click="$emit('close')"
@keydown.stop
@keyup.esc="handleEscape"
>
<dialog v-show="show" ref="dialog" :open="show" :class="$style.modal" tabindex="-1">
const roundingStops = [5, 10, 50, 100, 500, 1000, 5000, 10000, 50000, 100000]
export const roundToScale = (count, scale = roundingStops) => {
if (count === 0) return 0
const nearestIdx = scale.findIndex((s) => s > count)
let nearest = scale[nearestIdx]
if (nearestIdx !== 0 && nearest / 2 > count) nearest = scale[nearestIdx - 1] || scale[0]
return nearest || count
export const strip = (html: string) => {
const doc = new DOMParser().parseFromString(html, 'text/html')
return (doc.body.textContent || '').trim()
}