Skip to content

Instantly share code, notes, and snippets.

View tjimenez's full-sized avatar

Teodosio Jimenez tjimenez

View GitHub Profile
@tjimenez
tjimenez / force-ctrl-c-v.md
Created June 5, 2025 15:29 — forked from Gustavo-Kuze/force-ctrl-c-v.md
Enable copy and paste in a webpage from the browser console
javascript:(function(){
  allowCopyAndPaste = function(e){
  e.stopImmediatePropagation();
  return true;
  };
  document.addEventListener('copy', allowCopyAndPaste, true);
  document.addEventListener('paste', allowCopyAndPaste, true);
  document.addEventListener('onpaste', allowCopyAndPaste, true);
})(); 
@tjimenez
tjimenez / CreatesWithLock.php
Created October 27, 2022 01:06 — forked from troatie/CreatesWithLock.php
Guard against race conditions in Laravel's firstOrCreate and updateOrCreate
trait CreatesWithLock
{
public static function updateOrCreate(array $attributes, array $values = [])
{
return static::advisoryLock(function () use ($attributes, $values) {
// emulate the code found in Illuminate\Database\Eloquent\Builder
return (new static)->newQuery()->updateOrCreate($attributes, $values);
});
}
@tjimenez
tjimenez / Controller.php
Created December 31, 2021 23:39 — forked from sebastiaanluca/Controller.php
A HasMany relation sync method implementation using macros
<?php
$business->locations()->sync([1, 42, 16, 8]);
@tjimenez
tjimenez / change-enum.php
Created June 22, 2021 20:10 — forked from theconsolelogger/change-enum.php
An example of how to update a Laravel enum column with a migration script.
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
class ChangeEnum extends Migration
{
/**
@tjimenez
tjimenez / change-enum.php
Created June 22, 2021 20:10 — forked from theconsolelogger/change-enum.php
An example of how to update a Laravel enum column with a migration script.
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
class ChangeEnum extends Migration
{
/**
@tjimenez
tjimenez / postgres-brew.md
Created June 21, 2021 19:21 — forked from ibraheem4/postgres-brew.md
Installing Postgres via Brew (OSX)

Installing Postgres via Brew

Pre-Reqs

Brew Package Manager

In your command-line run the following commands:

  1. brew doctor
  2. brew update
@tjimenez
tjimenez / AppServiceProvider.php
Created June 21, 2021 15:46 — forked from simonhamp/AppServiceProvider.php
A pageable Collection implementation for Laravel
<?php
namespace App\Providers;
use Illuminate\Support\Collection;
use Illuminate\Pagination\LengthAwarePaginator;
class AppServiceProvider extends ServiceProvider
{
public function boot()
@tjimenez
tjimenez / ci.yml
Created June 2, 2021 19:08 — forked from stancl/ci.yml
Minimal GitHub Action example for running phpunit
name: CI
on: [ push, pull_request ]
jobs:
tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
@tjimenez
tjimenez / CommonFeatureTest.php
Created October 29, 2020 21:55
Common methods for feature testing
namespace Tests\Feature;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;
class CommonFeatureTest extends TestCase
{
public function test_route_endpoints_exists()
{
@tjimenez
tjimenez / axios-401-response-interceptor.js
Created November 1, 2019 23:38 — forked from yajra/axios-401-response-interceptor.js
Axios 401 response interceptor.
// Add a 401 response interceptor
window.axios.interceptors.response.use(function (response) {
return response;
}, function (error) {
if (401 === error.response.status) {
swal({
title: "Session Expired",
text: "Your session has expired. Would you like to be redirected to the login page?",
type: "warning",
showCancelButton: true,