Skip to content

Instantly share code, notes, and snippets.

View khromov's full-sized avatar

Stanislav Khromov khromov

View GitHub Profile
@khromov
khromov / bundle-size.yaml
Last active November 15, 2023 17:17
GitHub Actions Bundle size comparison
name: 'Bundle Size Comparison'
on:
pull_request:
branches:
- master
jobs:
build:
runs-on: ubuntu-latest
@khromov
khromov / service-worker.ts
Created April 10, 2023 21:17
SvelteKit service worker example
/// <reference types="@sveltejs/kit" />
/// <reference no-default-lib="true"/>
/// <reference lib="esnext" />
/// <reference lib="webworker" />
// https://kit.svelte.dev/docs/service-workers#type-safety
const sw = self as unknown as ServiceWorkerGlobalScope;
import { build, files, version } from '$service-worker';
@khromov
khromov / focused.ts
Last active February 19, 2023 20:20
Svelte window focused action
// Example: <div use:focused={(e) => console.log('Focused, event:', e)}>
export default function focused(node: HTMLElement, callback: Function) {
const handleFocusEvents = (event: Event) => {
callback(event)
};
window.addEventListener('online', handleFocusEvents);
window.addEventListener('focus', handleFocusEvents);
@khromov
khromov / .dockerignore
Last active January 11, 2023 20:04
SvelteKit staged build Dockerfile
node_modules
README.md
.svelte-kit
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.pnpm-debug.log*
.env*.local
.env.local
.env
@khromov
khromov / README.md
Last active January 3, 2023 02:53
DiceBear avatars for WordPress
@khromov
khromov / plugin.php
Created September 17, 2022 21:37
Gutenberg block templates with Advanced Custom Fields
<?php
/*
Plugin Name: Plugin
Version: 1.0
*/
add_action('acf/init', function() {
// Check function exists.
if( function_exists('acf_register_block_type') ) {
@khromov
khromov / tampermonkey-script.js
Last active August 12, 2022 12:48
Tampermonkey: Find driving slot Trafikverket
// ==UserScript==
// @name Find slot
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Book a Förarprov with the place and type (manual/auto) that you want, then go to Boka Prov > Personbil B > Bokade Prov > Press the edit icon for the existing test. Enable the script and reload the page. The script will look for a better time in the same configuration of auto/manual and location.
// @author You
// @match https://fp.trafikverket.se/boka/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=trafikverket.se
// @require https://cdnjs.cloudflare.com/ajax/libs/ion-sound/3.0.7/js/ion.sound.min.js
// @grant none
@khromov
khromov / gutenberg-locked-template.php
Created June 9, 2022 23:41
WordPress Gutenberg - Add a locked template to a post type
<?php
add_action('init', function() {
// For which posts type
$post_type_object = get_post_type_object( 'post' );
// Which allowed blocks
$post_type_object->template = [
['core/heading', ['level' => '5', 'content' => 'Default value']],
['core/paragraph'],
['core/image'],
@khromov
khromov / control-blocks-by-post-type.php
Created June 9, 2022 23:32
WordPress Gutenberg - Control allowed blocks by post type
<?php
add_filter( 'allowed_block_types_all', function($allowed_block_types, $block_editor_context) {
if ( $block_editor_context->post->post_type === 'post' ) {
return [
'acf/my-cool-block',
'core/paragraph'
];
}
return $allowed_block_types;
}, 10, 2 );
@khromov
khromov / docker-compose.yml
Created August 24, 2021 13:55
docker-compose file for Redis with persistence
version: "3"
services:
redis:
image: "redis:6.2-alpine"
command: sh -c "redis-server --appendonly yes"
ports:
- "6379:6379"
volumes:
- ./redis-data:/data