Skip to content

Instantly share code, notes, and snippets.

@n-ramdi
n-ramdi / worker.js
Created April 29, 2021 08:27
Cloudflare worker to bypass Instagram new cross-origin policy on images (fixes net :: ERR_BLOCKED_BY_RESPONSE )
// Instagram started setting cross-origin-resource-policy: same-origin when it sees bad referer headers.
// this change leads to ERR_BLOCKED_BY_RESPONSE error and broken images if instagram image is embedded to external website.
// to mitigate this, simple image proxy can be used.
// Steps to install this worker:
// 1. Create CNAME cdn.<yourdomain.com> in your CloudFlare panel
// 2. Create new worker and put the code below into the worker code
// 3. Setup worker route so the worker launches on your cdn. subdomain.
// 4. Modify your image urls from
// https://scontent-arn2-1.cdninstagram.com/v/t51.2885-15/sh0xxx.jpg
// to:
@n-ramdi
n-ramdi / Function.Array-Chunk-By.php
Created November 13, 2020 10:29 — forked from mcaskill/Function.Array-Chunk-By.php
PHP : Splits an array into chunks using a callback function.
<?php
if (!function_exists('array_chunk_by')) {
/**
* Splits an array into chunks using a callback function.
*
* Chunks an array into arrays by iteratively applying the $callback function
* to the elements of the $array.
*
* @see https://rlaanemets.com/post/show/group-array-by-adjacent-elements-in-javascript
@n-ramdi
n-ramdi / mag2-redirect.php
Created November 5, 2020 08:51 — forked from Alexander-Pop/mag2-redirect.php
Magento 2 - redirect programmatically #magento2 #module #redirect
<?php
//In controller:
//No need to declare $this->resultRedirectFactory in construct as its auto declared in construct of \Magento\Framework\App\Action\Action to which custom controller should extend.
public function execute()
{
$resultRedirect = $this->resultRedirectFactory->create();
$resultRedirect->setPath('routename/controllerpath/controllername');
$resultRedirect->setPath('');//home
return $resultRedirect;
@n-ramdi
n-ramdi / gist:4716fe634749cbfeddbd11c28170654c
Created September 11, 2020 08:39 — forked from obukhow/gist:5040981
Magento file size and file extensions frontend validation
Validation.addAllThese([
['validate-filesize','The file size should not exceed 100 kb.',function(v, elm){
var maxSize = 102400;
if (navigator.appName == "Microsoft Internet Explorer") {
if (elm.value) {
var oas = new ActiveXObject("Scripting.FileSystemObject");
var e = oas.getFile(elm.value);
var size = e.size;
}
} else {
@n-ramdi
n-ramdi / displaygrid.css
Created September 3, 2020 07:39 — forked from rodenacker/displaygrid.css
Convert Bootstrap grid to css display:grid
/*migrate bootstrap columns to display:grid*/
@supports (display: grid) {
.row {
display: grid;
grid-template-columns: repeat(12, minmax(10px, 1fr));
grid-gap: 0;
margin: 0;
}
.col-md-1, .col-xs-1, .col-lg-1 {