Skip to content

Instantly share code, notes, and snippets.

@owenconti
owenconti / intersection.sql
Created July 5, 2024 04:04
MySQL 8.2 Intersection not working
create table users (id int);
create table posts (id int, user_id int);
create table articles (id int, user_id int);
insert into users values (1), (2), (3), (4); -- Creating 4 users
insert into posts values (1, 2); -- Creating posts for user_id=2 ONLY
insert into articles values (1, 2); -- Creating articles for user_id=2 ONLY
select
id as 'user_id',
@owenconti
owenconti / gist:3f22d4825105a6ae3f364badd1156450
Created February 18, 2024 04:03
prompt for generating test classes
[
{
"role": "system",
"content": "You are a bot that generates Laravel Tests for given input files. You are an expert in your field. You prioritize standardization and consistency."
},
{
"role": "user",
"content": "I will provide to you a series of input files. I need you to generate a single Laravel test class as your output. Please put the contents of the generated test f
ile in a JSON object with the key: \"test_class\". Please also generate a file name for the test class and put it in the JSON object with the key: \"file_name\"."
},
@owenconti
owenconti / Category.php
Created August 11, 2021 16:35
Orbit relationships
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Schema\Blueprint;
use Orbit\Concerns\Orbital;
class Category extends Model
{
@owenconti
owenconti / 07856b2c-20cc-484e-9122-78475c0c5966.php
Last active August 3, 2021 16:47
Logging messages to Slack channels with Laravel
<?php
return [
'slack' => [
'driver' => 'slack',
'url' => env('LOG_SLACK_WEBHOOK_URL'),
'username' => 'Oh See Snaps',
'emoji' => ':boom:',
'level' => 'error'
],
@owenconti
owenconti / 3ec04f3e-3f53-4ffa-9f97-e4852ea43aea.js
Created July 11, 2021 04:19
Create a reverse proxy with Cloudflare Workers
addEventListener("fetch", (event) => {
event.respondWith(
handleRequest(event.request).catch(
(err) => new Response(err.stack, { status: 500 })
)
);
});
async function handleRequest(request) {
const { search } = new URL(request.url);
@owenconti
owenconti / 6cfd07c7-4c2a-48aa-a348-e7de71227e49.javascript
Last active July 11, 2021 04:16
Create a reverse proxy with Cloudflare Workers
addEventListener("fetch", (event) => {
event.respondWith(
handleRequest(event.request).catch(
(err) => new Response(err.stack, { status: 500 })
)
);
});
async function handleRequest(request) {
const { search } = new URL(request.url);
@owenconti
owenconti / 1923784f-028d-45d1-924e-16fcb12ce38c.php
Last active July 8, 2021 16:07
Temporary relationship trait for Laravel
<?php
namespace App\Models\Traits;
trait TemporaryRelationships
{
/**
* Returns the value of the given relationship from the current model.
*
* If the relation is already loaded, it is returned directly.
@owenconti
owenconti / 1b5a12c4-fb4b-4cb1-a7f9-119a58562550.php
Created June 11, 2021 17:02
whereHasAll functionality in Laravel
$authorIds = [1, 2];
Post::whereHas('authors', function ($query, $authorIds) {
$query->whereIn('id', $authorIds);
}, '=', count($authorIds))->get();
@owenconti
owenconti / 09801f6a-e1b4-4c16-b742-a50f57cc6a85.yml
Created April 12, 2021 16:33
Failing to start MySQL inside GitHub Actions
services:
mysql:
image: mysql:8
env:
MYSQL_USER: laravel_user
MYSQL_PASSWORD: laravel_pass
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: laravel_db
ports:
- 3306:3306
@owenconti
owenconti / 10614453-afca-4647-9eda-c1f09aa26717.sh
Last active March 19, 2022 12:10
Replacing Laravel Mix with Vite
// Vue 2
npm install --save-dev vite vite-plugin-vue2 dotenv @vue/compiler-sfc
// Vue 3
npm install --save-dev vite @vitejs/plugin-vue dotenv @vue/compiler-sfc