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 / pageReady.js
Created January 10, 2024 07:13
Run code even if it is side-loaded or too late to the party, and do not wait for an event that has already happened.
function main() {
console.info('Page ready...');
}
if (document.readyState === 'complete') {
main();
} else {
window.addEventListener('load', function() {
main();
});
@tobiasroeder
tobiasroeder / .htaccess
Created December 28, 2023 23:15
PHP Environment Variables
<IfModule mod_env.c>
SetEnv CONTEXT Development
</IfModule>
@tobiasroeder
tobiasroeder / create-id.js
Created July 5, 2023 11:31
Create a simple ID with JavaScript.
/**
* Create a simple ID with JavaScript.
*
* @author Tobias Röder
* @version 1.0.0
*
* @param {Number} length
*
* @returns {String}
*/
@tobiasroeder
tobiasroeder / average-color.php
Created June 24, 2023 21:03
Get the average color (HEX) from an JPEG image.
<?php
/**
* Get the average color from an JPEG image.
*
* @param string $image_path Explicit path to the image.
*
* @return string Returns a HEX value.
*/
function average_color(string $image_path): string
@tobiasroeder
tobiasroeder / storage.js
Last active May 29, 2023 20:25
Store data as an single item in the local storage.
/**
* Store data as an single item in the local storage.
*
* @author Tobias Röder
* @version 1.0.0
*
* @property reck
* @property itemName
*
* @method init
@tobiasroeder
tobiasroeder / PseudoCrypt.php
Created May 11, 2023 14:54
A tiny lib to generate obfuscated hashes from integers.
<?php
/**
* PseudoCrypt by KevBurns (http://blog.kevburnsjr.com/php-unique-hash)
* Reference/source: https://stackoverflow.com/a/1464155/933782
*
* @author KevBurns
* @link https://web.archive.org/web/20130727034425/http://blog.kevburnsjr.com/php-unique-hash
*/
@tobiasroeder
tobiasroeder / better-comments-malibuheme.jsonc
Created April 25, 2023 08:55
Better Comments Malibu Theme
// Default Tags
{
"color": "#c8342a",
"tag": "!"
},
{
"color": "#3c63a6",
"tag": "?"
},
{
@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 / 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 / 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;