Skip to content

Instantly share code, notes, and snippets.

View xZero707's full-sized avatar
🦆
Absent-Minded professor

Aleksandar Puharic xZero707

🦆
Absent-Minded professor
View GitHub Profile
@xZero707
xZero707 / foldersize.php
Created August 7, 2019 10:29 — forked from eusonlito/foldersize.php
PHP function to get the folder size including subfolders
<?php
function folderSize ($dir)
{
$size = 0;
foreach (glob(rtrim($dir, '/').'/*', GLOB_NOSORT) as $each) {
$size += is_file($each) ? filesize($each) : folderSize($each);
}
@xZero707
xZero707 / ArrayDiffAssoc.php
Created July 12, 2019 12:27
Compares two arrays and shows exact difference between them. The ultimate function
<?php
/**
* Compares two arrays and shows exact difference between them.
*
* !!! IMPORTANT !!
* Order of two supplied arrays matters!
*
* @fix xZero707 <[email protected]>: Pay attention to types as well
*
@xZero707
xZero707 / git-mv-with-history
Created March 5, 2019 12:18 — forked from emiller/git-mv-with-history
git utility to move/rename file or folder and retain history with it.
#!/bin/bash
#
# git-mv-with-history -- move/rename file or folder, with history.
#
# Moving a file in git doesn't track history, so the purpose of this
# utility is best explained from the kernel wiki:
#
# Git has a rename command git mv, but that is just for convenience.
# The effect is indistinguishable from removing the file and adding another
# with different name and the same content.
@xZero707
xZero707 / str_map.php
Last active February 11, 2019 11:02
str_replace on steroids
<?php
namespace NorthernLights\Util;
/**
* Map/replace string accordingly to supplied character map
* Note:
* There is certain overhead because we use 4 function calls main -> mapper -> array_keys -> array_values
* versus that it can be done with just single str_replace()
* However, accordingly to benchmarks, difference becomes noticeable only after 1 000 000 iterations (~300ms slower)
@xZero707
xZero707 / debian-install-zram.sh
Last active October 21, 2018 20:16
Install zRAM on Debian(8)
#!/bin/bash
#
not_root() {
echo "ERROR: You have to be root to execute this script"
exit 1
}
zram_exists() {
echo "ERROR: /etc/init.d/zram already exists"
<?php
/**
* We declare $x as init of anonymous class, which implements magic __toString() method
* @author Alexander Puharic <[email protected]>
*/
$x = new class
{
/** @var array */
private $feed;
<?php
var_dump(
(empty('' . $x) && ($x == 'FA' && $x == 'LO' && $x == '103' && $x == '208'))
);
@xZero707
xZero707 / exceptions-tree.php
Created July 12, 2018 13:43 — forked from mlocati/exceptions-tree.php
Throwable and Exceptions tree
<?php
if (!function_exists('interface_exists')) {
die('PHP version too old');
}
$throwables = listThrowableClasses();
$throwablesPerParent = splitInParents($throwables);
printTree($throwablesPerParent);
if (count($throwablesPerParent) !== 0) {
die('ERROR!!!');
@xZero707
xZero707 / BinarySearchTreeArray.php
Last active March 26, 2018 09:59
Uses a binary search tree algorithm to locate a value in the specified array.
<?php
/**
* Uses a binary search algorithm to locate a value in the specified array
* Due to internal function call overhead (count, floor), it might be inefficient to use on small arrays
*
* Original:
* @author Nicholas C. Zakas
* @see https://www.htmlgoodies.com/beyond/javascript/how-to-search-a-javascript-string-array-using-a-binary-search.html
*
@xZero707
xZero707 / keybase.md
Created March 7, 2018 08:38
Keybase Identity Verification

Keybase proof

I hereby claim:

  • I am xzero707 on github.
  • I am xzero707 (https://keybase.io/xzero707) on keybase.
  • I have a public key ASAA5Sg7IqA1pGLf3Utp582WPy4O5T-4tXdm5XZ-0QKd3go

To claim this, I am signing this object: