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 / 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 / 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 / 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 / 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 / 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 / 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 / advent.js
Created November 29, 2022 13:46
Get the date for all four advent.
class Advent {
#oneDayMs = 86400000;
constructor(year = new Date().getFullYear()) {
this.christmasEve = `${year}-12-24`;
this.christmasEveDate = new Date(this.christmasEve);
}
#getDiff(days) {
return this.christmasEveDate.getDay() + days;
@tobiasroeder
tobiasroeder / to2digits.js
Last active May 15, 2023 13:01
Turn a one digit number into a two digit number string.
/**
* Turn a one digit number into a two digit number string.
*
* If you can not garantee that the number n is a number, simply wrap it with Number(n) to turn the string into a number.
*
* The following three functions are doing the same thing. You can choose which one fits the best purpose for you. The last one has the most legacy support.
*/
/**
* Turn a one digit number into a two digit number string by using the padStart method.
@tobiasroeder
tobiasroeder / dateFormat.js
Created February 2, 2023 09:46
Custom date format prototype.
/**
* Custom date format prototype.
*
* @param {string} format Format character inspired by PHP. @link https://www.php.net/manual/en/datetime.format.php
*
* @returns {string|Date}
*/
Date.prototype.format = function (format) {
const to2digits = n => (n < 10 ? '0' + n : n);
@tobiasroeder
tobiasroeder / better-comments-malibuheme.jsonc
Created April 25, 2023 08:55
Better Comments Malibu Theme
// Default Tags
{
"color": "#c8342a",
"tag": "!"
},
{
"color": "#3c63a6",
"tag": "?"
},
{