Skip to content

Instantly share code, notes, and snippets.

Avatar

Stanislav Khromov khromov

View GitHub Profile
@khromov
khromov / tampermonkey-script.js
Last active Aug 12, 2022
Tampermonkey: Find driving slot Trafikverket
View tampermonkey-script.js
// ==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 Jun 9, 2022
WordPress Gutenberg - Add a locked template to a post type
View gutenberg-locked-template.php
<?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 Jun 9, 2022
WordPress Gutenberg - Control allowed blocks by post type
View control-blocks-by-post-type.php
<?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 Aug 24, 2021
docker-compose file for Redis with persistence
View docker-compose.yml
version: "3"
services:
redis:
image: "redis:6.2-alpine"
command: sh -c "redis-server --appendonly yes"
ports:
- "6379:6379"
volumes:
- ./redis-data:/data
@khromov
khromov / README.md
Last active Sep 20, 2020
docker-compose file for phpMyAdmin and MySQL
View README.md
@khromov
khromov / polylang-multilingual-sitemap.php
Last active Sep 15, 2020
Multilingual Polylang sitemaps for "XML Sitemap & Google News" plugin
View polylang-multilingual-sitemap.php
<?php
/**
* Plugin Name: Multilingual Polylang sitemaps for "XML Sitemap & Google News" plugin
* Description: For https://wordpress.org/plugins/xml-sitemap-feed/
* Version: 1.0
*/
add_action('xmlsf_tags_after', function () { // xmlsf_tags_after
//Bail early.
if (!function_exists('pll_languages_list')) {
View functions.php
<?php
// Your themes functions.php
add_action( 'init', function() {
add_rewrite_rule(
'recipe/([0-9]+)/?$',
'index.php?pagename=recipe&recipe_id=$matches[1]',
'top' );
});
View built-share-[id].js
(window.webpackJsonp = window.webpackJsonp || []).push([
[21], {
"+51p": function(t, n, e) {
"use strict";
e.r(n), e.d(n, "__N_SSP", (function() {
return m
}));
var o = e("q1tI"),
r = e.n(o),
c = e("8Kt/"),
@khromov
khromov / PWAOfflineStatus.js
Last active Jul 26, 2020
React Progressive Web App Online / Offline warning message hook
View PWAOfflineStatus.js
import React, { useState, useEffect } from 'react';
function PWAOfflineStatus(props) {
const [isOnline, setOnlineStatus] = useState(true);
// https://stackoverflow.com/questions/44756154/progressive-web-app-how-to-detect-and-handle-when-connection-is-up-again
useEffect(() => {
const setFromEvent = function(event) {
if(event.type === 'online') {
setOnlineStatus(true);
@khromov
khromov / README.md
Last active May 16, 2020
Migrate an Amazing Marvin list to Wallabag
View README.md

Migrate an Amazing Marvin reading list to Wallabag

Example: You've been using the Amazing Marvin Bookmarklet and now the tasks have piled up and Marvin is acting sluggish. Wallabag is a prefect place to migrate these bookmarks.

Prerequisites

  • PHP 7
  • Python 3

Process

  • Export one or more of your reading lists containings URLs from Amazing Marvin by going to Account > Backups > Backup.