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 / 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 / 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 / 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 / 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 / network-redirections.sh
Created March 22, 2017 05:52
#1: Redirect traffic from port to port (local) #2: Route all incoming traffic to other host preserving the information about requester's IP address
#!/bin/bash
function get_gateway_interface() {
route|grep default|awk '{print $8}'
}
# Redirect all incoming traffic to the other port
function redirect_port_to_port() {
# $1 from port
# $2 to port
@blackandred
blackandred / README.md
Created March 12, 2017 12:33
Docker: Get running container IP address

Usage:

./docker-container-ip.sh container_name_here

@blackandred
blackandred / PostShortenTwigExtension.php
Created February 21, 2017 07:09
Twig: Shorten a HTML posted message
<?php
namespace Wolnosciowiec\Twig;
/**
* Shorten post preserving the HTML formatting
*/
class PostShortenTwigExtension extends \Twig_Extension
{
/**
@blackandred
blackandred / docker-host-ip.sh
Last active January 1, 2017 17:05
Docker: Get host IP and add it locally as docker_host_machine so it could be accessible eg. via http://docker_host_machine
#!/bin/bash
#
# Get host IP and add it locally as docker_host_machine so it could be accessible eg. via http://docker_host_machine
# ================================
# Requirements: iproute2
#
cat /etc/hosts | grep -v "docker_host_machine" > /etc/hosts.2 && mv /etc/hosts.2 /etc/hosts
echo "$(ip route show|grep src|awk '{print $9}') docker_host_machine" >> /etc/hosts
@blackandred
blackandred / main.yml
Last active November 15, 2024 02:10
Ansible + Docker: Clean up unused, old containers and images to free up the disk space
#
# Created for free for the anarchist movement around the world.
# See iwa-ait.org, zsp.net.pl, wolnosciowiec.net
#
- name: Schedule a clean up for Docker images
become: yes
cron:
name: "docker-clean-up-images"
minute: "0"
@blackandred
blackandred / main.yml
Created December 30, 2016 17:38
Ansible: Useful tools on Ubuntu/Debian server
- name: Install misc admin packages
become: yes
apt: name={{ item }} state=present
with_items:
- htop
- iotop
- mytop
- iftop
- iptraf
- telnet