Skip to content

Instantly share code, notes, and snippets.

void setupRouting() {
registerRoute("/api/furnace", HTTP_GET, [&] (Request& request) {
furnaceController.apiGetAction(request);
});
/* and many more like this one */
}
// OPTION A: copy callback to function + move to lambda
void registerRoute(
const char* const uri,
#include <iostream>
using namespace std;
class Bar {
public:
Bar(int a, int b): a(a), b(b) {};
// a is mutable property, b isn't – by the contract of object's public interface
void setA(int _a) { a = _a; }
<?php
// https://www.wykop.pl/wpis/39614135/mirki-chce-przekierowanie-na-wp-jesli-httpacceptla/
// 1. Zawsze porównuj z `===` - w bardzo wyjątkowych przypadkach `==` jest słuszne. Doczytaj sobie w dokumentacji dlaczego.
// 2. Spójność napisów - masz raz tak, raz inaczej, bez reguły. Najlepiej zawsze używaj apostrofów do napisów (`'`), chyba że faktycznie chcesz interpolować zmienne lub mieć znaki nowej linii, itp. (wtedy cudzysłowy `"`).
// 3. Jak kolega wyżej słusznie zauważył, `$_SERVER['HTTP_ACCEPT_LANGUAGE']` może nie istnieć. Powinieneś sprawdzać najpierw czy w ogóle jest wartość (np `isset`em) i uwzględnić ten przypadek.
// 4. Zmienne `$url` są Ci zbędne - wsadzaj wartość bezpośrednio do `wp_redirect`.
// 5. Jak już jesteś na głównej z PL, to przekierowanie zbędne.
// 6. Weź pod uwagę, że klient może przesłać język wielkimi literami.
<?php
// spoko, wiemy co należy przekazać
// ale kiepsko, bo dużo argumentów
function foo($bar1, $bar2, $bar3, $bar4, $bar5) {
}
// kiepsko, bo nie wiemy co dany parametr oznacza
foo('abc', 'def', 'ghj', 'klm', 'zxc');
@MacDada
MacDada / FavoriteRepository.php
Created December 12, 2016 11:00
What is that for?
<?php
use Doctrine\ORM\EntityRepository;
class FooRepository extends EntityRepository
{
public function save(Foo $foo)
{
$em = $this->getEntityManager();
$uof = $em->getUnitOfWork();
{# what is the proper way to escape var in url path in html in twig? #}
{# method A #}
<a href="/foo/{{ bar }}">Link</a>
{# method B #}
<a href="/foo/{{ bar|e('url') }}">Link</a>
{# method C #}
@MacDada
MacDada / ViewItemUseCase.php
Last active November 20, 2016 20:55
Authorization and Use Cases: option 1: authorization inside Use Case
<?php
namespace Foo\Bar\Application\UseCase;
use Foo\Bar\Application\AuthorizationChecker;
use Foo\Bar\Domain\ItemRepository;
class ViewItemUseCase
{
/**
<?php
class Order
{
public $user1;
public $user2;
}
@MacDada
MacDada / AuthenticationSuccessHandler.php
Last active September 18, 2016 23:55
Symfony AuthenticationSuccessHandler
<?php
namespace AppBundle\Security;
use Symfony\Component\Security\Http\Authentication\DefaultAuthenticationSuccessHandler;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\HttpFoundation\Request;
use Doctrine\Common\Persistence\ObjectManager;
use AppBundle\Entity\User;
use AppBundle\Entity\UserHasLoggedIn;
<?php
public function testInterval()
{
$date = new DateTime('+1 month');
$date->add(\DateInterval::createFromDateString('3 months'));
// Tested on 2016-08-31
// Failed asserting that two DateTime objects are equal.