Skip to content

Instantly share code, notes, and snippets.

@cereal-s
cereal-s / get_combinations.php
Last active August 26, 2019 08:47 — forked from cecilemuller/get_combinations.php
PHP: Get all combinations of multiple arrays (preserves keys)
<?php
function get_combinations($arrays) {
$result = [[]];
foreach ($arrays as $property => $property_values) {
$tmp = [];
foreach ($result as $result_item) {
foreach ($property_values as $property_value) {
$tmp[] = array_merge($result_item, array($property => $property_value));
}
@cereal-s
cereal-s / tokenize_string.php
Created August 24, 2019 20:02
Tokenize string - strtok()
<?php
/**
* Break lines for each group of values
* in the SQL insert statements.
*
* It can be used also for simple strings.
*
* Usage script.php < IN > OUT
*
@cereal-s
cereal-s / mysql_dump_backup.php
Last active August 24, 2019 14:26
Dump of MySQL server
<?php
/**
* This script does a full backup of a MySQL server
* it uses `mysqldump` to save:
*
* - full database: create & inserts
* - tables create statements
* - table inserts
* - database routines: functions & stored procedures
@cereal-s
cereal-s / gist:3ec7c45353e8e259ec16cf10ea2ad1a7
Last active August 24, 2019 14:09 — forked from codler/gist:3906826
Support HTTP Header Range, mp4, php.php/mp4.mp4
<?php
# Nginx doesn't have PATH_INFO
if (!isset($_SERVER['PATH_INFO'])) {
$_SERVER['PATH_INFO'] = substr($_SERVER["ORIG_SCRIPT_FILENAME"], strlen($_SERVER["SCRIPT_FILENAME"]));
}
$request = substr($_SERVER['PATH_INFO'], 1);
$file = $request;
$fp = @fopen($file, 'rb');
@cereal-s
cereal-s / compare.php
Created August 8, 2019 20:34
Compare list of files
<?php
try {
function _trim($str) {
return rtrim(trim($str, ' \r\t\n\0\x0B'), ' /');
}
# paths to compare
$dir1 = isset($argv[1]) ? _trim($argv[1]) : null;
@cereal-s
cereal-s / run.php
Created June 10, 2019 20:03
Find value into an array. Comparison between for loop + if/else, in_array(), and array_flip() + for loop + isset().
<?php
function _report($start) {
$total_time = microtime( true ) - $start;
echo PHP_EOL;
echo 'Total time: ' . number_format($total_time, 6);
echo PHP_EOL;
echo PHP_EOL;
}
@cereal-s
cereal-s / png2svg.php
Last active May 23, 2019 09:06
Import PNG to SVG with <image> tag
<?php
/**
* Import PNG to SVG with <image> tag
* @see https://developer.mozilla.org/en-US/docs/Web/SVG/Tutorial/SVG_Image_Tag
*/
$ext = 'png';
$mime = 'image/png';
$files = glob('*.' . $ext);
@cereal-s
cereal-s / README.md
Last active March 18, 2019 11:33
Bitnami service not working

If an instance of Bitnami (Wordpress, Prestashop) is timing out, verify if the services are running:

sudo service --status-all

You should see the bitnami service on:

[+] bitnami
@cereal-s
cereal-s / index.php
Last active December 12, 2018 01:35
Form to XML file.
<?php
$file = 'file.xml';
if(isset($_POST))
{
$url = filter_input(INPUT_POST, 'url', FILTER_VALIDATE_URL);
$template = <<<XML
<Response>
@cereal-s
cereal-s / workspaces.sh
Created December 24, 2016 12:28
Change the number of workspaces in Ubuntu 16.04: usage `./workspaces.sh 3 3` to get 9 workspaces
#!/usr/bin/env sh
gsettings set org.compiz.core:/org/compiz/profiles/unity/plugins/core/ vsize $1
gsettings set org.compiz.core:/org/compiz/profiles/unity/plugins/core/ hsize $2