Skip to content

Instantly share code, notes, and snippets.

@tacoberu
tacoberu / sample.java
Last active April 21, 2020 20:04
Zapouzdření objektu.
class Person
{
private String name;
private Address address;
private int age;
public Person(String name, Address address, int age)
{
this.assertName(name);
this.assertAddress(address, age);
this.assertAge(age);
@tacoberu
tacoberu / annonymous-instance.php
Last active October 19, 2019 20:49
First-class class in the PHP
<?php
$inst = new class("> ") {
private $prefix;
function __construct(string $prefix)
{
$this->prefix = $prefix;
}
function log($msg)
[user]
name = Martin Takáč
email = martin@takac.name
[push]
# default = matching
default = simple
[core]
autocrlf = input
@tacoberu
tacoberu / sample.php
Last active September 27, 2018 19:11
Najdi jednu užitečnou informaci.
/**
* Vrátí seznam článků.
* @param $flag
*/
function getArticleList($flag)
{
// ...
}
@tacoberu
tacoberu / sample.php
Created September 27, 2018 18:35
Nedůvěra k vlastnímj kódu
// Ověříme, zda má nějaké BCC adresy.
if (count($data['Message']['bcc'])) {
//...
}
<?php
class UserDatabaseTable
{
const
TABLE_NAME = 'users',
COLUMN_ID = 'id',
COLUMN_NAME = 'username',
COLUMN_EMAIL = 'email',
@tacoberu
tacoberu / .hgrc
Last active May 23, 2018 16:21
Shorthand for mercurial like in git.
[extensions]
strip =
shelve =
rebase =
[alias]
out-log = out -q --template '{rev}: {desc}\n'
out-files = !$HG out -q --template '{files}\n' | sort | uniq
push-this = !$HG push -b `hg branch`
push-this-force = !$HG push -b `hg branch` -f
using System;
namespace Une
{
class Person
{
private string last;
private string first;
public Person(string lastName, string firstName)
@tacoberu
tacoberu / download.php
Last active April 24, 2018 12:12
Firefox, Chrome, Safary ...
<?php
$file = __dir__ . '/file-1.jpg';
header('Content-Description: File Transfer');
header("Content-Length: ".filesize($file));
header("Content-Disposition: attachment; filename=\"" . basename($file) . "\";");
readfile($file);
@tacoberu
tacoberu / intf.java
Last active June 6, 2018 11:22
Příklad: Budu mět nějakou funkci/metodu, která bude validovat, zda dotyčný smí alkohol. Takže prohlásíme, že příchozí objekt musí být schopen se prokázat věkem.
class Age
{
private int val;
Age(int val)
{
assertInt(0, 150);
this.val;
}
int getVal()
{