Skip to content

Instantly share code, notes, and snippets.

View hrach's full-sized avatar

Jan Škrášek hrach

View GitHub Profile
@hrach
hrach / benchmark.php
Created August 23, 2013 18:22
Objekty s preddefinovanymi property jsou pro Entity o polovinu datove narocne nez jedno pole + __get & __set. Objekt si totiz nemusi drzet klic.
<link href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet">
<?php
function calculate_median($arr) {
sort($arr);
$count = count($arr); //total numbers in array
$middleval = floor(($count-1)/2); // find the middle value, or the lowest middle value
if($count % 2) { // odd number, middle is the median
$median = $arr[$middleval];
} else { // even number, calculate avg of 2 medians
@hrach
hrach / FormMacros.php
Created July 29, 2013 13:44
FormMacros customization of Bootstrap3 macro (for Nette framework). See https://github.com/nextras/forms
<?php
/**
* signaly.cz - christian community platform
* MIT license
*
* @link https://www.signaly.cz
*/
namespace Signaly;
<?php
class TestIterator implements \IteratorAggregate
{
public function getIterator()
{
return new ArrayIterator(array(1, 2, 3));
}
}
@hrach
hrach / api.php
Created March 21, 2013 22:09
Premyslim nad novym api pro Nette\Database. - je treba osekat aktualni selection, ktera ma metody delete, insert, atp. - je treba osekat metody save, update, delete na active row V nize draft api je toto odstraneno. Je zavedena repository. Programator by samozrejme mohl definovat vlastni repository. Co rikate na navrhovany smer? Jinak, aby bylo …
<?php
$user = $connection->repository('user')->get(1);
// $user instanceof Row
$users = $connection->repository('user')->query()->where('id in ?', [1, 2, 3]);
// $users instanceof SqlBuilder
$users = $connection->repository('user')->query()->where('id in ?', [1, 2, 3])->getSelection();
// $users instanceof Selection
@hrach
hrach / query.sql
Last active December 13, 2015 23:19
PostgreSQL subselect
CREATE TABLE book (
id serial NOT NULL,
author_id int NOT NULL,
translator_id int,
title varchar(50) NOT NULL,
PRIMARY KEY (id)
);
CREATE TABLE book_tag (
book_id int NOT NULL,
$('.ameta').each(function() {
var i = $(this).find('.a').text();
i = i.substring(0, i.length - 3).replace(',','');
var d = $(this).find('.d').text();
d = d.substring(0, d.length - 3).replace(',','');
$(this).parents('li').data('rank', i - d);
});
var l = $('.contrib-data');
var list = l.find('li').sort(function(a,b){ return $(b).data('rank') - $(a).data('rank'); });
l.find('li').remove();
@hrach
hrach / gist:3947722
Created October 24, 2012 18:00
markdown code source
```
```abc
```
@hrach
hrach / composer.bat
Created September 24, 2012 20:52
Composer runnery na windows (SH verze pro Git bash)
@echo off
if "%PHPBIN%" == "" set PHPBIN=php.exe
"%PHPBIN%" "C:/Program Files (x86)/wamp/bin/php/php5.4.6/composer.phar" %*
@hrach
hrach / .bashrc
Last active October 12, 2016 12:07
Git config
alias gui='git gui&'
alias gitk='gitk --all &'
source /c/dev/git-bash-tools/completion.bash # find it in your git installation path
hg_ps1() {
hg prompt "{ {branch}}{ at {bookmark}}{{status}}" 2> /dev/null
}
function color_my_prompt {
@hrach
hrach / macros.php
Created March 10, 2012 00:20
Signaly Form macros
<?php
/**
* @license MIT license
*/
namespace Nextras;
use Nette,
Nette\Latte,
Nette\Latte\MacroNode,