Skip to content

Instantly share code, notes, and snippets.

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

Michal Haták Twista

😺
:q!
View GitHub Profile
public function processEditForm(\Nette\Application\UI\Form $form) {
$mealcat = new \MealCategory($form->getValues());
try {
$this->facade->saveCategory($mealcat);
} catch (\Exception $e) {
$this->flashMessage($e->getMessage(), 'alert-error');
$this->flashMessage('Bohužel, kategorii se nepodařilo uložit', 'alert-error');
$this->redirect('Mealcategory:overview');
}
$this->flashMessage('Kategorie uložena', 'alert-success');
@Twista
Twista / gist:4221532
Created December 6, 2012 03:10
javascript callback | solution A
// fce kterou volam
function doSomething(callback) {
// ...
// volani callbacku
callback('stuff', 'goes', 'here');
}
// pripraveny callback
function foo(a, b, c) {
@Twista
Twista / pr1.js
Created December 6, 2012 03:19
javascript callback | solution B
// nejjednodusi zpusob
function Thing(name) {
this.name = name;
}
Thing.prototype.doSomething = function(callback) {
// zavolani callbacku, this kuli kontextu
callback.call(this);
@Twista
Twista / gist:4478416
Last active December 10, 2015 18:58
chrome extension - manifest access
chrome.manifest = function() {
var manifestObject = false;
var request = new XMLHttpRequest();
request.onreadystatechange = function() {
if (request.readyState == 4) {
manifestObject = JSON.parse(request.responseText);
}
};
@Twista
Twista / gist:4559273
Last active December 11, 2015 06:28
DS1 - Zídy
# Netrivialni dotazy
###########################x
# 1) vypiste jmena odberatelu a pocet objednanych polozek (nerozlisujte zda jsou zaplaceny ci nikoliv)
SELECT odberatel.jmeno, odberatel.prijmeni, COUNT( fakturapolozka.polozka_id ) AS pocet_polozek
FROM odberatel
LEFT JOIN faktura ON ( odberatel.odberatel_id = faktura.odberatel_id )
LEFT JOIN fakturapolozka ON ( faktura.cislo_faktury = fakturapolozka.cislo_faktury )
GROUP BY odberatel.odberatel_id
@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;
}
<?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: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 __autoload($class_name) {
$filename = __DIR__.DIRECTORY_SEPARATOR.strtolower($class_name).'.php';
if(is_readable($filename))
require ($filename);
}
<?php
$file1 = 'soubor1.txt';
$file2 = 'soubor2.txt';
// porovnani veliksoti souboru
if(filesize($file1) == filesize($file2)){
echo 'jsou stejne';
} else {
echo 'nejsou stejne';