This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function ltrimWord(string $str, array $words): string | |
{ | |
$words = array_map('preg_quote', $words); | |
return preg_replace('/(' . implode('|', $words) . ')/A', '', $str); | |
} | |
function rtrimWord(string $str, array $words): string { | |
$words = array_map('preg_quote', $words); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function pluckObject($arrayOfObjects, string $value, ?string $key = null): array | |
{ | |
$data = []; | |
if ($key) { | |
foreach ($arrayOfObjects as $object) { | |
$data[$object->{$key}] = $object->{$value}; | |
} | |
} else { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## This is my file hugonew | |
## | |
## 1. Place this file where your helper scripts are. For example I have dropbox folder "my_scripts". | |
## Then add this folder to path variable. | |
## 2. cd to folder of your hugo blog and type: | |
## hugonew 'my awesome new nice title' | |
## | |
## this will create file 2022-12-12_my-awesome-new-nice-title.md in content/posts folder (if today is 2022-12-12) | |
## Some dummy ConvertTo-Slug function. scroll to bottom to see code. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//copy this script to hugo content/posts folder and run php rename_files.php and you will get nicely named files with date prefix | |
if (!function_exists('str_ends_with')) { | |
function str_ends_with(string $haystack, string $needle): bool | |
{ | |
$needle_len = strlen($needle); | |
return ($needle_len === 0 || 0 === substr_compare($haystack, $needle, -$needle_len)); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Polyfill for PHP 4 - PHP 7, safe to utilize with PHP 8 | |
if (!function_exists('str_contains')) { | |
function str_contains (string $haystack, string $needle) | |
{ | |
return empty($needle) || strpos($haystack, $needle) !== false; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function echoIfEqual($value1, $value2, $echoText) { | |
if ($value1 == $value2) echo $echoText; | |
} | |
function echoIfEqualChecked($value1, $value2) { | |
echoIfEqual($value1, $value2, 'checked'); | |
} | |
function echoIfEqualSelected($value1, $value2) { | |
echoIfEqual($value1, $value2, 'selected'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
document.body.addEventListener('keydown', function (e) { | |
if (e.key === 'Enter' && e.target.localName === 'textarea' && (e.metaKey || e.ctrlKey) && e.target.form) { | |
e.target.form.requestSubmit(); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class IndexNow | |
{ | |
const LOG = true; | |
public static function submit(array $urls): void | |
{ | |
$data = [ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function arrayToTable(array $rows, string $tableAttributes = ''): string | |
{ | |
if (!$rows) { | |
return ''; | |
} | |
$rowsHeaders = array_keys($rows[0]); | |
$table = "<table {$tableAttributes}><tr>"; | |
foreach ($rowsHeaders as $rowsHeader) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function ISO8601ToSeconds($ISO8601){ | |
$interval = new \DateInterval($ISO8601); | |
return ($interval->d * 24 * 60 * 60) + | |
($interval->h * 60 * 60) + | |
($interval->i * 60) + | |
$interval->s; | |
} | |
function ISO8601ToMinutes($ISO8601){ |
NewerOlder