Skip to content

Instantly share code, notes, and snippets.

View rikschennink's full-sized avatar

Rik rikschennink

View GitHub Profile
@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 / 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 / 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 / Stylesheet.swift
Last active November 8, 2019 14:38
A UIView extension that adds a style property which allows you to style UI elements using tags.
// Default button style
StyleCollection.addStyle("btn-default", paint: {(view) -> Void in
// These buttons should all have rounded corners and a dropshadow
view.layer.cornerRadius = view.frame.height * 0.5
view.layer.backgroundColor = UIColor(hex:0x294A5F).CGColor
view.layer.shadowColor = UIColor.blackColor().CGColor
view.layer.shadowOffset = CGSizeMake(0, 2)
view.layer.shadowRadius = 2
@rikschennink
rikschennink / README.md
Last active January 29, 2019 09:44
Sass OO Mixins: OOCSS without the HTML clutter

Sass OO Mixins: OOCSS without the HTML clutter

  • Less HTML clutter (caused by all those fragmented class names).
<button class="btn btn-primary btn-large btn-outline">Buy!</button>
  • Descriptive classes (or no classes at all) in the HTML results in cleaner and easier to read HTML.
Buy!