Skip to content

Instantly share code, notes, and snippets.

View frgomes's full-sized avatar

Richard Gomes frgomes

View GitHub Profile
@frgomes
frgomes / kvm_host_network_interfaces
Created January 10, 2022 01:42
Linux - Turn off AAAA queries in Debian
## /etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
source /etc/network/interfaces.d/*
# The loopback network interface
auto lo
iface lo inet loopback
@frgomes
frgomes / RegexExtractorDomainName.scala
Last active June 22, 2021 02:09
Scala - Pattern match extractors, Regex domain names, IPv4, IPv6
/** Parse any IPv4 address or IPv6 address or domain name */
def parsePeerAddress(value: String): Try[String] =
parseIPv4(value) orElse parseIPv6(value) orElse parseHostname(value)
/** Parse IPv4 address */
def parseIPv4(value: String): Try[String] =
value.trim match {
case regexIPv4(_*) => Success(value)
case _ => Failure(new IllegalArgumentException(s"invalid IPv4 address name: ${value.trim}"))
}
@frgomes
frgomes / install-docker.sh
Last active June 6, 2021 18:52
Debian - install docker in Debian Jessie
#!/bin/bash
# compiled from https://docs.docker.com/engine/installation/linux/debian/#/debian-jessie-80-64-bit
sudo apt-get update
sudo apt-get dist-upgrade -y
sudo apt-get install apt-transport-https ca-certificates -y
sudo sh -c "echo deb https://apt.dockerproject.org/repo debian-jessie main > /etc/apt/sources.list.d/docker.list"
sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
@frgomes
frgomes / linalg.sh
Last active May 3, 2021 01:04
Bash - Matrix multiplication, passing associative arrays to functions, returning associative arrays from functions
#!/bin/bash -eu
function linalg_matrix_dump {
local -n M=${1}
local -a data=(${M[data]})
typeset -i rows=${M[rows]}
typeset -i cols=${M[cols]}
typeset -i i j
printf "%s:\n" ${1}
for ((i=0;i<rows;i++)) ; do
@frgomes
frgomes / github_clone_user.py
Last active April 17, 2021 05:12
Python - github_clone_user - clones all repositories of type=sources
#!/usr/bin/env python3
import json
import requests
import argparse
import os
import sys
from git import Repo
##
@frgomes
frgomes / gist:46d60e1da1d76df878323467a9930a8e
Created April 7, 2021 10:31
Rust - LinkedList and DoubleLinkedList
mod LinkedList {
type Link<T> = Option<Box<Node<T>>>;
struct Node<T> {
value: T,
next: Link<T>,
}
}
mod DoubleLinkedList {
use core::cell::RefCell;
@frgomes
frgomes / cmake-out_of_tree.md
Last active March 25, 2021 04:28
bash - run cmake out of tree / run cmake out of project

Instead of running cmake in tree such as:

cd ${WORKSPACE}
git clone http://github.com/WebAssembly/wabt

cd wabt
mkdir build
cd build
cmake ..

cmake --build .

@frgomes
frgomes / gist:4cb640a4507976f50a3b5847f8fd77d1
Last active March 3, 2021 20:46
salt: Create Salt installation in a virtual environment
#!/bin/bash -ex
# This script creates a Salt installation inside a virtual environment so that
# a steteful infrastructure aiming customer A is absolutely oblivious of customer B.
#
# No changes are required on configuration files, so that you can be sure that
# whatever you keep in the source control is valid in production. All you have to do
# in production is copying the trees /etc/salt and /srv/salt from the source control
# to their glorified places /etc/salt and /srv/salt in production.
#
@frgomes
frgomes / find_public_keys.py
Created February 9, 2021 23:53
Python - Find public keys matching a given list of patterns
def contents(ssh, files):
for file in files:
path = '{}/{}'.format(ssh, file)
yield open(path).read().replace("\n", "")
def keysFor(args):
ssh = '{}/.ssh'.format(os.environ['HOME'])
extensions = [ '.pub' ]
files = [f for f in os.listdir(ssh) if os.path.splitext(f)[1] in extensions]
keys = [k for k in contents(ssh, files) if k.split(' ')[2] in args]
@frgomes
frgomes / ChainingTry.scala
Last active November 18, 2020 17:45
Scala - Chaining Try/Success/Failure, return first successful
def a: Try[String] = Failure(new RuntimeException)
def b: Try[String] = Failure(new RuntimeException)
def c: Try[String] = Success("C")
def d: Try[String] = Failure(new RuntimeException)
def e: Try[String] = Success("E")
def f: Try[String] = Failure(new RuntimeException)
val result = a orElse b orElse c orElse d orElse e orElse f
// result is Success("C")