Skip to content

Instantly share code, notes, and snippets.

View schuhwerk's full-sized avatar

Vitus Schuhwerk schuhwerk

View GitHub Profile
const stringToBool = (s: string) => (s.toString().match(/^(true|[1-9][0-9]*|[0-9]*[1-9]+|yes)$/i) ? true : false)
type levelNames = "emerg" | "alert" | "crit" | "error" | "warn" | "notice" | "info" | "debug"
type logLevel = {
name: levelNames
cb: CallableFunction
defaultEnabled: boolean
}
type callableNames = {
[K in levelNames]: CallableFunction
@schuhwerk
schuhwerk / defaults and types.ts
Last active January 9, 2024 10:28
Infer types from an object. Make object-key prefixed with "_" partials (not required)
// Keys in R overwrite the ones in Default.
type Modify<Default, R> = Omit<Default, keyof R> & R
// get only types where key is prefixed with Prefix.
type FilterPrefixed<O, Prefix extends string> = {
[K in keyof O as K extends `${Prefix}${infer _}` ? K : never]: O[K]
}
/**
* Object-Keys that are not prefixed with "_" become partials.
@schuhwerk
schuhwerk / Trellis WSL.bash
Created November 9, 2022 10:46
Trellis-CLI in Windows (WSL1)
# Do this step by step.
# WSL: https://learn.microsoft.com/de-de/windows/wsl/install
# Trellis-Cli: https://github.com/roots/trellis-cli
# install brew (packet manager) - Just for trellis-cli.
# If you don't have already probably easier to just download and add to Path...
sudo apt update
sudo apt-get install build-essential curl file git
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
@schuhwerk
schuhwerk / get-user-logins.sql
Last active April 5, 2022 10:05
Get the login-times of users (no plugin required).
/*
* Get last login time of WordPress users.
* WordPress stores the last time a user logged in in a serialized array in the usermeta - table.
* Your prefix might be different (xyz_usermeta instead of wp_usermeta).
* @see https://shocksolution.com/2019/04/16/find-last-login-time-for-wordpress-users-in-the-sql-database/
*/
select
wu.user_login,
metatable.*,
FROM_UNIXTIME(metatable.login_time)
@schuhwerk
schuhwerk / convert-myisam-to-innodb.sh
Last active March 5, 2021 20:02
Convert tables (WordPress) to innodb. Run multiple at once...
#!/usr/bin/env bash
# Original Author Mike https://guides.wp-bullet.com
# Edited by Vitus Schuhwerk
# Purpose - Convert MyISAM tables to InnoDB with WP-CLI
# You can run multiple instances of this like this:
# - "bash scriptname 4 0" convert tables 0, 4, 8, ...
# - "bash scriptname 4 1" convert tables 1, 5, 9, ...
# - "bash scriptname 4 2" convert tables 2, 6, 10, ...
# - "bash scriptname 4 3" convert tables 3, 7, 11, ...
@schuhwerk
schuhwerk / composer.json
Created February 13, 2021 22:13
More comoser dependencies spaces.vs.digital
{
"name": "spaces/more-composer-dependencies",
"repositories": [
{
"type": "composer",
"url": "https://wpackagist.org"
}
],
"require": {
"wpackagist-plugin/acf-to-rest-api": "3.*",
@schuhwerk
schuhwerk / composer.json
Last active December 7, 2020 15:23
This is a composer file for testing...
{
"name": "spaces/more-composer-dependencies",
"require": {
"psr/container": "^1.0"
}
}
@schuhwerk
schuhwerk / timing things.php
Last active November 26, 2018 18:34
first draft of endlessly recurring datespans optimised for querying...
<?php
namespace Spaces;
require dirname( __DIR__ ) . '/vendor/autoload.php';
/**
* @see https://github.com/smhg/date-timespan-php
*/
use Timespan\Timespan;
@schuhwerk
schuhwerk / setcookie_samesite_polyfill.php
Last active October 15, 2021 15:04 — forked from bohwaz/setcookie_samesite_polyfill.php
PHP setcookie function polyfill with support for SameSite attribute (compatible with PHP 5.0+)
<?php
/**
* Setcookie function with support for SameSite
* @param string|null $samesite 'Lax' or 'Strict'
*/
function setcookie_samesite( $name, $value = '', $expire = 0, $path = null, $domain = null, $secure = false, $httponly = false, $samesite = null)
{
$header = 'Set-Cookie: '.rawurlencode($name) . '=' . rawurlencode($value).';';
$header .= $expire ? sprintf('expires=%s', gmdate('D, d M Y H:i:s \G\M\T', $expire)).'; ' : '';
@schuhwerk
schuhwerk / font-awesome-4.7.0.json
Last active January 12, 2022 22:22 — forked from zwinnie/font-awesome-4.7.0.json
JSON Of Font Awesome 4.7.0 Icons (That don't collide with UI-Elements)
{
"4.7.0": [
"fa-500px",
"fa-address-book",
"fa-address-book-o",
"fa-address-card",
"fa-address-card-o",
"fa-adjust",
"fa-adn",
"fa-align-center",