portalzine / HTMX - Process on DOM changes
0 likes
0 forks
1 files
Last active 5 months ago
| 1 | const observer = new MutationObserver((mutations) => { |
| 2 | mutations.forEach((mutation) => { |
| 3 | mutation.addedNodes.forEach((node) => { |
| 4 | if (node.nodeType === 1 && !node["htmx-internal-data"]) { |
| 5 | htmx.process(node) |
| 6 | } |
| 7 | }) |
| 8 | }) |
| 9 | }) |
| 10 | observer.observe(document, {childList: true, subtree: true}) |
portalzine / Protect access to log and sql files
0 likes
0 forks
1 files
Last active 6 months ago
| 1 | # protect access to log and sql files. |
| 2 | <FilesMatch "\.(log|sql)(\.(t?gz|tar|gz|tar\.gz|7z|rar|bz2))?$"> |
| 3 | <IfModule mod_authz_core.c> |
| 4 | Require all denied |
| 5 | </IfModule> |
| 6 | <IfModule !mod_authz_core.c> |
| 7 | Order deny,allow |
| 8 | Deny from all |
| 9 | </IfModule> |
| 10 | </FilesMatch> |
portalzine / Extract text between two tags (domDocument)
0 likes
0 forks
1 files
Last active 7 months ago
| 1 | $tag = "p"; |
| 2 | $html ="I am here!"; |
| 3 | $dom = new domDocument('1.0', 'utf-8'); |
| 4 | $dom->loadHTML($html); |
| 5 | $dom->preserveWhiteSpace = false; |
| 6 | |
| 7 | $findTag = $dom->getElementsByTagName($tag); |
| 8 | |
| 9 | echo $findTag->item(0)->nodeValue; |
portalzine / Randomly reorder a list
0 likes
0 forks
1 files
Last active 7 months ago
| 1 | var reorder = function(selector){ |
| 2 | var ul = document.querySelector(selector); |
| 3 | for (var i = ul.children.length; i >= 0; i--) { |
| 4 | ul.appendChild(ul.children[Math.random() * i | 0]); |
| 5 | } |
| 6 | |
| 7 | } |
portalzine / Syntax Highlighting Class
0 likes
0 forks
2 files
Last active 7 months ago
| 1 | class SyntaxHighlight { |
| 2 | |
| 3 | static $tokens = array();// This array will be filled from the regexp-callback |
| 4 | public static function process($s) { |
| 5 | $s = htmlspecialchars($s); |
| 6 | // Workaround for escaped backslashes |
| 7 | $s = str_replace('\\\\','\\\\<e>', $s); |
| 8 | $regexp = array( |
| 9 | // Punctuations |
| 10 | '/([\-\!\%\^\*\(\)\+\|\~\=\`\{\}\[\]\:\"\'<>\?\,\.\/]+)/' |
portalzine / Getting the average of an array of numbers
0 likes
0 forks
2 files
Last active 7 months ago
| 1 | $average_of_myfoos = array_sum($myfoos) / count($myfoos); |
portalzine / Codekit - Timestamp Hook
0 likes
0 forks
1 files
Last active 7 months ago
| 1 | NOW=`date "+%a %Y-%m-%d %T"` |
| 2 | sed -i -- "s|{{TIMESTAMP}}|${NOW}|g" $CK_OUTPUT_PATH |
portalzine / Translate Slugs (Umlaute)
0 likes
0 forks
1 files
Last active 8 months ago
| 1 | add_filter( 'sanitize_title', '_translate_slug_umlauts', 5, 3 ); |
| 2 | /** |
| 3 | * Transliterates German umlauts in post slugs for both the classic and block editors. |
| 4 | * |
| 5 | * @param string $title The sanitized title. |
| 6 | * @param string $raw_title The title prior to any sanitization. |
| 7 | * @param string $context The context in which the sanitization is occurring. |
| 8 | * |
| 9 | * @return string The modified title with German umlauts transliterated. |
| 10 | */ |
Newer
Older