Skip to content

Instantly share code, notes, and snippets.

View jonathansanchez's full-sized avatar
🏠
Working from home

Jonathan Sánchez jonathansanchez

🏠
Working from home
View GitHub Profile
@jonathansanchez
jonathansanchez / cors.md
Created September 28, 2020 00:12 — forked from jesperorb/cors.md
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
@jonathansanchez
jonathansanchez / SomeClass.java
Last active September 23, 2019 15:44
Log4j2 In Spring Boot
package com.some.package;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class SomeClass {
private static final Logger logger = LogManager.getLogger(SomeClass.class);
public void someMethod() {
@jonathansanchez
jonathansanchez / TestController.php
Last active September 9, 2019 12:26
Receive post json from request on silex
<?php
final class TestController extends SomeBaseController
{
private $someService;
public function __construct(SomeService $someService)
{
parent::__construct($someService);
$this->someService = $someService;

Common Options

-#, --progress-bar Make curl display a simple progress bar instead of the more informational standard meter.

-b, --cookie <name=data> Supply cookie with request. If no =, then specifies the cookie file to use (see -c).

-c, --cookie-jar <file name> File to save response cookies to.

<?php
final class Rut {
/**
* Check a valid Rut
* @param string $rut
* @return boolean
*/
public static function validate(string $rut): bool
@jonathansanchez
jonathansanchez / LaravelLogger.php
Last active July 19, 2018 16:12
Passing Request object to Infrastructure Service on Laravel 5.4
<?php namespace App\Infrastructure\Logging\Laravel;
use App\Infrastructure\Logging\Logger;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
final class LaravelLogger implements Logger
{
/** @var Request */
private $request;
@jonathansanchez
jonathansanchez / examplePredis.php
Created May 25, 2018 13:50
Basic Example Predis
<?php
require "predis/autoload.php";
PredisAutoloader::register();
try {
$redis = new PredisClient();
/**
* Por defecto conecta así, por lo que no es necesario agregar esta info.
*
@jonathansanchez
jonathansanchez / AjaxController.php
Created March 14, 2018 18:14
Send AJAX POST file on Laravel
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class ActivationPostPagoController extends Controller
{
.
.
@jonathansanchez
jonathansanchez / Validator.php
Created March 6, 2018 16:46
Server side validation ReCaptcha
<?php
namespace App\Exceptions;
/**
* Class Validator to sanitize
* manually fields from Request.
* @package App\Exceptions
*/
class Validator extends \Exception
@jonathansanchez
jonathansanchez / callbak.php
Created February 19, 2018 20:04
Example: html button to get contacts from Outlook/Live/Hotmail in Graph Outlook
<?php
// initiate cURL resource
$ch = curl_init();
// where you want to post data
$url = "https://login.microsoftonline.com/common/oauth2/v2.0/token";
curl_setopt($ch, CURLOPT_URL,$url);
// tell curl you want to post something
curl_setopt($ch, CURLOPT_POST, true);