Skip to content

Instantly share code, notes, and snippets.

Let's change the world

Andrew Johnson blackandred

Let's change the world
  • Saskatoon, Canada
Block or report user

Report or block blackandred

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@blackandred
blackandred / jvm
Last active Jul 1, 2019
Use dockerized java easily, instead of running java on host. Keeps gradle cached packages in a mapped volume.
View jvm
#!/bin/bash
SUDO=${SUDO:-sudo}
IMAGE=${IMAGE:-openjdk:8-jre-stretch}
PARAMS="$@"
if [[ ! ${PARAMS} ]]; then
PARAMS="exit 1"
fi
@blackandred
blackandred / Makefile
Created Oct 11, 2018
Makefile template
View Makefile
.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 Sep 9, 2018
Doctrine: Automatic mapping for entities in multiple directories (DDD)
View doctrine.php
<?php declare(strict_types=1);
/*
* Doctrine auto-mapping
*/
if (!function_exists('generateDoctrineMappings')) {
function generateDoctrineMappings(): array
{
$domains = glob(__DIR__ . '/../../src/Domain/*/Entity');
View mysql.err
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 Jul 31, 2018
Symfony: Mock Symfony validator to return always true in isValid() for functional testing
View symfony-mock-validator-is-valid.php
<?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 Jul 30, 2018
PHP: Get all implemented traits recursively in parents, parents-parents, parents-...-parents
View implemented-traits.php
<?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 Jul 18, 2018
Docker + MySQL 5.1 problem solution: "[ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.host'" "docker"
View mysql.sh
#!/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 Jun 5, 2018
Tornado: Set CORS headers for every controller (use origin with * for dev environment and for internal services behind firewall)
View tornado-cors-all.py
import tornado.web
#
# Created for Anarchist movement
#
# http://iwa-ait.org
# http://zsp.net.pl
#
@blackandred
blackandred / ProxyController.py
Created May 31, 2018
Tornado: Redirect all traffic to external server
View ProxyController.py
from tornado import web
import tornado
import tornado.httpclient
import tornado.httputil
import logging
from .BaseController import BaseHandler
logger = logging.getLogger('tornado_proxy')
View docker-pull-containers.sh
#!/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
You can’t perform that action at this time.