Skip to content

Instantly share code, notes, and snippets.

View x404's full-sized avatar

Oleksii x404

View GitHub Profile
@x404
x404 / clean_code.md
Created September 17, 2023 12:24 — forked from wojteklu/clean_code.md
Summary of 'Clean code' by Robert C. Martin

Code is clean if it can be understood easily – by everyone on the team. Clean code can be read and enhanced by a developer other than its original author. With understandability comes readability, changeability, extensibility and maintainability.


General rules

  1. Follow standard conventions.
  2. Keep it simple stupid. Simpler is always better. Reduce complexity as much as possible.
  3. Boy scout rule. Leave the campground cleaner than you found it.
  4. Always find root cause. Always look for the root cause of a problem.

Design rules

@x404
x404 / object-empty.js
Created January 10, 2022 17:54 — forked from slavafomin/object-empty.js
JavaScript is Object Empty Function
/**
* Returns true if specified object has no properties,
* false otherwise.
*
* @param {object} object
* @returns {boolean}
*/
function isObjectEmpty(object)
{
if ('object' !== typeof object) {
@x404
x404 / acf_wpml_language_rule.php
Created November 17, 2021 19:08 — forked from theMikeD/acf_wpml_language_rule.php
Adds a language selector to the Location rules for ACF, allowing you to restrict a field group to appear only on admin pages of the selected language.
<?php
/**
* ACF Rule: adds Post Language type
*
* @author @theMikeD
*
* @param array $choices, all of the available rule types
* @return array
*/
function cnmd_acf_rule_type_language( $choices ) {
@x404
x404 / Вывод количества товаров в категории.php Вывод количества товаров в категории minishop2 Сниппет получает сумму всех товаров в категории, с учетом мультикатегорий MS2. Можно указать нужную категорию параметром $parent.
<?php
if (empty($parent)) {$parent = $modx->resource->id;}
$pids = array_merge(array($parent), $modx->getChildIds($parent));
$ids = array();
$q = $modx->newQuery('msProduct');
$q->where(array('class_key' => 'msProduct','parent:IN' => $pids,'published' => 1,'deleted' => 0));
$q->select('`msProduct`.`id`');
if ($q->prepare() && $q->stmt->execute()) {
$ids = $q->stmt->fetchAll(PDO::FETCH_COLUMN);
@x404
x404 / async-await.js
Created December 26, 2017 20:29 — forked from wesbos/async-await.js
Simple Async/Await Example
// 🔥 Node 7.6 has async/await! Here is a quick run down on how async/await works
const axios = require('axios'); // promised based requests - like fetch()
function getCoffee() {
return new Promise(resolve => {
setTimeout(() => resolve('☕'), 2000); // it takes 2 seconds to make coffee
});
}
@x404
x404 / collections.imageplus.js
Created November 29, 2017 09:28 — forked from vidhav/collections.imageplus.js
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';
@x404
x404 / .htaccess
Last active November 7, 2017 20:11 — forked from bartholomej/.htaccess
MODx htaccess for Babel
# MODX htaccess for BABEL (idealab settings)
RewriteEngine On
RewriteBase /
php_flag display_startup_errors on
php_flag display_errors on
php_flag html_errors on
# redirect all requests to /de/favicon.ico and /nl/favicon.ico