Skip to content

Instantly share code, notes, and snippets.

View Twista's full-sized avatar
😺
:q!

Michal Haták Twista

😺
:q!
View GitHub Profile
@Twista
Twista / add.latte
Created June 28, 2015 00:29
@layout.latte
{block detail}
spolecny form
{/block}
{block content}
{include detail}
{/block}
@Twista
Twista / gist:1fbd2ffcf9707a4d67a4
Last active August 29, 2015 14:05
text truncating in php
<?php
/**
* truncate text
* @param string $text source
* @param int $length length
* @param string $suffix append
* @param bool $force exactly
* @return string
*/
function truncate($text, $length, $suffix = '', $force = false) {
request = new XMLHttpRequest()
request.onreadystatechange = ()->
if request.readyState == 4 && request.status == 200
console.log request.responseText
return
request.open "GET", url , true
request.send()
<?php
use Nette\Application\UI\Control;
class ArticleControl extends Control{
protected $model;
public function __construct(MyModel $model){
@Twista
Twista / gist:6382940
Last active December 21, 2015 23:29
simple element builder
###*
* dynamic element builder
* @param {string} name element name, e.g "a"
* @param {Object} params attributes
* @return {Object} element
###
buildElement: (name, params = {}) ->
elem = document.createElement(name)
for key, value of params
elem.setAttribute key, value
<?php
$file1 = 'soubor1.txt';
$file2 = 'soubor2.txt';
// porovnani veliksoti souboru
if(filesize($file1) == filesize($file2)){
echo 'jsou stejne';
} else {
echo 'nejsou stejne';
<?php
function __autoload($class_name) {
$filename = __DIR__.DIRECTORY_SEPARATOR.strtolower($class_name).'.php';
if(is_readable($filename))
require ($filename);
}
@Twista
Twista / gist:5322609
Created April 5, 2013 21:03
dev my.ini
# MySQL Server Instance Configuration File
# ----------------------------------------------------------------------
# Generated by the MySQL Server Instance Configuration Wizard
#
#
# Installation Instructions
# ----------------------------------------------------------------------
#
# On Linux you can copy this file to /etc/my.cnf to set global options,
# mysql-data-dir/my.cnf to set server-specific options
<?php
function trojuhelnik($a, $b, $c){
$arr = func_get_args(); // array($a, $b, $c);
sort($arr);
if(($arr[0] <= 0) || ($arr[0] + $arr[1] <= $arr[2]))
throw new Exception("Trojuhelnik neni mozne sestrojit");
$arr = array_unique($arr);
$result = array("rovnostranny","rovnoramenny","obecny");
return $result[count($arr)-1];
@Twista
Twista / gist:4626002
Created January 24, 2013 18:19
simple make link
function makeLink($text){
$reg_exUrl = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/";
preg_match_all($reg_exUrl, $text, $url);
foreach ($url[0] as $key => $value) {
$text = strtr($text, array($value => '<a href="'.$value.'" target="_blank">'.$value.'</a>'));
}
return $text;
}