Skip to content

Instantly share code, notes, and snippets.

@maryo
maryo / hosts
Last active March 21, 2024 12:02
devenv hosts file
192.168.1.11 .test
@maryo
maryo / server.php
Last active February 19, 2022 13:51
Naive (HTTP) socket server baseline
<?php
$host = '0.0.0.0';
$port = 8080;
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
socket_set_option($socket, SOL_SOCKET, SO_REUSEADDR, 1);
socket_bind($socket, $host, $port);
socket_listen($socket);
socket_set_nonblock($socket);
echo "Listening on {$host}:{$port}\n\n";
@maryo
maryo / Uuid.php
Created April 29, 2021 12:33
Simple UUID
<?php declare(strict_types = 1);
class Uuid implements Guid
{
private string $uuid;
public function __construct($uuid = null)
{
if ($uuid !== null) {
if (!static::isValid($uuid)) {
@maryo
maryo / download.js
Created January 28, 2019 01:24
Typekit font downloader
const https = require('https');
const fs = require('fs');
// https://github.com/majodev/google-webfonts-helper/blob/master/server/logic/conf.js
const FORMAT_USER_AGENTS = {
// see http://www.dvdprojekt.de/category.php?name=Safari for a list of sample user handlers
// test generation through running grunt mochaTest:src
eot: 'Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0)',
woff: 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:27.0) Gecko/20100101 Firefox/27.0',
// must serve complete woff2 file for one variant (no unicode range support yet!)
@maryo
maryo / SnippetRenderer.php
Created December 16, 2018 15:52
Symfony snippet renderer
<?php
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent;
use Symfony\Component\HttpKernel\KernelEvents;
@maryo
maryo / vlna.php
Created December 5, 2018 13:45
Vlna na webu
<?php
function vlna(string $text): string
{
return preg_replace('/([^a-zA-Z0-9])([ksvzaiou])\s([a-zA-Z0-9]{1,})/i', "\$1\$2\xc2\xa0\$3", $text);
}
@maryo
maryo / convert_to_camelcase.php
Created May 17, 2018 02:41
Convert unicode string to camel case
<?php
function substring(string $string, int $start, int $length = null): string
{
return mb_substr($string, $start, $length, 'UTF-8');
}
function lower(string $string): string
{
return mb_strtolower($string, 'UTF-8');
@maryo
maryo / IsolatedKernelTestCase.php
Last active November 2, 2015 16:28
Symfony2 / Doctrine2 Tests isolation without schema reloading / DB purging + fixtures support
<?php
namespace AcmeBundle\Test;
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
use Doctrine\Common\DataFixtures\Executor\ORMExecutor;
use Doctrine\Common\DataFixtures\Loader;
use Doctrine\Common\DataFixtures\ReferenceRepository;
use Doctrine\DBAL\Connection;
use Doctrine\ORM\EntityManager;
use Symfony\Bridge\Doctrine\DataFixtures\ContainerAwareLoader;
@maryo
maryo / Client.php
Last active August 29, 2015 14:03
Doctrine2 isolation of tests
<?php
namespace Company\SecretBundle\Test;
use Doctrine\DBAL\Connection;
use Symfony\Bundle\FrameworkBundle\Client as BaseClient;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\HttpKernel\TerminableInterface;
@maryo
maryo / SafeConditionWalker.php
Last active December 24, 2015 07:19
Doctrine2 Sandboxing Safe Condition DQL AST Walker
<?php
use Doctrine\ORM\Query\AST;
use Doctrine\ORM\Query\TreeWalkerAdapter;
class SafeConditionWalker extends TreeWalkerAdapter
{
/** @var bool */
private $inCondition = false;
/**