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 / databases.yml
Created June 10, 2018 21:46 — forked from serapheem/databases.yml
Symfony - SQLite database connection
test:
doctrine:
param:
dsn: 'sqlite::memory:'
# dsn: 'mysql:host=localhost;dbname=clipkit_dev'
# dsn: 'sqlite:%SF_DATA_DIR%/test-doctrine.db'
statistic:
param:
dsn: 'sqlite::memory:'
tracking:
function CallAPI($method, $url, $data = false)
{
$curl = curl_init();
switch ($method)
{
case "POST":
curl_setopt($curl, CURLOPT_POST, 1);
if ($data)
@somoza
somoza / .php
Created July 8, 2018 23:13
Filtro por fecha Desde y Hasta Symfony 1.4
$this->widgetSchema['membership_start'] = new sfWidgetFormFilterDate(
array(
'from_date' => new sfWidgetFormJQueryDate(array(
'config' => '{}',
'culture' => 'es',
'config' => "{firstDay: 1, dayNamesMin: ['Do', 'Lu', 'Ma', 'Mi', 'Ju', 'Vi', 'Sa'],
monthNames: ['Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre']}",
'date_widget' => new sfWidgetFormDate(array('format' => '%day%-%month%-%year%'))
)),
'to_date' => new sfWidgetFormJQueryDate(array(
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) {
@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);
}
@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 / 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 / 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 / sort_array.php
Created February 3, 2020 21:11
Sort multidimensional array
$response = [
[
'position'=> 1,
'name' => 'Test',
],
[
'position'=> 2,
'name' => 'Test2',
],
]
relative_urls: false,
remove_script_host: true,