Skip to content

Instantly share code, notes, and snippets.

View chrisdempsey's full-sized avatar

Chris Dempsey chrisdempsey

View GitHub Profile
@devkinetic
devkinetic / _default-variables.scss
Created May 4, 2020 17:15
Backport Bootstrap 4 spacing classes to Bootstrap 3 SASS/SCSS
//== Spacing
//
$grid-breakpoints: (
xs: 0,
sm: $screen-sm-min,
md: $screen-md-min,
lg: $screen-lg-min
);
$spacer-x-0: 0rem;
$spacer-y-0: 0rem;
@NatemcM
NatemcM / createImg.pthumnb.modx.php
Last active January 15, 2021 00:22
A snippet that creates a <picture></picture> element with webp & jpg sources using pThumb with different media sizes depending on layout for bootstrap
<?php
$img_src = $modx->getOption('src', $scriptProperties);
$img_alt = $modx->getOption('alt', $scriptProperties);
$img_width = $modx->getOption('width', $scriptProperties,640);
$is_lazy = $modx->getOption('lazy', $scriptProperties, false);
$img_class = $modx->getOption('class', $scriptProperties, 'img-fluid');
$colums = $modx->getOption('cols', $scriptProperties, '{"xs":12,"sm":12,"md":8,"lg":6,"xl":6}');
$img_type = $modx->getOption('type', $scriptProperties, 'jpg');
$dataAttr = '';
@wazum
wazum / aspect_ratio.php
Last active October 26, 2023 13:41
PHP Calculate aspect ratio from width and height
<?php
function getAspectRatio(int $width, int $height)
{
// search for greatest common divisor
$greatestCommonDivisor = static function($width, $height) use (&$greatestCommonDivisor) {
return ($width % $height) ? $greatestCommonDivisor($height, $width % $height) : $height;
};
$divisor = $greatestCommonDivisor($width, $height);
@alamis
alamis / Постраничная навигация bootstrap 4 (pdoPage)
Created January 6, 2017 18:06
вывод ресурсов с навигацией Modx Revo
<div class="row">
[[!pdoPage?
&parents=`3`
&depth=`0`
&tpl=`tpl-podcat`
&includeTVs=`image`
&sortdir=`ASC`
&limit=`4`
&tplPageWrapper=`@INLINE <nav aria-label="pagination"><ul class="pagination">[[+first]][[+prev]][[+pages]][[+next]][[+last]]</ul></nav>`
&tplPageFirst=`@INLINE <li class="page-item"><a class="page-link" href="[[+href]]">Первая</a></li>`
@vidhav
vidhav / collections.imageplus.js
Last active April 12, 2024 11:43
Custom MODX Collections renderer for Image+
Collections.renderer.imageplus = function(value, metaData, record, rowIndex, colIndex, store) {
if (value != '' && value != null) {
var data = Ext.decode(value);
var url = MODx.config.connectors_url + 'system/phpthumb.php?imageplus=1';
var params = {};
params.src = MODx.config['collections.renderer_image_path'] + data.sourceImg.src;
params.w = 100;
if (data.sourceImg.src.indexOf('.png') !== -1) {
params.f = 'png';
@adityasatrio
adityasatrio / MySqlBackup.bat
Created July 1, 2015 04:02
Mysql Backup Script For Windows
@echo off
set dbUser=root
set dbPassword=password
set backupDir="F:\AdityaSatrioNugroho\testbackupDb-bat\"
set mysqldump="C:\xampp\mysql\bin\mysqldump.exe"
set mysqlDataDir="C:\xampp\mysql\data"
set zip="C:\Program Files\7-Zip\7z.exe"
:: get date
@andronex
andronex / exampleQueries
Last active August 20, 2020 11:28
Примеры выборок из БД в MODX и кол-во запросов к БД в зависимости от конструкции и способа запроса.
Все примеры расположены в порядке уменьшения нагрузки на БД и при равенстве кол-ва запросов в порядке уменьшения кол-ва строк кода. Сверху самый ресурсоёмкий по кол-ву запросов к БД.
///////////////////////////////////////////////////////////
Пустая страница MODX при отключенном кэше:
кол-во зпросов/время запросов/время выполнения PHP кода/общее время
6/0.0002 s/0.0336 s/0.0338 s
***********************************************************
1-ый код с pdoFetch, все методы:
$pdo = $modx->getService('pdoFetch');
$pdo->setConfig(array(
@thoroc
thoroc / getdate.bat
Created March 25, 2015 10:48
Auto MySQL Backup For Windows Servers By Matt Moeller
@ECHO off
SETLOCAL
IF [%1]==[] goto s_start
ECHO GETDATE.cmd
ECHO Returns the date independent of regional settings
ECHO Creates the environment variables %v_year% %v_month% %v_day%
ECHO.
ECHO SYNTAX
ECHO GETDATE
@christianseel
christianseel / fix-file-permissions
Created March 13, 2015 14:07
fix file and folder permissions for MODX
<?php
switch($modx->event->name) {
case 'OnFileManagerDirCreate':
$modx->log(modX::LOG_LEVEL_ERROR, 'fix folder permissions for: '.$directory.'/');
chmod($directory.'/', octdec($modx->getOption('new_folder_permissions')));
break;
case 'OnFileManagerFileCreate':
$modx->log(modX::LOG_LEVEL_ERROR, 'fix file permissions for: '.$path);
chmod($path, octdec($modx->getOption('new_file_permissions')));
break;
@lmartins
lmartins / functions.php
Last active November 3, 2023 19:28 — forked from woogist/functions.php
By default WooCommerce redirects the user to the My Account page after a successful login. You may change this and use a custom URL based on the user role, like the Dashboard for admins and My Account page for customers. To do this, add this code at the end of the file functions.php located in wp-content/themes/your-theme-name/ https://support.w…
<?php
/**
* Redirect users to custom URL based on their role after login
*
* @param string $redirect
* @param object $user
* @return string
*/
function wc_custom_user_redirect( $redirect, $user ) {
// Get the first of all the roles assigned to the user