Skip to content

Instantly share code, notes, and snippets.

View akondas's full-sized avatar

Arkadiusz Kondas akondas

View GitHub Profile
@akondas
akondas / slugify.js
Last active August 29, 2015 14:10 — forked from mathewbyrne/slugify.js
Make friendly url and remove Polish national characters
function slugify(text)
{
var fromChar = [/ą/ig, /ę/ig, /ó/ig, /ś/ig, /ł/ig, /ż/ig, /ź/ig, /ć/ig, /ń/ig];
var toChar = ['a', 'e', 'o', 's', 'l', 'z', 'z', 'c', 'n'];
for ( var i in fromChar )
text = text.replace(fromChar[i], toChar[i]);
return text.toString().toLowerCase()
.replace(/\s+/g, '-') // Replace spaces with -
.replace(/[^\w\-]+/g, '') // Remove all non-word chars
.replace(/\-\-+/g, '-') // Replace multiple - with single -
@akondas
akondas / Zamiec - runTime
Last active August 29, 2015 14:14
Zamieć - czasy zawodników na trasie (bez przerw)
SZYMON NIKIEL 20:07:15
JAROSŁAW KOCUR 20:39:32
TOMASZ BARSZCZ 19:10:39
KAMIL KLICH 20:39:01
JAREK GONCZARENKO 17:32:25
AGATA MATEJCZUK 18:52:36
GRZEGORZ MENET 19:23:15
KRYSTIAN KORZAŃSKI 19:17:57
MARCIN MIKOŚ 18:14:11
BARTOSZ MALAWSKI 18:12:31
<?php
function add(int $a, int $b): int {
return $a + $b;
}
add(1, '2');
<?php
declare(strict_types=1); // musi być w 1 linii
function add(int $a, int $b): int {
return $a + $b;
}
add(1, '2');
// Catchable fatal error: Argument 2 passed to add() must be of the type integer, string given
<?php
// przed php 7
uasort($array, function($a, $b){
return ($a < $b) ? -1 : (($a > $b) ? 1 : 0);
});
// po php 7
uasort($array, function($a, $b){
return $a <=> $b;
});
<?php
try {
nonExistentFunction();
} catch (\EngineException $e) {
var_dump($e);
}
object(EngineException)#1 (7) {
["message":protected]=>
string(32) "Call to undefined function nonExistantFunction()"
<?php
// call closures assigned to properties
($object->closureProperty)()
// chain static calls
class foo { static $bar = 'baz'; }
class baz { static $bat = 'Hello World'; }
baz::$bat = function () { echo "Hello World"; };
<?php
// co zwróci podane wyrażenie ?
$obj->$properties['name'];
// w PHP 5.6
$obj->{$properties['name']}
// w PHP 7
{$obj->$properties}['name']
<?php
// proste zastosowanie
$username = $user->getName() ?? 'nobody';
// dobre do tablic bo nie trzeba sprawdzać isset
$width = $imageData['width'] ?? 100;
// bardziej złożony przykład
$config = $config ?? $this->config ?? static::$defaultConfig;
<?php
// do PHP 5.6
use Framework\Component\ClassA;
use Framework\Component\ClassB as ClassC;
use Framework\Component\OtherComponent\ClassD;
// od PHP 7
use Framework\Component\{
ClassA,
ClassB as ClassC,