Skip to content

Instantly share code, notes, and snippets.

View enix-app's full-sized avatar
🎯
Focusing

E enix-app

🎯
Focusing
  • EnixApp
View GitHub Profile
@enix-app
enix-app / gist:7fd8ea281d361eaab13531b0edc48b46
Created August 28, 2019 20:13 — forked from liunian/gist:9338301
Human Readable File Size with PHP
<?php
# http://jeffreysambells.com/2012/10/25/human-readable-filesize-php
function human_filesize($bytes, $decimals = 2) {
$size = array('B','kB','MB','GB','TB','PB','EB','ZB','YB');
$factor = floor((strlen($bytes) - 1) / 3);
return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . @$size[$factor];
}
echo human_filesize(filesize('example.zip'));
@enix-app
enix-app / gist:10d91492c5e93358b0302ac6314b168f
Created August 25, 2019 17:58 — forked from dalethedeveloper/gist:966848
Reorder a PHP array, moving items up or down
<?php
/*
A quick set of functions to move items in a non-associative array
up or down by one, shifting the items around it appropriately.
Original usage was to for a set of UP and DOWN buttons to
manipulate the order of an array of items stored in Wordpress option.
*/
$a = array('a','b','c','d','e');
@enix-app
enix-app / str_start_case.php
Last active March 7, 2019 08:10
PHP - Start Case Function
<?php
if(!function_exists('str_start_case'))
{
/**
* @param $str string Required.
* @param $replace array Optional. Default an empty array.
* @param $separator string Optional. Default space.
*/
function str_start_case(string $str, array $replace=[], string $separator=" ")
@enix-app
enix-app / minify.php
Created December 28, 2018 06:22
A small PHP-Script for minifying CSS
<?php
// specify your css-files and their order here
$cssFiles = array(
'normalize.css', 'style.css', 'print.css', 'colorbox.css'
);
// the file to write the compressed css to
$minFileName = 'minified.css';
// thats all, just call this file in your browser and it will
// build you a minimized css-file. then just link to this single
@enix-app
enix-app / jquery.getStylesheet.js
Created August 20, 2018 15:52 — forked from james2doyle/jquery.getStylesheet.js
An implementation of $.getScript but for stylesheets. Call it $.getStylesheet
(function($) {
$.getStylesheet = function (href) {
var $d = $.Deferred();
var $link = $('<link/>', {
rel: 'stylesheet',
type: 'text/css',
href: href
}).appendTo('head');
$d.resolve($link);
return $d.promise();