Skip to content

Instantly share code, notes, and snippets.

View pferreirafabricio's full-sized avatar
🔥

Fabrício Pinto Ferreira pferreirafabricio

🔥
View GitHub Profile
@pferreirafabricio
pferreirafabricio / select-triggers.sql
Created November 7, 2024 14:15
🎲 A select query to get queries inside a SQL Server database
SELECT
t.name AS TriggerName,
o.name AS TableName,
t.type_desc AS TriggerType,
m.definition AS TriggerDefinition
FROM
sys.triggers t
INNER JOIN
sys.objects o ON t.parent_id = o.object_id
INNER JOIN
@pferreirafabricio
pferreirafabricio / RouteServiceProvider.php
Created June 11, 2024 23:50
Setup rate limit IP whitelist in Laravel 8 application
<?php
namespace App\Providers;
use Illuminate\Cache\RateLimiting\Limit;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\RateLimiter;
use Illuminate\Support\Facades\Route;
@pferreirafabricio
pferreirafabricio / row-count-size-tables.sql
Last active January 24, 2024 12:11
📊 Get row count and size for all tables in SQL Server
SELECT s.Name AS SchemaName,
t.NAME AS TableName,
p.rows AS RowCounts,
CAST(SUM(a.total_pages) * 8 / 1024.0 AS DECIMAL(10, 2)) AS TotalSpaceMB
FROM sys.tables t
INNER JOIN sys.indexes i ON t.OBJECT_ID = i.object_id
INNER JOIN sys.partitions p ON i.object_id = p.OBJECT_ID AND i.index_id = p.index_id
INNER JOIN sys.allocation_units a ON p.partition_id = a.container_id
LEFT OUTER JOIN sys.schemas s ON t.schema_id = s.schema_id
WHERE t.TYPE = 'U'
@pferreirafabricio
pferreirafabricio / laravel-simplier-script.php
Created December 27, 2023 00:36
🐘 A simple start script to build a standalone app using Laravel features
<?php
require __DIR__ . './vendor/autoload.php';
$app = require_once __DIR__ . './bootstrap/app.php';
$kernel = $app->make(\Illuminate\Contracts\Http\Kernel::class);
$response = $kernel->handle(
$request = \Illuminate\Http\Request::capture()
);
@pferreirafabricio
pferreirafabricio / dotnet-watch-not-interactive.ps1
Created November 30, 2023 16:24
🔥 How to make .NET stop asking if you want to reload when you made a change
$env:DOTNET_WATCH_RESTART_ON_RUDE_EDIT = 1
# Or
dotnet watch run --non-interactive
@pferreirafabricio
pferreirafabricio / binding-slots.vue
Created November 20, 2023 18:28
Example of how to bind slots in Vue 2
<template>
<template v-for="(_, slotName) in $slots" v-slot:[slotName]="scope">
<slot :name="slotName" v-bind="scope" />
</template>
</template>
@pferreirafabricio
pferreirafabricio / UnitTestHangFireNSubstitute.cs
Created September 21, 2023 19:25
🧪 How to unit test if a Hangfire Job was enqueued with NSubstitute
var _backgroundJobClient = Substitute.For<IBackgroundJobClient>();
await _someService.MethodThatEnqueueSomething("idXXX");
_backgroundJobClient.Received()
.Create(
Arg.Is<Job>(
job => job.Type == typeof(MyJobClass)
&& job.Args[0].ToString() == "idXXX"
),
@pferreirafabricio
pferreirafabricio / useScrollByDrag.ts
Created September 4, 2023 13:13
🤚 A React Hook to make an HTML element (e.g. a table, list, div with large text) scrollable with the mouse
import { useEffect, useState } from 'react';
export function useScrollByDrag({
elementToScroll,
scrollVelocity = 1,
}: {
elementToScroll: HTMLElement | null;
scrollVelocity?: number;
}) {
useEffect(() => {
@pferreirafabricio
pferreirafabricio / reset-pinia.ts
Created August 5, 2023 13:00
🗑 Basic logic to reset all Pinia stores at same time
import { defineStore, getActivePinia } from "pinia";
const activePinia = getActivePinia();
if (!activePinia) return;
Object.entries(activePinia.state.value).forEach(([storeName, state]) => {
console.debug("Resetting store", storeName);
const storeDefinition = defineStore(storeName, state);
const store = storeDefinition(activePinia);
@pferreirafabricio
pferreirafabricio / UfStatesBrazil.php
Last active February 11, 2023 17:40
🐘 Classe de constantes em PHP com todos os UFs de cada estado do Brasil
<?php
namespace App\Constants;
/**
* Classe com todos os UFs de cada estado do Brasil
*/
class UfStatesBrazil
{
public const ACRE = 'AC';