Skip to content

Instantly share code, notes, and snippets.

View blackandred's full-sized avatar
Let's change the world

Andrew Johnson blackandred

Let's change the world
  • Non-profit, activist
  • Saskatoon, Canada
View GitHub Profile
@blackandred
blackandred / SerializerAware.php
Last active May 14, 2019 17:43
Symfony 4: Trait + Setter injection
<?php declare(strict_types = 1);
namespace App\Core\DependencyInjection\Extension;
use App\Core\Service\Serializer;
/**
* Extends the class with awareness of Serializer service
*
* Created for free for the anarchist movement around the world.
@blackandred
blackandred / Makefile
Created October 11, 2018 04:54
Makefile template
.SILENT:
# Colors
COLOR_RESET = \033[0m
COLOR_INFO = \033[32m
COLOR_COMMENT = \033[33m
## This help screen
help:
printf "${COLOR_COMMENT}Usage:${COLOR_RESET}\n"
@blackandred
blackandred / doctrine.php
Last active September 9, 2018 08:55
Doctrine: Automatic mapping for entities in multiple directories (DDD)
<?php declare(strict_types=1);
/*
* Doctrine auto-mapping
*/
if (!function_exists('generateDoctrineMappings')) {
function generateDoctrineMappings(): array
{
$domains = glob(__DIR__ . '/../../src/Domain/*/Entity');
root@fbda086ffd7e:/# resolve_stack_dump -s ./mysql.sym -n ./mysql.stack
0x7aa245 my_print_stacktrace + 53
0x677123 handle_fatal_signal + 1027
0x7f74a5510890 _end + -1537442712
0x8a7b5a dict_table_check_foreign_keys + 343050
0x824f51 _ZN21ha_innobase_add_indexD0Ev + 391329
0x828c46 _ZN21ha_innobase_add_indexD0Ev + 406934
0x855f49 dict_table_check_foreign_keys + 8185
0x85ad20 dict_table_check_foreign_keys + 28112
0x845321 _ZN21ha_innobase_add_indexD0Ev + 523377
@blackandred
blackandred / symfony-mock-validator-is-valid.php
Created July 31, 2018 09:53
Symfony: Mock Symfony validator to return always true in isValid() for functional testing
<?php
protected function mockFormValidationToReturnValid(): void
{
$form = $this->createMock(FormInterface::class);
$form->method('isValid')->willReturn(true);
$factory = $this->createMock(FormFactoryInterface::class);
$factory->method('create')->willReturn(FormInterface::class)->willReturn($form);
$this->getContainer()->set('form.factory', $factory);
@blackandred
blackandred / implemented-traits.php
Created July 30, 2018 06:38
PHP: Get all implemented traits recursively in parents, parents-parents, parents-...-parents
<?php declare(strict_types=1);
class SomeThing
{
private function getClassTraitNames(string $className = null): array
{
if ($className === null || !class_exists($className)) {
return [];
}
@blackandred
blackandred / mysql.sh
Created July 18, 2018 20:33
Docker + MySQL 5.1 problem solution: "[ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.host'" "docker"
#!/bin/bash
if [[ ! -f /var/lib/mysql/ibdata1 ]]; then
cd /usr/local/mysql/
mysql_install_db --user=mysql --ldata=/var/lib/mysql
fi
echo " >> Starting MySQL from /var/lib/mysql"
exec mysqld --datadir=/var/lib/mysql
@blackandred
blackandred / tornado-cors-all.py
Created June 5, 2018 04:52
Tornado: Set CORS headers for every controller (use origin with * for dev environment and for internal services behind firewall)
import tornado.web
#
# Created for Anarchist movement
#
# http://iwa-ait.org
# http://zsp.net.pl
#
@blackandred
blackandred / ProxyController.py
Created May 31, 2018 19:55
Tornado: Redirect all traffic to external server
from tornado import web
import tornado
import tornado.httpclient
import tornado.httputil
import logging
from .BaseController import BaseHandler
logger = logging.getLogger('tornado_proxy')
#!/bin/bash
printf " >> Pulling all base images\n"
for image_name in $$(cat ./containers/*/Dockerfile | grep -E "FROM (.*)" | sed -e 's/FROM //g'); do \
echo " >> Pulling $$image_name"; \
sudo docker pull "$${image_name}"; \
done
printf " >> Pulling images from docker-compose\n"
sudo docker-compose pull