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 / monitor_ethernet_interface.sh
Created June 3, 2017 09:15
Recover internet connection after any failure (OS independent, works on all Linux distrubutions)
#!/bin/bash
if ! ping -c 1 google.com -W 10 > /dev/null 2>&1; then
interface=$(ifconfig -a |grep -E "(enp([a-z0-9]+)|eth([0-9]+))" | grep -v "veth" | awk '{print $1}' | sed -r "s/://g")
echo " >> Bringing up the ethernet interface $interface"
killall dhclient -9 > /dev/null 2>&1
dhclient $interface
echo " >> Setting up DNS"
@blackandred
blackandred / push_handler.py
Created November 26, 2017 08:46
Gogs: Push hook handler
import tornado.ioloop
import tornado.web
import json
import os
class MainHandler(tornado.web.RequestHandler):
config = {}
def initialize(self, config):
self.config = config
@blackandred
blackandred / README.md
Created November 27, 2017 07:52
Ansible: Own docker registry (ARM)

Docker Registry

Creates a docker registry for storing built images.

@blackandred
blackandred / PageType.php
Created February 16, 2018 06:12
Symfony 4: In context of edit (not creation) allow the fields to be partialy modified (single fields could be submitted, the rest ignored)
<?php declare(strict_types = 1);
namespace App\Core\Form\Type;
use App\Core\Service\Content\TextUtils;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\Extension\Core\Type\{TextType, LanguageType, SubmitType, CheckboxType};
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
@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 / tiles.js
Created March 31, 2018 19:55
Manages tiles with support for double-sized tiles
class TilesViewManager {
/**
* @param {array} tiles
* @param {number} maxTiles
* @param {number} maxInRow
* @param {number} maxDoubleElements
*/
constructor (tiles, maxTiles, maxInRow, maxDoubleElements) {
this.tiles = tiles
#!/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
@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')
@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 / 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