Skip to content

Instantly share code, notes, and snippets.

View m4s0's full-sized avatar
🏠
Working from home

Marco Masotti m4s0

🏠
Working from home
View GitHub Profile
@m4s0
m4s0 / ArrayFlat.php
Created October 23, 2018 13:11
recursively flatten a multidimensional array
<?php
class ArrayFlat
{
public function execute($arg): array
{
return is_array($arg) ? array_reduce($arg, function ($c, $a) {
return array_merge($c, $this->execute($a));
}, []) : [$arg];
}
@m4s0
m4s0 / yaourt-skip-validity-checks.txt
Created August 31, 2016 18:09
[archlinux] yaourt skip validity checks
yaourt --m-arg "--skippgpcheck" -S {{ package }}
###
--skipinteg
Do not perform any integrity checks (checksum and PGP)
on source files.
--skipchecksums
Do not verify checksums of source files.
@m4s0
m4s0 / js event on page loading.txt
Last active July 18, 2016 08:16
js event on page loading
<script>
var eventHandler =function (event) {
console.log('Event: ' + event.type);
// console.log(event.timeStamp);
console.log('Document state: '+document.readyState);
var end = new Date().getTime();
var time = end - start;
console.log('Execution time: ' + time);
console.log('\n');
@m4s0
m4s0 / AppKernel.php
Created January 21, 2016 16:30
Symfony - Move cache and log dir to shared memory
public function getCacheDir()
{
if (in_array($this->environment, array('dev'))) {
return '/dev/shm/site/cache/' . $this->environment;
}
return parent::getCacheDir();
}
public function getLogDir()
@m4s0
m4s0 / init_permission.sh
Last active January 23, 2016 16:13
Symfony 3.* init permissions folders
#!/usr/bin/env bash
HTTPDUSER=`ps aux | grep -E '[a]pache|[h]ttpd|[_]www|[w]ww-data|[n]ginx' | grep -v root | head -1 | cut -d\ -f1`
FOLDERS="var/cache var/logs var/sessions"
sudo setfacl -R -m u:"$HTTPDUSER":rwX -m u:`whoami`:rwX $FOLDERS
sudo setfacl -dR -m u:"$HTTPDUSER":rwX -m u:`whoami`:rwX $FOLDERS
sudo chown -R `whoami`:`whoami` $FOLDERS
@m4s0
m4s0 / Mysqldump.php
Created October 6, 2015 20:18
Magento dump without mysqdump
<?php
/**
* Mysqldump File Doc Comment
*
* PHP version 5
*
* @category Library
* @package Ifsnop\Mysqldump
* @author Michael J. Calkins <clouddueling@github.com>
* @author Diego Torres <ifsnop@github.com>
@m4s0
m4s0 / mageDbDump.php
Created October 6, 2015 15:54
Magento database dump
<?php
$xml = simplexml_load_file("app/etc/local.xml");
$db_host = (string)$xml->global->resources->default_setup->connection->host;
$db_name = (string)$xml->global->resources->default_setup->connection->dbname;
$db_username = (string)$xml->global->resources->default_setup->connection->username;
$db_password = (string)$xml->global->resources->default_setup->connection->password;
$mysqldump = trim(shell_exec("which mysqldump"));
#include <stdio.h>
#include <stdlib.h>
typedef struct {
int *array;
size_t used;
size_t size;
} Array;
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct {
char **data;
size_t used;
size_t size;
} Array;
@m4s0
m4s0 / init_permission.sh
Last active December 15, 2015 20:59
Symfony 2.* init permissions folders
#!/usr/bin/env bash
HTTPDUSER=`ps aux | grep -E '[a]pache|[h]ttpd|[_]www|[w]ww-data|[n]ginx' | grep -v root | head -1 | cut -d\ -f1`
FOLDERS="app/cache app/logs app/sessions"
sudo setfacl -R -m u:"$HTTPDUSER":rwX -m u:`whoami`:rwX $FOLDERS
sudo setfacl -dR -m u:"$HTTPDUSER":rwX -m u:`whoami`:rwX $FOLDERS
sudo chown -R `whoami`:`whoami` $FOLDERS