/ Gists

Gists

On gists

Sticky navigation using jquery (sticky after viewport is overhead...)

jQuery

Sticky navigation #

$(document).ready(function () {
                var aboveHeight = $('#topContainer').outerHeight();
                $(window).scroll(function () {
                    if ($(window).scrollTop() > aboveHeight) {
                        $('#menu').addClass('fixed').css('top', '0').next()
                            .css('padding-top', '50px');
                    } else {
                        $('#menu').removeClass('fixed').next()
                            .css('padding-top', '0');
                    }
                });
            });

On gists

Convert tables to InnoDB

MySql

convert-to-innodb #

SET @DATABASE_NAME = 'test';

SELECT  CONCAT('ALTER TABLE ', table_name, ' ENGINE=InnoDB;') AS sql_statements
FROM    information_schema.tables AS tb
WHERE   table_schema = @DATABASE_NAME
AND     `ENGINE` = 'MyISAM'
AND     `TABLE_TYPE` = 'BASE TABLE'
ORDER BY table_name DESC;

On gists

Komplení regexp na username

PHP

User RegExp #

$userRegExp = "#^[_A-Za-z0-9áäéëěíóöôúůüýčďňŕřšťžĺľÁÄÉËĚÍÓÖÔÚŮÜÝČĎŇŔŘŠŤŽĹĽ ]{3,40}\$#";

On gists

jquery - multiple on

jQuery

jquery multiple on #

$("#myLink")
    .addClass("bold")
    .on("click", myClickHandler)
    .on("mouseover", myMouseOverHandler)
    .show();

On gists

Complete ajax

jQuery

Complete ajax #

var jqxhr = $.ajax({
    url: url,
    type: "GET", // default is GET but you can use other verbs based on your needs.
    cache: true, // default is true, but false for dataType 'script' and 'jsonp', so set it on need basis.
    data: {}, // add your request parameters in the data object.
    dataType: "json", // specify the dataType for future reference
    jsonp: "callback", // only specify this to match the name of callback parameter your API is expecting for JSONP requests.
    statusCode: { // if you want to handle specific error codes, use the status code mapping settings.
        404: handler404,
        500: handler500
    }
});
jqxhr.done(successHandler);
jqxhr.fail(failureHandler);

On gists

Ajax - with done || fail

jQuery

ajax-done-fail #

$.ajax({ ... }).then(successHandler, failureHandler);
 
// OR
var jqxhr = $.ajax({ ... });
jqxhr.done(successHandler);
jqxhr.fail(failureHandler);

On gists

Jquery - conditional load

jQuery

jquery-conditional-load #

<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="js/jquery-1.11.0.min.js" type="text/javascript"><\/script>')</script>

On gists

PHP Curl to check if url is alive

PHP

curl_example.php #

<?php

function check_alive($url, $timeout = 10, $successOn = array(200, 301)) {
  $ch = curl_init($url);

  // Set request options
  curl_setopt_array($ch, array(
    CURLOPT_FOLLOWLOCATION => false,
    CURLOPT_NOBODY => true,
    CURLOPT_TIMEOUT => $timeout,
    CURLOPT_USERAGENT => "page-check/1.0"
  ));

  // Execute request
  curl_exec($ch);

  // Check if an error occurred
  if(curl_errno($ch)) {
    curl_close($ch);
    return false;
  }

  // Get HTTP response code
  $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  curl_close($ch);

  // Page is alive if 200 OK is received
  //return $code;
  return in_array( $code, $successOn );
}

$checks = array(
	'http://www.google.co.uk',
	'http://www.facebook.com',
	'http://www.bbc.co.uk',
	'http://photogabble.co.uk',
	'http://youtube.com'
	);

foreach($checks as $check)
{
	echo $check . ' is ' . ( (check_alive($check) ) ? 'Alive' : 'Dead' ) . "\n";
}

On gists

Download via Iframe // wo refresh

PHP

Downlad file via iframe (no refr #

<a href="" id="csv-export">export</a>
<iframe id="downloadIframe" src="" style="height: 0px; width: 0px; display: none;"></iframe>
<script>
    $("#csv-export").click(function(e){
        e.preventDefault();
        oIFrm = document.getElementById('downloadIframe');
        oIFrm.src = '' // URL to download file -- via php download headers;
    });
</script>

On gists

Convert UTF - win1250 - CSV

PHP

Convert utf-8 to win1250 - csv e #

 <?php
 
 $out = iconv('utf-8', 'windows-1250//TRANSLIT', $out);
 
         
 $filename = 'katalog-export___' . date('YmdHis') . '.csv';
 header('Content-Encoding: windows-1250');
 header('Content-type: text/csv; charset=windows-1250');
 header('Content-Disposition: attachment; filename=' . $filename);
 //echo "\xEF\xBB\xBF"; // UTF-8 BOM
 echo $out;
 exit(0);
 
 ?>