Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / _description.md
Created June 26, 2018 17:14 — forked from andytlr/_description.md
Convert SVG <polyline> to <path> so they can be animated with D3 etc.

Convert SVG polyline to path

Replace all instances of <polyline with <path and points=" with d="M.

 <?xml version="1.0" encoding="utf-8"?>
 <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
 <svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="1000px" height="1000px" viewBox="0 0 1000 1000" enable-background="new 0 0 1000 1000" xml:space="preserve">
-<polyline fill="#FFFFFF" stroke="#000000" stroke-miterlimit="10" points="100.712,141.534 582.904,227.835 425.37,478.521
+
@cereal-s
cereal-s / VideoStream.php
Last active February 5, 2020 14:39 — forked from ranacseruet/VideoStream.php
PHP VideoStream class for HTML5 video streaming
<?php
/**
* Description of VideoStream
*
* @author Rana
* @link http://codesamplez.com/programming/php-html5-video-streaming-tutorial
*/
class VideoStream
{
private $path = "";
@cereal-s
cereal-s / split.php
Created June 9, 2018 20:15
Split CSV columns
<?php
// Usage:
// php split.php < input.csv > output.csv
// CSV format example:
// street,"city, state",zip
// "3526 HIGH ST","SACRAMENTO, CA",95838
// "51 OMAHA CT","SACRAMENTO, CA",95823
// "2796 BRANCH ST","SACRAMENTO, CA",95815
@cereal-s
cereal-s / mb_str_pad.php
Created May 17, 2018 21:53 — forked from nebiros/mb_str_pad.php
mb_str_pad
<?php
/**
* mb_str_pad
*
* @param string $input
* @param int $pad_length
* @param string $pad_string
* @param int $pad_type
* @return string
@cereal-s
cereal-s / pre-commit
Created May 1, 2018 15:31 — forked from hraban/pre-commit.md
Git pre-commit hook (.git/hooks/pre-commit) to prevent accidentally committing debug code (add NOCOMMIT in source comment)
#!/bin/sh
# This pre-commit hook will prevent you from committing any line (or filename) containing
# the string NOCOMMIT. Use that tag in comments around source code you want to avoid
# accidentally committing, like temporary IP addresses or debug printfs.
#
# To add it to an existing repository, save it to .git/hooks/pre-commit (or append, if
# that file already exists). Remember to make executable (chmod +x ...)
#
# To automatically add this pre-commit hook to every repository you create or clone: