Skip to content

Instantly share code, notes, and snippets.

@Rattone
Rattone / bootstrap-sail.sh
Created November 13, 2023 21:29 — forked from njbair/bootstrap-sail.sh
Install Laravel Sail into an existing project without PHP & Composer
#!/bin/sh
# Installs Laravel Sail into an existing project
# The official Laravel Sail docs[1] provide instructions for installing Sail
# into an existing PHP application. But the official method requires invoking
# Composer locally. Part of Sail's appeal is that it removes the need to
# install PHP on your host machine.
# This script is lifted from laravel.build[2], and thus uses the same method
@Rattone
Rattone / index.php
Last active April 5, 2022 09:53
Get all subarrays of a given $array with sum divisible by a given $divider
<?php
$array = [5, 10, 11, 9, 5];
$divider = 3;
$subArrays = [];
$subArraysIndex = 0;
for ($start = 0; $start <= count($array); $start++) {
@Rattone
Rattone / deploy.sh
Created June 24, 2019 09:26 — forked from BenSampo/deploy.sh
Laravel deploy script
# Change to the project directory
cd /home/forge/domain.com
# Turn on maintenance mode
php artisan down
# Pull the latest changes from the git repository
# git reset --hard
# git clean -df
git pull origin master
@Rattone
Rattone / index.php
Created October 9, 2018 14:52
FCM Simple Notifications in PHP
<?php
$token = 'xxxxx';
$title = 'Testo notifica';
$fcmUrl = 'https://fcm.googleapis.com/fcm/send';
$serverKey = 'xxxxx';
$notification = [
'title' => $title,
@Rattone
Rattone / roundForHumans.php
Created April 6, 2017 08:49 — forked from ludo237/roundForHumans.php
Round numbers in order to have something more human readable
<?php
/**
* Round a number into an human readable number
*
* The idea is to converts numbers like 999,999 into something like 0.9M or 999.99K
* using the scientific notation.
*
* @param $number
*
* @return string
@Rattone
Rattone / index.html
Created January 24, 2017 10:40
Persistent Header elements like Instagram
<article class="persist-area">
<h1 class="persist-header">PERSIST HEADER 0</h1>
...<br>
...<br>
...<br>
...<br>
...<br>
...<br>
...<br>
...<br>
<?php
// previene injection
function addslashes_deep($value)
{
return is_array($value) ? array_map('addslashes_deep', $value) : addpslashes($value);
}
$_POST = array_map('addslashes_deep', $_POST);
$_GET = array_map('addslashes_deep', $_GET);
@Rattone
Rattone / mysql-function-slugify.sql
Created July 17, 2016 00:49
MySQL stored function to create a slug
DROP FUNCTION IF EXISTS `slugify`;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost`
FUNCTION `slugify`(dirty_string varchar(200))
RETURNS varchar(200) CHARSET latin1
DETERMINISTIC
BEGIN
DECLARE x, y , z Int;
Declare temp_string, new_string VarChar(200);
Declare is_allowed Bool;
@Rattone
Rattone / randomCode.php
Last active March 21, 2018 14:14 — forked from justinkelly/randomCode.php
Simple PHP function to generate a random apha-numeric code with only readable characters
<?php
/*
* Simple PHP function to generate a random apha-numeric code with only readable characters
*/
function randomCode($length=4)
{
/* Only select from letters and numbers that are readable - no 0 or O etc..*/
$characters = '23456789ABCDEFHJKLMNPRTVWXYZ';
$string = '';