Skip to content

Instantly share code, notes, and snippets.

View sepiariver's full-sized avatar

YJ Tso sepiariver

View GitHub Profile
@sepiariver
sepiariver / performance.conf
Created February 7, 2021 20:03 — forked from JamiesonRoberts/performance.conf
Apache Security Headers Setup for Serverpilot
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"
<?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
.box
{
text-align:center;
padding:0px;
box-shadow:none;
}
.thing,.box-header,.box-footer,.box-bit
{
background:#39f;

Keybase proof

I hereby claim:

  • I am sepiariver on github.
  • I am sepiariver (https://keybase.io/sepiariver) on keybase.
  • I have a public key ASD1X6kMkDJf-qfi4YYBtldsTf2jTVPO46PCj5ur4w6sSQo

To claim this, I am signing this object:

@sepiariver
sepiariver / inSection.snippet.php
Last active December 21, 2017 12:24
Detects if the current MODX Resource is in a predefined list of "sections", and if so returns a string (e.g. a CSS classname).
<?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
sepiariver / readtime.snippet.php
Last active December 21, 2017 12:24
Reading time MODX output filter.
<?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
sepiariver / client_preview.plugin.php
Created February 6, 2017 00:00
MODX 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
sepiariver / filterpathsegment.snippet.php
Created January 24, 2017 02:08
Use the MODX filterPathSegment method to filter a string value into valid URL syntax. Useful for HTML attribute values as well.
<?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
sepiariver / quicklist.snippet.php
Last active December 21, 2017 12:25
Fast snippet for listing MODX Resources. Outputs generic HTML list with link to each Resource. Not template-able except wrapper.
<?php
/**
* quickList
*
* Lists Resourcs super fast. Uses code by Garry Nutting of the MODX Core Team.
*
* @author YJ Tso <yj@modx.com>, Garry Nutting <garry@modx.com>
*
*
* quickList is free software; you can redistribute it and/or modify it
@sepiariver
sepiariver / 0_reuse_code.js
Created July 21, 2016 22:06
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console