Skip to content

Instantly share code, notes, and snippets.

View zoxon's full-sized avatar

Zoxon zoxon

View GitHub Profile
@zoxon
zoxon / getIEVer.js
Last active August 29, 2015 13:58
JavaScript: Get IE version
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
function getIEVer() {
var rv = -1; // Return value assumes failure.
if (navigator.appName == 'Microsoft Internet Explorer') {
var ua = navigator.userAgent;
var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
if (re.exec(ua) !== null) {
rv = parseFloat(RegExp.$1);
}
@zoxon
zoxon / UpdateQueryString.js
Last active August 29, 2015 13:58
JavaScript: Change the URL in the format of key/value
// Change the URL in the format of key/value
function UpdateQueryString(key, value, url) {
if (!url) url = window.location.href;
var re = new RegExp("([/])" + key + "/.*?(/|$)", "gi");
var separator = '/';
if (url.match(re)) {
return url.replace(re, '$1' + key + "/" + value + '$2');
}
else {
return url + separator + key + "/" + value;
@zoxon
zoxon / formatFileSize.php
Last active August 29, 2015 13:58
PHP: Format file size units
public static function formatFileSize($fileSize) {
if ($fileSize >= 1073741824) {
$fileSize = round($fileSize / 1073741824 * 100) / 100 . " " . self::_translate()->_('ГБ');
} elseif ($fileSize >= 1048576) {
$fileSize = round($fileSize / 1048576 * 100) / 100 . " " . self::_translate()->_('МБ');
} elseif ($fileSize >= 1024) {
$fileSize = round($fileSize / 1024 * 100) / 100 . " " . self::_translate()->_('КБ');
} else {
$fileSize = $fileSize . " " . self::_translate()->_('Б');
}
@zoxon
zoxon / filesizeUrl.php
Last active August 29, 2015 13:58
PHP: Get file size by URL
function filesizeUrl($url) {
return ($data = @file_get_contents( $url )) ? strlen( $data ) : false;
}
@zoxon
zoxon / listdir.php
Last active August 29, 2015 13:58
PHP: List recursive all folders
function listdir($dir) {
$current_dir = opendir( $dir );
while ( $entryname = readdir( $current_dir ) ) {
if( is_dir( "$dir/$entryname" ) and ($entryname != "." and $entryname != "..") ) {
listdir( "${dir}/${entryname}" );
} elseif( $entryname != "." and $entryname != ".." ) {
unlink( "${dir}/${entryname}" );
}
}
@zoxon
zoxon / totranslit.php
Last active August 29, 2015 13:58
PHP: Russian to Translit
function totranslit($var, $lower = true, $punkt = true) {
$NpjLettersFrom = "абвгдезиклмнопрстуфцыі";
$NpjLettersTo = "abvgdeziklmnoprstufcyi";
$NpjBiLetters = array ("й" => "j", "ё" => "yo", "ж" => "zh", "х" => "x", "ч" => "ch", "ш" => "sh", "щ" => "shh", "э" => "ye", "ю" => "yu", "я" => "ya", "ъ" => "", "ь" => "", "ї" => "yi", "є" => "ye" );
$NpjCaps = "АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЬЪЫЭЮЯЇЄІ";
$NpjSmall = "абвгдеёжзийклмнопрстуфхцчшщьъыэюяїєі";
$var = str_replace( ".php", "", $var );
$var = trim( strip_tags( $var ) );
@zoxon
zoxon / checkHTTPS.php
Last active August 29, 2015 14:00
PHP: Get current URL
function checkHTTPS() {
if(!empty($_SERVER['HTTPS'])) {
return ($_SERVER['HTTPS'] !== 'off') ? true : false;
}
else {
return ($_SERVER['SERVER_PORT'] == 443) ? true : false;
}
}
function getCurURI(){
@zoxon
zoxon / documentReady.js
Last active August 29, 2015 14:02
JavaScript: Document Ready
document.addEventListener('DOMContentLoaded', function () {
});
@zoxon
zoxon / gist:034aea68e0098e94cf6f
Last active August 29, 2015 14:03
Stylus: text-overflow ellipsis
white-space nowrap
overflow hidden
text-overflow ellipsis
display block
@zoxon
zoxon / gist:c167ad2ca788efd89fc2
Last active August 29, 2015 14:04
HTML: Sample html5 support for IE < 9
<!--[if lt IE 9]>
<script>
var e = ("article,aside,figcaption,figure,footer,header,hgroup,nav,section,time").split(',');
for (var i = 0; i < e.length; i++) {
document.createElement(e[i]);
}
</script>
<![endif]-->