Skip to content

Instantly share code, notes, and snippets.

@Yalme
Yalme / php_cors_header_examples.php
Created November 17, 2023 17:33
PHP CORS Access Control Cross-Origin Header
<?php
// if you want pass all
header('Access-Control-Allow-Origin: *');
// if you want limit by domain
header('Access-Control-Allow-Origin: https://domain.com');
// if you want limit by multiple domains
// list of allowed domains
@Yalme
Yalme / easy css js tabs
Created April 3, 2023 16:33
easy css js tabs
<script>
$(document).ready(function() {
$('.yal-tabs .tabs-header .tab').on('click', function(e) {
// console.log('asfasdfa 1');
if (!$(this).hasClass('active')) {
$(this).closest('.yal-tabs').find('.tabs-header .tab').removeClass('active');
$(this).addClass('active');
let p = $(this).index();
// console.log('asfasdfa 3 pos: ' + p);
@Yalme
Yalme / .gitignore
Created November 21, 2022 20:01
Example of web development based .gitignore file
# Common paths
**/lib/
**/libs/
**/cache/
**/vendor/
**/uploads/
**/images/
**/imgs/
**/files/
**/fonts/
@Yalme
Yalme / gist:5d2af34008100bc8874b7322fd82b372
Created October 12, 2022 20:41
Google reCapcha renders out of screen FIX
// So, if after you submit form, recaptcha challenge/puzze appears outside of current view screen, you can fix this by adding simple CSS rule:
body > div > div > iframe { position: fixed; z-index: 9999; top: 10px; }
// This will force exactly recaptcha iframe to appear inside visible area, on top of other elements.
// If you want to say thanks:
// ETH 0x79B3a1febF8b3Aa6DAC1227237d1d0E0B015cbc2
// BTC bc1qlp4f8jzrpj4yajj5dpy00lkj65vp8gy6dccv8d
// https://donationalerts.com/r/yalme
@Yalme
Yalme / get_svg.php
Created August 3, 2022 22:56
Get SVG through PHP with cache
function get_svg($path = '')
{
// yal_debug($path);
if (empty($path)) return '';
static $cache = array();
$svg = '';
$key = md5($path);
if (!empty($cache[$key])) {
$svg = $cache[$key];
} else {
/* ---------- reset ---------- */
*{box-sizing:border-box;padding:0;margin:0;font:inherit;}b,strong{font-weight:bold}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}img{border:0}button,input,optgroup,select,textarea{font-family:inherit;}article,aside,details,figcaption,figure,footer,header,hgroup,menu,nav,section,main{display:block}table{border-collapse:collapse;border-spacing:0}
/* variables */
:root {
--id-1-color: #219653; /* news */
--text-grey: #443E3E;
--mobile-h1-size: 1.8rem;
<!-- Код для проброса utm меток и др параметров через все внутренние и внешние ссылки -->
<!--<script src="https://fatma.ru/test/tmp/tilda_utm_transfer.js" type="text/javascript"></script>-->
<script type="text/javascript">
$(function() {
yalTransferParams();
});
@Yalme
Yalme / google_recaptcha_multiple_invisible.php
Last active August 19, 2022 20:15
Multiple Invisible Google Recaptcha
//// multiple invisible recaptca, dont forget tot set $g_recaptcha_secret and data-sitekey
//// FORM / add to any form you want to check attribute like this
<form data-recaptcha="1"></form>
//// HTML / add this one time in any place, before body tag for example -->
<script>
var yal_grecaptcha_form;
var yal_grecaptcha_form_executed = false;
@Yalme
Yalme / hello_world_in_patterns.php
Created September 8, 2021 12:54
"Hello World" in patterns (overengineering).
<?php
/********************************************************************
Model-View-Controller implementation according to POSA
(Pattern-Oriented Software Architecture
http://www.hillside.net/patterns/books/Siemens/book.html)
********************************************************************/
class HelloWorldController {
private $model;
function __construct($model) {
// подключаем автолоад и запускаем общий кеш
require_once $PATHS['FILE']['ROOT'].'system'.DS.'vendor'.DS.'autoload.php';
use Phpfastcache\CacheManager;
use Phpfastcache\Config\ConfigurationOption;
CacheManager::setDefaultConfig(new ConfigurationOption([
'path' => $PATHS['FILE']['ROOT'].'system'.DS.'cache'.DS, // or in windows "C:/tmp/" // 'path' => sys_get_temp_dir(),
]));
$cache = CacheManager::getInstance('files');
// Тест работы кеша