Skip to content

Instantly share code, notes, and snippets.

View periplox's full-sized avatar

Sebastian Fernandez periplox

  • Buenos Aires, Argentina
View GitHub Profile
@periplox
periplox / preview_route.php
Last active March 15, 2025 17:22
Laravel route for preview default template using a route. Very useful when while editing the theme form mail messages.
Route::get('/email/preview', function() {
return (new Illuminate\Notifications\Messages\MailMessage)
->greeting('Welcome, John Doe!')
->line('Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.')
->action('Sample button', 'https://laravel.com/')
->render();
});
@periplox
periplox / validateCuitCuil.js
Last active April 19, 2022 18:40
Función de JS para validación de CUIT/CUIL (Argentina)
function validateCuitCuil(num) {
const multipliers = [5, 4, 3, 2, 7, 6, 5, 4, 3, 2, 1];
const validPrefixes = [20, 23, 24, 27, 30, 33, 34];
const digits = num.toString().split('');
const prefix = parseInt(digits[0]+digits[1]);
if (digits.length != 11 || !validPrefixes.includes(prefix)) return false;
const reduction = digits.reduce((carry, value, index) => {
return carry + (value * multipliers[index])
@periplox
periplox / validateCuitCuil.php
Last active April 19, 2022 18:09
Función de PHP para validar CUIT/CUIL (Argentina)
<?php
function validateCuitCuil($num)
{
$multipliers = [5, 4, 3, 2, 7, 6, 5, 4, 3, 2, 1];
$valid_prefixes = [20, 23, 24, 27, 30, 33, 34];
$digits = array_map('intval', str_split($value));
$prefix = intval($digits[0].$digits[1]);
@periplox
periplox / updateQueryString.php
Last active December 4, 2018 20:47
Simple function to update query strings. It adds new parameters, updates existing ones and return the updated string.
<?php
function updateQueryString($oldQuery, $newQuery) {
// Parse old string into array
parse_str($oldQuery, $oldParams);
// Parse new string into array
parse_str($newQuery, $newParams);
// Merge both arrays recursivley
$merged = array_replace_recursive($oldParams, $newParams);
//Return the result parsed into a query string