Skip to content

Instantly share code, notes, and snippets.


YJ Tso sepiariver

View GitHub Profile
sepiariver / performance.conf
Created Feb 7, 2021 — forked from JamiesonRoberts/performance.conf
Apache Security Headers Setup for Serverpilot
View performance.conf
Header set Connection keep-alive
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType image/svg+xml "access 1 month"
ExpiresByType text/css "access 1 month"
ExpiresByType application/pdf "access 1 month"
View classnames.snippet.php
$input = $modx->getOption('input', $scriptProperties, '', true);
$output = $modx->getOption('options', $scriptProperties, '', true);
$classnames = explode(' ', $input);
$results = [];
foreach ($classnames as $token) {
// Strip out any % encoded octets
$normalized = preg_replace('|%[a-fA-F0-9][a-fA-F0-9]|', '', $token);
// Replace _ with - and lowercase for old times' sake
View test.txt

Keybase proof

I hereby claim:

  • I am sepiariver on github.
  • I am sepiariver ( on keybase.
  • I have a public key ASD1X6kMkDJf-qfi4YYBtldsTf2jTVPO46PCj5ur4w6sSQo

To claim this, I am signing this object:

sepiariver / inSection.snippet.php
Last active Dec 21, 2017
Detects if the current MODX Resource is in a predefined list of "sections", and if so returns a string (e.g. a CSS classname).
View inSection.snippet.php
// The Resource ID to test
$id = (int) $modx->getOption('id', $scriptProperties, $modx->resource->get('id'), true);
// Option to return early if Current Resource matches $id
$matchCurrent = $modx->getOption('matchCurrent', $scriptProperties, true);
// IDs of Resources deemed as "sections", against which to test
$sectionIds = array_filter(array_map('trim', explode(',', $modx->getOption('sectionIds', $scriptProperties, ''))));
// IDs of parent Resources, the direct children of which will be added to $sectionIds
$sectionParentIds = array_filter(array_map('trim', explode(',', $modx->getOption('sectionParentIds', $scriptProperties, ''))));
// If the test passes, meaning the Resource has a $sectionId as an ancestor, output this
sepiariver / readtime.snippet.php
Last active Dec 21, 2017
Reading time MODX output filter.
View readtime.snippet.php
$options = (int) $modx->getOption('options', $scriptProperties, 200, true); // 200 words per minute
$wordCount = (int) str_word_count(strip_tags($input)); // To display word count set options to 0
if ($options === 0) return $wordCount;
return ceil($wordCount / abs($options));
sepiariver / client_preview.plugin.php
Created Feb 6, 2017
MODX Client Preview Plugin
View client_preview.plugin.php
if ($modx->context->get('key') === 'mgr') return;
$key = $modx->getOption('key', $scriptProperties, 'my-secret-key');
$val = $modx->getOption('val', $scriptProperties, 'my-secret-value');
switch ($modx->event->name) {
case 'OnHandleRequest':
if (!$modx->getOption('site_status')) {
if ($_GET[$key] === $val) {
$modx->config['site_status'] = 1;
sepiariver / filterpathsegment.snippet.php
Created Jan 24, 2017
Use the MODX filterPathSegment method to filter a string value into valid URL syntax. Useful for HTML attribute values as well.
View filterpathsegment.snippet.php
$options = $modx->getOption('options', $scriptProperties, $modx->getOption('friendly_alias_restrict_chars_pattern'), true);
return $modx->filterPathSegment($input, array('friendly_alias_restrict_chars_pattern' => $options));
sepiariver / quicklist.snippet.php
Last active Dec 21, 2017
Fast snippet for listing MODX Resources. Outputs generic HTML list with link to each Resource. Not template-able except wrapper.
View quicklist.snippet.php
* quickList
* Lists Resourcs super fast. Uses code by Garry Nutting of the MODX Core Team.
* @author YJ Tso <>, Garry Nutting <>
* quickList is free software; you can redistribute it and/or modify it
sepiariver / 0_reuse_code.js
Created Jul 21, 2016
Here are some things you can do with Gists in GistBox.
View 0_reuse_code.js
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console