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 / Example.html.twig
Last active December 25, 2016 13:02
Twig - HTML Meta / SEO tags # https://github.com/Wolnosciowiec
{% import "SEOTags.html.twig" as SEOTags %}
{% block header_meta %}
{{
SEOTags.draw({
'title': 'Hello World',
'description': 'Hi, this is a test',
'keywords': ['first', 'second', 'third'],
'image': 'http://.../image.jpg'
})
@blackandred
blackandred / pacman-cleanup-cache
Last active December 30, 2016 17:32
Arch Linux: Clean up pacman cache, leave only 2 versions of every package, the rest of olders remove
#!/usr/bin/python
import os
import collections
def getPackageName(fileName):
exp = fileName.split('-')
found = False
name = ""
sep = ""
@blackandred
blackandred / docker-compose-install.sh
Last active December 30, 2016 17:36
Ansible: Recent version of Docker-Compose on Debian/Ubuntu # https://github.com/Wolnosciowiec
#!/bin/bash
# Installs a recent version of docker-compose
# as on recent Ubuntu version it's pretty old
# but also this script could help to keep consistency
# between developer and production environment
# Based on: https://gist.github.com/wdullaer/f1af16bd7e970389bad3
COMPOSE_VERSION=`git ls-remote https://github.com/docker/compose | grep refs/tags | grep -oP "[0-9]+\.[0-9]+\.[0-9]+$" | tail -n 1`
sudo sh -c "curl -L https://github.com/docker/compose/releases/download/${COMPOSE_VERSION}/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose"
sudo chmod +x /usr/local/bin/docker-compose
@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
@blackandred
blackandred / datamapper.php
Last active January 1, 2017 16:40
PHP Data objects: Data mapper in manual way
<?php
namespace Manager;
use Doctrine\DBAL\Connection;
use Model\Entity\File;
use Symfony\Component\Serializer\Serializer;
/**
* @package Manager
@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 / 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 / README.md
Created March 12, 2017 12:33
Docker: Get running container IP address

Usage:

./docker-container-ip.sh container_name_here

@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 / 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"