Skip to content

Instantly share code, notes, and snippets.

@KoljaL
KoljaL / comparison-between-methods-of-applying-the-goo-filter.markdown
Created February 26, 2024 17:12
comparison between methods of applying the goo filter
@KoljaL
KoljaL / Roles_in_Laravel.md
Created October 26, 2023 15:42
Multiple User groups in Laravel

For my Laravel App, I need two types of Users: Staff & Member. Some Staff-User has an "is_admin" flag for more rights.

My first attempt was to create two new User-like Models. But as I found out, and it was recommended to me, that is not the common way.

So now I use the User-Model only for the Login (email, name, password & role) and to divide the User-Types by a role field. That worked very well for the login procedure.
But if it's necessary to edit some fields of one of the User-Type, it is getting complicated, because there are always two Models to handle.
This is my code to create a new Member, for example:

// Shows all font and background colors on an table,
// use with Greasemonkes or as a browser bookmark
(function () {
'use strict';
function categorizeAndRankColorsWithRanksOnWebsite() {
// let allElements = document.getElementsByTagName('*');
const allElements = Array.from(document.body.getElementsByTagName('*')).filter((element) => element.tagName !== 'STYLE' && element.tagName !== 'SCRIPT');
// console.log('allElements', allElements);
const colorCategories = {
@KoljaL
KoljaL / tools.md
Last active August 10, 2023 12:26

Führungsschiene

Idealo 40€

Akku 10,8V

Amazon 37€
oder
Idealo 30€

Stichsäge DJV185

@KoljaL
KoljaL / css-only-parallax-effect.markdown
Created July 2, 2023 08:20
CSS-Only Parallax Effect
@KoljaL
KoljaL / util.js
Created June 6, 2023 07:16
Collected functions for util.js
// return *positive* remainder of n divided by m.
export function mod(n, m) {
return ((n % m) + m) % m;
}
export function sleep(time) {
return new Promise((res) => setTimeout(res, time));
}
function randInt(a, b) {
@KoljaL
KoljaL / doAPromise.js
Created April 27, 2023 10:45
just a function to imitate a slow promise
let color = 'color: LimeGreen;';
let ms = performance.now();
async function doAPromise(success, timeout) {
return new Promise((resolve, reject) => {
setTimeout(() => {
if (success) {
resolve();
console.log('%cPromise resolved', color, ms);
} else {
@KoljaL
KoljaL / localStore.ts
Created March 21, 2023 21:52
A Svelte store that remembers 🤭
// import { Writable } from 'svelte/store'
import { writable as internal, get } from 'svelte/store'
import { PUBLIC_LOCALSTORAGE_PREFIX as PRFX } from '$env/static/public';
declare type Updater<T> = (value: T) => T
declare type StoreDict<T> = { [key: string]: Writable<T> }
/* eslint-disable @typescript-eslint/no-explicit-any */
const stores: StoreDict<any> = {}

Find the max value in an array

Math.max(...array)

Remove duplicates from an array

[...new Set(array)]

Generate a random number between 1 and 100

@KoljaL
KoljaL / nice-URLs-with-SvelteKit.md
Last active March 2, 2023 23:22
Use two parameters in one route with separator string

nice URLs with SvelteKit

TL;DR

If you want URLs like these:

  • for topics:
    awesome.app/best-topic-in-the-world--t5173