Skip to content

Instantly share code, notes, and snippets.

View tobiasroeder's full-sized avatar
:octocat:
I <3 </>

Tobias Röder tobiasroeder

:octocat:
I <3 </>
View GitHub Profile
@tobiasroeder
tobiasroeder / wpcf7-spam-filter.php
Last active July 22, 2022 09:41
WordPress Contact Form 7 Spam Filter
<?php
/**
* Contact Form 7 Spam Filter
*/
add_filter( 'wpcf7_spam', function( $spam ) {
if ( $spam )
return $spam;
$spam_key_words = [
@tobiasroeder
tobiasroeder / coming-soon.html
Created April 16, 2022 19:07
Locking/unlocking a website, e.g. for a landing page that is currently in a beta phase.
<h1>Coming Soon</h1>
@tobiasroeder
tobiasroeder / getTomorrow.js
Created March 1, 2022 12:39
Simple and reliable way to get date from tomorrow in JavaScript.
// main idea from https://www.youtube.com/watch?v=PNjNFatebgY&lc=UgzPj8mKHXk4akXfLcR4AaABAg
function getTomorrow( date = Date.now() ) {
let today = new Date(date);
let tomorrow = today.setDate(today.getDate() + 1);
return tomorrow;
}
function formatDate( date ) {
@tobiasroeder
tobiasroeder / better-comments-nordtheme.json
Created February 3, 2022 11:01
Better Comments Nord Theme
{
"better-comments.tags": [
{
"tag": "!",
"color": "#bf616a"
},
{
"tag": "?",
"color": "#81a1c1"
},
@tobiasroeder
tobiasroeder / get1stAdvent.php
Created January 14, 2022 13:28
Get the date for the first advent.
<?php
/**
* @param string $date - [YYYY-MM-DD]
* @return int
*/
function getWeekday( string $date ):int {
// 'w' 0 (for Sunday) through 6 (for Saturday)
$result = (int) date('w', strtotime($date));
@tobiasroeder
tobiasroeder / hashToObject.js
Last active December 4, 2021 08:29
Convert a string (location.hash) into an object.
/**
* convert string (hash) to object
* @param {string} hash
* @returns {object}
*/
function hashToObject(hash) {
let obj = {};
hash = hash.slice(1);
let params = hash.split(',');
params.forEach(param => {
@tobiasroeder
tobiasroeder / chr.php
Created October 18, 2021 14:02
0-9 A-Z a-z
<?php
$chars = '';
// 65 - 122 (A-Za-z)
// 48 - 122 (0-9A-Za-z)
for ($i = 48; $i <= 122; $i++) {
// skip 58 - 64 and 91 - 96
if ($i >= 58 && $i <= 64 || $i >= 91 && $i <= 96)
continue;
@tobiasroeder
tobiasroeder / vigenere.js
Created September 24, 2021 09:15
Vigenère-Chiffre
/*
* source: https://rosettacode.org/wiki/Vigen%C3%A8re_cipher#JavaScript
*/
// vigenere
function vigenere(text, key, decode) {
// helper
const ordA = a => a.charCodeAt(0) - 65;
// main
let i = 0, b;
@tobiasroeder
tobiasroeder / .htaccess
Last active January 15, 2023 08:49
Very simple PHP Router
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
@tobiasroeder
tobiasroeder / hasCssProperty.js
Created May 15, 2021 13:35
Check if an element contains a specific css property.
// returns a boolean if the element contains that property
const hasCssProperty = (elmt, property) => {
const elmtPropertyValue = window.getComputedStyle(elmt, null).getPropertyValue(property);
return elmtPropertyValue ? true : false;
}
// live example
const elmt = document.querySelector('#video');
if (hasCssProperty(elmt, 'aspect-ratio')) {