/ Gists

Gists

On gists

Date range - vygenerování datum. rozmezí

PHP

array of date range.php #

<?php 

function dateRange( $first, $last, $step = '+1 day', $format = 'Y/m/d' ) {

	$dates = array();
	$current = strtotime( $first );
	$last = strtotime( $last );

	while( $current <= $last ) {

		$dates[] = date( $format, $current );
		$current = strtotime( $step, $current );
	}

	return $dates;
}

?>

On gists

Jquery plugin - tiny - ukázkový

jQuery-plugins

gistfile1.js #

(function($)  {
   $.fn.extend({
      check : function()  {
         return this.filter(":radio, :checkbox").attr("checked", true);
      },
      uncheck : function()  {
         return this.filter(":radio, :checkbox").removeAttr("checked");
      }
   });
}(jQuery));

On gists

JavaScript: only num in input

JavaScript

gistfile1.js #

<input onkeypress="return !isNaN(String.fromCharCode(event.charCode || event.keyCode))">

On gists

Jquery - plugin, funkce, vl. selektor

jQuery jQuery-plugins

mike-youtube.js #

$.fn.showWhenScrolled=function(){
	var self = this;
	
	this.init = function(){
		self.each(function(){
			var self_top   = $(this).offset().top;
			var scroll_top = $(window).scrollTop();
			var win_height = $(window).height();
			var frame      = $(this).find('iframe');
			if(scroll_top > (self_top - win_height)){
				if(!frame.attr('src')){
					frame.attr({src:frame.attr('title')});
				}
			}
		});
	};
	
	$(window).scroll(function(){
		self.init();
	}).resize(function(){
		self.init();
	});
	
	self.init();
};

$('.youtube-container').showWhenScrolled();

On gists

PHP: CSV export from MySql to output

PHP

csv-export.php #

<?
    $out = '';
    $fields = dibi::fetchAll("SHOW COLUMNS FROM web_application");
    foreach ($fields as $field)
    {
    $out .= '"'.$field->Field.'";';
    }
    $out = rtrim($out, ';');
    $out .= PHP_EOL;
    foreach ($this->model->csvExport() as $index => $row)
    {
    foreach ($row as $r)
    {
    $out .='"'.$r.'";';
    }
    $out = rtrim($out, ';');
    $out .= PHP_EOL;
    }
    $out = iconv('utf-8', 'windows-1250', $out);
    $filename = 'application-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);
    $this->view->setTemplateFile('modules/application/csv.php');

On gists

PHP: Readable filesize

PHP Helpers-Filters-Plugins

readable-filesize.php #

<? 

function HumanReadableFilesize($size) {
// Adapted from: http://www.php.net/manual/en/function.filesize.php
$mod = 1024;
$units = explode(' ','B KB MB GB TB PB');
for ($i = 0; $size > $mod; $i++) {
$size /= $mod;
}
return round($size, 2) . ' ' . $units[$i];
}

function fsize($file) {
$a = array("B", "KB", "MB", "GB", "TB", "PB");
$pos = 0;
$size = filesize($file);
while ($size >= 1024) {$size /= 1024;$pos++;}
return round($size,2)." ".$a[$pos];
}

?>

On gists

PHP: Unzip folder

PHP

unzip-folder.php #

<?
    $extract_dir = "./sprites/";
    $extract_file = "sprites.zip";
    $zip = new ZipArchive;
    $res = $zip->open($extract_file);
    if ($res === TRUE) {
    $zip->extractTo($extract_dir);
    $zip->close();
    echo "OK";
    } else {
    echo "NOK";
    }

?>

On gists

PHP: Zip folder

PHP

zip-folder.php #

<?    
class zipuj_helper
    {
    protected $jmeno_zipu;
    protected $root;
    protected $zip;
    public function __construct($root = ".", $jmeno_zipu = "zip.zip")
    {
    $this->root = $root;
    $this->jmeno_zipu = $jmeno_zipu;
    $this->zip = new ZipArchive();
    $this->zip->open($this->jmeno_zipu, ZIPARCHIVE::CREATE);
    $this->nactiAdr();
    $this->uloz();
    }
    public function nactiAdr($cesta = "")
    {
    $hn = scandir($this->root.$cesta);
    foreach ($hn as $file)
    {
    if ($file == "." || $file == "..")
    {
    continue;
    }
    if (is_dir($this->root.$cesta."/".$file))
    {
    $this->zip->addEmptyDir($cesta."/".$file);
    $this->nactiAdr($cesta."/".$file);
    }
    else
    {
    $this->zip->addFile($this->root.$cesta."/".$file, $cesta."/".$file);
    }
    }
    }
    public function uloz()
    {
    $this->zip->close();
    }
    }

    // use
 $filename = 'prilohy__' . date('YmdHis') . '.zip';
 $zalohuj = new zipuj_helper('./storage/application/', './storage/application-zip/' . $filename);

On gists

JavaScript: string fns prototypes

JavaScript-OOP JavaScript Helpers-Filters-Plugins

js-fns-prototypes.js #

// stripslashes    
String.prototype.stripslashes = function(){
    return this.replace(/<.*?>/g, '');
    };
    String.prototype.htmlspecialchars = function(){
    var str = this.replace(/&/g, '&amp;');
    str = str.replace(/</g, '&lt;');
    str = str.replace(/>/g, '&gt;');
    str = str.replace(/"/g, '&quot;');
    return str;
    };

// htmlspecialchars
    var str = '<b>my personal website:</b> ';
    str += '<a href="http://www.jonasjohn.de/">jonasjohn.de</a>';
    document.write("Original string (html): '" + str + "'<br/><br/>");
    var str_no_html = str.stripslashes();
    document.write("- String without HTML tags: '" + str_no_html + "'<br/>");
    var str_hsc = str.htmlspecialchars();
    document.write("- String with converted HTML tags: '" + str_hsc + "'");

On gists

HTML: List of entities

Helpers-Filters-Plugins

HTML: List of entities #

znak    kl.zkratka	Alt+#		HTML kód	název

"	----------	Alt+34		&quot;		uvozovka/quote
#	Ctrl+Alt+X	Alt+35		  		mřížka/hash/sharp
$	Ctrl+Alt+ů	Alt+36		  		dollar
&	Ctrl+Alt+C	Alt+38		&amp;		ampersand
' 	----------	Alt+39		&#39;		apostrof
*	Ctrl+Alt+-	Alt+42		  		hvězdička/asterisk
/ 	----------	Alt+47		&#47;		lomítko/slash
:	----------	Alt+58				dvojtečka/colon
;	----------	Alt+59				středník/semicolon	
<	Ctrl+Alt+,	Alt+60		&lt;		menší než/ less than
>	Ctrl+Alt+.	Alt+62		&gt;		větší než/ greater then
@	Ctrl+Alt+V	Alt+64		  		zavináč/at
[	Ctrl+Alt+F	Alt+91		  		levá hranatá závorka/left square bracket
\	Ctrl+Alt+Q	Alt+92		  		obrácené/opačné lomítko/backslash/reverse solidus
]	Ctrl+Alt+G	Alt+93		  		pravá hranatá závorka/right square bracket
^	----------	Alt+94		&circ;	  	stříška/wedge
{	Ctrl+Alt+B	Alt+123		  		levá složená závorka/left curly bracket
|	Ctrl+Alt+W	Alt+124				svislítko
}	Ctrl+Alt+N	Alt+125		  		pravá složená závorka/right curly bracket
~	Ctrl+Alt++	Alt+126		&tilde;		vlnovka/tilda/tilde
€	Ctrl+Alt+E	Alt+0128	&euro; 		znak eura
¦	----------	Alt+0166	&brvbar;	přerušené svislítko/broken bar
§	----------	Alt+0167	&sect;		paragraf/section
¨	----------	Alt+0168	&uml;		přehláska/umlaut
©	----------	Alt+0169	&copy;		copyright
®	----------	Alt+0174	&reg;		registred
°	----------	Alt+0176	&deg;	  	stupeň/degre
±	----------	Alt+0177	&plusmn;	plus mínus
µ	----------	Alt+0181	&micro;	  	mikro,mí
ß	Ctrl+Alt+§	Alt+0223	&szlig;	  	ostré s
ä	----------	Alt+0228	&auml;	  	a s přehláskou
ë	----------	Alt+0235	&euml;	  	e s přehláskou
ö	----------	Alt+0246	&ouml;	  	o s přehláskou
÷	Ctrl+Alt+ú	Alt+0247	&divide;	děleno/divide
ü	----------	Alt+0252	&uuml;	  	u s přehláskou
Π	----------	Alt+0928	&Pi;	  	velké pí
Σ	----------	Alt+0931	&Sigma;	  	velké sigma
Φ	----------	Alt+0934	&Phi;	  	velké fí
Ω	----------	Alt+0937	&Omega;	  	velké omega
α	----------	Alt+0945	&alpha;	  	alfa
β	----------	Alt+0946	&beta;	  	beta
γ	----------	Alt+0947	&gamma;	  	gama
δ	----------	Alt+0948	&delta;	  	delta
λ	----------	Alt+0955	&lambda;	lambda
π	----------	Alt+0960	&pi;	  	malé pí
ρ	----------	Alt+0961	&rho;	  	malé ró
σ	----------	Alt+0963	&sigma;	  	malé sigma
τ	----------	Alt+0964	&tau;	  	malé tau
φ	----------	Alt+0966	&phi;	  	malé fí
χ	----------	Alt+0967	&chi;	  	malé chí
ψ	----------	Alt+0968	&psi;	  	malé psí
ω	----------	Alt+0969	&omega;	  	malé omega