Skip to content

Instantly share code, notes, and snippets.

View somoza's full-sized avatar
🔮
Preparing Elixir

Julián Somoza somoza

🔮
Preparing Elixir
View GitHub Profile
@somoza
somoza / tinker.php
Created January 21, 2021 19:57
Find unused translations on Laravel with Tinker By @linktoahref
php artisan tinker
$translations = require resource_path('lang/en/app.php');
$unused_keys = [];
foreach ($translations as $key => $value) {
// Here app is the name of the translation file
// that was required in first step.
// Replace app with the name of the translation file that is been required.
@somoza
somoza / Laravel Countries seeder
Created November 15, 2020 14:33
Just a seeder to populate country tables.
<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
class CountryTableSeeder extends Seeder
{
/**
@somoza
somoza / SomeFilterType.php
Created April 19, 2020 19:23
Filter by DateTime using just date on Symfony 3.4
$builder->add('created', Filters\DateFilterType::class, array(
'widget' => 'single_text',
'label' => 'Fecha',
'html5' => false,
'attr' => ['class' => 'js-datepicker'],
'apply_filter' => function (QueryInterface $filterQuery, $field, $values) {
if (empty($values['value'])) {
return null;
}
relative_urls: false,
remove_script_host: true,
@somoza
somoza / sort_array.php
Created February 3, 2020 21:11
Sort multidimensional array
$response = [
[
'position'=> 1,
'name' => 'Test',
],
[
'position'=> 2,
'name' => 'Test2',
],
]
@somoza
somoza / check_apache.sh
Created December 26, 2019 13:25
Bash to check apache status, restart it and send telegram bot.
#!/bin/bash
telegram=(xxxxx, yyyyyy)
if ! pidof apache2 > /dev/null
then
# web server down, restart the server
echo "Server down"
/etc/init.d/apache2 restart > /dev/null
sleep 10
@somoza
somoza / pagerFanta.php
Last active November 14, 2019 17:53
Sort By manyToOne on Symfony 3 / Doctrine 2 - PagerFanta bundle.
//Add false as second parameter
$adapter = new DoctrineORMAdapter($queryBuilder, false);
@somoza
somoza / resize_crop.php
Created July 2, 2019 03:38
GD crop center differents extentions
function resize_crop_image($max_width, $max_height, $source_file, $dst_dir, $quality = 80)
{
$imgsize = getimagesize($source_file);
$width = $imgsize[0];
$height = $imgsize[1];
$mime = $imgsize['mime'];
switch($mime){
case 'image/gif':
$image_create = "imagecreatefromgif";
@somoza
somoza / move.php
Created June 27, 2019 22:02
Move entire folder and their content with PHP
// Function to remove folders and files
function rrmdir($dir) {
if (is_dir($dir)) {
$files = scandir($dir);
foreach ($files as $file)
if ($file != "." && $file != "..") rrmdir("$dir/$file");
rmdir($dir);
}
else if (file_exists($dir)) unlink($dir);
}
document.addEventListener("DOMContentLoaded", function() {
var elements = document.getElementsByTagName("INPUT");
for (var i = 0; i < elements.length; i++) {
elements[i].oninvalid = function(e) {
e.target.setCustomValidity("");
if (!e.target.validity.valid) {
e.target.setCustomValidity("This field cannot be left blank");
}
};
elements[i].oninput = function(e) {