Skip to content

Instantly share code, notes, and snippets.

View rikschennink's full-sized avatar

Rik rikschennink

View GitHub Profile
@rikschennink
rikschennink / main.rs
Created December 13, 2022 14:10
Tauri MacOS tray app
#![cfg_attr(
all(not(debug_assertions), target_os = "windows"),
windows_subsystem = "windows"
)]
// Learn more about Tauri commands at https://tauri.app/v1/guides/features/command
#[tauri::command]
fn sync(name: &str) -> String {
format!("Hello, {}! You've been greeted from Rust!", name)
@rikschennink
rikschennink / worker.js
Created September 28, 2022 11:33
Cloudflare purge cache worker
// Based on https://gist.github.com/vdbelt/20f116236d2ebffa92f131e679c0551a
addEventListener('fetch', event => {
event.respondWith(purgeCache(event.request))
})
async function purgeCache(request) {
// get zone querystring value
const zone = new URL(request.url).searchParams.get('zone');
@rikschennink
rikschennink / scramble.ts
Created October 11, 2021 09:42
Scramble filter for use in worker
export default (
options: { imageData: ImageData; amount: number },
done: (err: string, imageData: ImageData) => void
): void => {
const { imageData, amount = 1 } = options;
const intensity = Math.round(Math.max(1, amount) * 2);
const range = Math.round(intensity * 0.5);
const inputWidth = imageData.width;
@rikschennink
rikschennink / convolution.ts
Created October 11, 2021 09:42
Convolution filter for use in worker
export default (
options: { imageData: ImageData; matrix: number[] },
done: (err: string, imageData: ImageData) => void
): void => {
const { imageData, matrix } = options;
if (!matrix) return done(null, imageData);
// calculate kernel weight
let kernelWeight = matrix.reduce((prev, curr) => prev + curr);
@rikschennink
rikschennink / simulate-pointers.js
Created July 9, 2021 12:20
A script to simulate pointer events, very specific to Pintura project so might need some customisation to work with yours
{
const DEBUG = false;
const style = document.createElement('style');
style.textContent = `
.sim-pointer {
margin-top: -1px;
position: absolute;
z-index: 9999999999999;
left: -24px;
@rikschennink
rikschennink / code-macro.njk
Created January 14, 2021 13:40
A macro that generates faux code SVG path elements
{% macro codeline(x, y, totalStatements, spaceWidth) %}
{% set offset = x %}
{% for i in range(0, totalStatements) -%}
{% set width = [2, 4, 8, 12, 24] | random %}
{% set opacity = [0.5, 0.75, 1] | random %}
<path d="M{{ offset }} {{ y }} h{{width}}" opacity="{{ opacity }}"/>
{% set offset = offset + width + spaceWidth %}
{% endfor %}
@rikschennink
rikschennink / nudgeable.ts
Last active October 22, 2023 05:53
⌨️ A Svelte action to add arrow key interaction to an element
export default (element: HTMLElement, options: any = {}) => {
// if added as action on non focusable element you should add tabindex=0 attribute
const {
direction = undefined,
shiftMultiplier = 10,
bubbles = false,
stopKeydownPropagation = true,
} = options;
@rikschennink
rikschennink / cloudinary.js
Last active February 9, 2024 16:15
FilePond Cloudinary
const createCloudinary = (cloudName, unsignedUploadPreset) => ({
process: (fieldName, file, metadata, load, error, progress, abort) => {
// `fieldName` and `meta` are not used for now
const url = `https://api.cloudinary.com/v1_1/${cloudName}/upload`;
const xhr = new XMLHttpRequest();
const formData = new FormData();
@rikschennink
rikschennink / gist:a906d3da0ded79738364b26a5c8167f6
Last active August 27, 2018 14:55
Twitter muted words (this doesn't mean I'm not interested in them, I just don't want them distracting me from front-end related info)
zwarte pieten, zwarte piet, democracy, @realDonaldTrump, referendum, Vote Leave, women in tech, lgbt+, lgbt, she-ra, #remain, NHS, russians, russian, politics, milo, kardashian, sarah sanders, capitalist, Socialist, socialism, capitalism, linkedin, politician, Russia, Musk's, Mansplainers, Mansplains, Mansplain, Mansplainer, government, musk, Cambridge Analytica, handmaids, soccer, football, mansplaining, west world, dolores, westworld, conservatives, Nigel Farage, men, harassment, health care, Tory, flat earth, feminist, feminism, religious, religion, republican, republicans, white house, comey, climate change, trans, pizzagate, ar-15, Putin, NRA, trans people, Cis people, vagina, blackmirror, Black Mirror, healthcare, tories, tax bill, white supremacy, male colleague, white men, PoC, white walker, #GameOfThrones, game of thrones, ukip, nazism, fascism, fascis, fascist, racial, Nazis, Trump's, bitcoin, Brexiters, diversity, brexit, confederate, antifa, nazi, sexism, supremist, racist, racism, sexist, Trump
const easeInOutSine = t => -0.5 * (Math.cos(Math.PI * t) - 1);
export const addGradientSteps = (
// the gradient to add the steps to
gradient,
// the color of the gradient (in rgb) and target alpha value
color = [0, 0, 0], alpha = 1,
// the ease function to use and the amount of steps to render (higher is more precision)