Skip to content

Instantly share code, notes, and snippets.

Avatar

Richard Gomes frgomes

View GitHub Profile
View scala_base64_encode_decode.scala
// Base64 encode
val text = "This is plaintext."
val bytesEncoded = java.util.Base64.getEncoder.encode(text.getBytes())
// Base64 decode
val textDecoded = new String(java.util.Base64.getDecoder.decode(bytesEncoded))
println(textDecoded)
View ElanTabletWACOM.txt
Section "InputClass"
Identifier "Wacom driver override"
MatchProduct "ELAN2514:00 04F3:2B05"
MatchDevicePath "/dev/input/event*"
Driver "wacom"
EndSection
@frgomes
frgomes / RegexExtractorDomainName.scala
Last active Jun 22, 2021
Scala - Pattern match extractors, Regex domain names, IPv4, IPv6
View RegexExtractorDomainName.scala
/** 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 Jun 6, 2021
Debian - install docker in Debian Jessie
View install-docker.sh
#!/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 / ddns-update
Last active May 12, 2021
bash - sysadm - /usr/sbin/ddns-update
View ddns-update
#!/bin/bash -eu
#######################################################################
## ##
## A simple, lightweight and self contained alternative to ddclient. ##
## ##
## NOTE: This script only works with HE FreeDNS http://dns.he.net ##
## ##
#######################################################################
@frgomes
frgomes / linalg.sh
Last active May 3, 2021
Bash - Matrix multiplication, passing associative arrays to functions, returning associative arrays from functions
View linalg.sh
#!/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 Apr 17, 2021
Python - github_clone_user - clones all repositories of type=sources
View github_clone_user.py
#!/usr/bin/env python3
import json
import requests
import argparse
import os
import sys
from git import Repo
##
@frgomes
frgomes / gist:46d60e1da1d76df878323467a9930a8e
Created Apr 7, 2021
Rust - LinkedList and DoubleLinkedList
View gist:46d60e1da1d76df878323467a9930a8e
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 Mar 25, 2021
bash - run cmake out of tree / run cmake out of project
View cmake-out_of_tree.md

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 Mar 3, 2021
salt: Create Salt installation in a virtual environment
View gist:4cb640a4507976f50a3b5847f8fd77d1
#!/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.
#