Skip to content

Instantly share code, notes, and snippets.

@cereal-s
cereal-s / compare.php
Created Aug 8, 2019
Compare list of files
View compare.php
<?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 Jun 10, 2019
Find value into an array. Comparison between for loop + if/else, in_array(), and array_flip() + for loop + isset().
View run.php
<?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 Mar 18, 2019
Bitnami service not working
View README.md

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 Dec 12, 2018
Form to XML file.
View index.php
<?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
Import PNG to SVG with <image> tag
View png2svg.php
<?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 Jun 26, 2018 — forked from andytlr/_description.md
Convert SVG <polyline> to <path> so they can be animated with D3 etc.
View _description.md

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
+<path fill="#FFFFFF" stroke="#000000" stroke-miterlimit="10" d="M100.712,141.534 582.904,227.835 425.37,478.521
@cereal-s
cereal-s / VideoStream.php
Last active Feb 5, 2020 — forked from ranacseruet/VideoStream.php
PHP VideoStream class for HTML5 video streaming
View VideoStream.php
<?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 Jun 9, 2018
Split CSV columns
View split.php
<?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
View mb_str_pad.php
<?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 — forked from hraban/pre-commit
Git pre-commit hook (.git/hooks/pre-commit) to prevent accidentally committing debug code (add NOCOMMIT in source comment)
View pre-commit
#!/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: