Skip to content

Instantly share code, notes, and snippets.

View AkramiPro's full-sized avatar
🎯
I may be slow to respond.

Mahdi Akrami AkramiPro

🎯
I may be slow to respond.
View GitHub Profile
@jesperorb
jesperorb / cors.md
Last active February 21, 2024 14:17
Handle CORS Client-side

Handle CORS Client-side

Cross-origin resource sharing (CORS) is a mechanism that allows restricted resources (e.g. fonts) on a web page to be requested from another domain outside the domain from which the first resource was served. This is set on the server-side and there is nothing you can do from the client-side to change that setting, that is up to the server/API. There are some ways to get around it tho.

Sources : MDN - HTTP Access Control | Wiki - CORS

CORS is set server-side by supplying each request with additional headers which allow requests to be requested outside of the own domain, for example to your localhost. This is primarily set by the header:

Access-Control-Allow-Origin
@eduwass
eduwass / duplicate-post.php
Last active April 9, 2024 05:32
Programmatically duplicating a WordPress post
<?php
/**
* Duplicates a post & its meta and returns the new duplicated Post ID.
*
* @param int $post_id The Post ID you want to clone.
* @return int The duplicated Post ID.
*/
function duplicate_post(int $post_id): int
{
@topliceanu
topliceanu / alter-ajax-response.js
Created November 30, 2012 10:58
A centralized way to modify jquery ajax responses. Usefull in testing where you need semi-mocks
var alterResponse = function (opts) {
/**
* Function modifies $.ajax responses
* by allowing you to modify ajax response object before each bound success callback.
* Currently it supports only `success` callbacks, `error` and `complete` support to come.
* @param {RegExp} opts.urlMatch - use this to filter calls by url
* @param {String} opts.dataType - Optional - use this to filter calls by response type
* @param {Function} opts.successWrapper - function that gets called before each ajax callback
* - function (options:Object, originalOptions:Object, jqXHR:jQuery.XHR, originalSuccess: Function)
*/