Skip to content

Instantly share code, notes, and snippets.

View umidjons's full-sized avatar
🏠
Working from home

Umid umidjons

🏠
Working from home
View GitHub Profile
@umidjons
umidjons / compress-jsmin.php
Created August 2, 2013 05:07
Compress JavaScript file with JSMin
<?php
// -- Test JSMin
require( 'min/lib/JSMin.php' );
$file = 'jquery-1.10.2.js';
$pi = pathinfo( $file );
$filemin = $pi[ 'filename' ] . '-jsmin.' . $pi[ 'extension' ];
if ( file_exists( $file ) ) {
$source = file_get_contents( $file );
$res = JSMin::minify( $source );
file_put_contents( $filemin, $res );
@umidjons
umidjons / js-compressor.php
Created August 2, 2013 05:42
JSCompressor class to minify JS files (uses JSMin and JSMinPlus libraries)
<?php
class JSCompressor {
const COMPRESS_METHOD_JSMIN = 1;
const COMPRESS_METHOD_JSMIN_PLUS = 2;
public static function minify( $file, $newfile = null, $compress_method = self::COMPRESS_METHOD_JSMIN, $debug = false ) {
if ( $debug )
$time_start = microtime( true );
@umidjons
umidjons / dyn_create_select.html
Last active December 20, 2015 13:29
Dynamically create <select> and populate <option>s with jQuery.
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Select tag</title>
</head>
<body>
<script src="jquery-1.10.2.js"></script>
<script>
jQuery(document).ready(function($){
@umidjons
umidjons / truepath_realpath_alternative.php
Created August 5, 2013 09:17
realpath() alternative to detect absolute path (URN and URL is not supported, only local paths on the server)
<?php
/**
* This function is to replace PHP's extremely buggy realpath().
* @param string The original path, can be relative etc.
* @return string The resolved path, it might not exist.
*/
public static function truepath( $path )
{
// whether $path is unix or not
$unipath = strlen( $path ) == 0 || $path{0} != '/';
@umidjons
umidjons / sort_li_by_child_input_value.html
Created August 6, 2013 11:33
Sort <li> items by child element value
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Select tag</title>
</head>
<body>
<ul id="file-system">
<li>
<img src="images/folder.png" alt="">
@umidjons
umidjons / dirname_basename.js
Last active August 26, 2018 17:28
PHP dirname() and basename() alternatives for JavaScript
function basename( path )
{
return path.replace( /\\/g, '/' ).replace( /.*\//, '' );
}
function dirname( path )
{
return path.replace( /\\/g, '/' ).replace( /\/[^\/]*$/, '' );
}
console.log( dirname( '/srv/www/dev/umid/admin/cfg.admin.php' ) );
@umidjons
umidjons / jquery-plugin-example.html
Last active December 20, 2015 17:49
jQuery plugin example
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>jQuery Simple Plugin Example</title>
</head>
<body>
<p class="wow">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Autem deleniti dolorem fugit maiores, nulla
quam quos.
@umidjons
umidjons / vh_htaccess_error_log.htaccess
Created August 7, 2013 06:35
Set error log location with .htaccess for virtual host
php_flag log_errors on
php_flag display_errors on
# E_ALL = 30719
php_value error_reporting 30719
php_value error_log /var/www/domains/example.com/php.error.log
@umidjons
umidjons / file_extension.js
Last active December 20, 2015 17:58
Get file extension in JavaScript
var file = "some-file.pdf";
var ext = file.split( '.' ).pop();
console.log('File extension is', ext);
@umidjons
umidjons / index.html
Last active January 6, 2024 18:46
Upload File using jQuery.ajax() with progress support
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Upload File using jQuery.ajax() with progress support</title>
</head>
<body>
<input type="file" name="file" id="sel-file"/>