Skip to content

Instantly share code, notes, and snippets.

View frgomes's full-sized avatar

Richard Gomes frgomes

View GitHub Profile
@frgomes
frgomes / install_retropie.sh
Last active December 12, 2019 02:17
bash - install RetroPie on UDOO Bold V8
#!/bin/bash
##
## This script is instended to install RetroPie on a newly installed Debian Buster box.
##
## Hardware requirements:
## This script is known to work well with UDOO Bolt V8, which has an AMD Ryzen 1000 SoC.
##
## Software Requirements:
##
@frgomes
frgomes / kubectl_helpers.sh
Last active August 18, 2019 08:58
k8s: find cluster names in kubectl configuration
#!/bin/bash
// one-liner which converts YAML to JSON
function yaml2json {
python -c 'import sys, yaml, json; y=yaml.load(sys.stdin.read()); print(json.dumps(y))'
}
function kubectl_clusters {
cat ~/.kube/config | yaml2json | jq '.clusters[].name' | sed 's/"//g'
}
@frgomes
frgomes / slick_schema_more_than_22_fields.scala
Last active August 10, 2019 11:06
Scala/Slick :: More than 22 fields using nested case classes
//----------------------------------------------------------------------------------------------------------------------
// This is an example of how more than 22 fields could be mapped with Slick 3.3.1 (other versions may work as well?).
//
// The general idea is pretty simple:
// 1. define a case class made of nested case classes.
// 2. define a projection made of nested projections.
//
// In addition, you can just get rid of noisy usages of ``GetResult`` generated by the Slick Code Generator.
// Just get rid of that, since usage of ``mapTo[T]`` makes definition of projections clean and hygienic.
//----------------------------------------------------------------------------------------------------------------------
@frgomes
frgomes / openssl_pfx.sh
Last active July 1, 2019 10:26
openssl - Convert from .PFX to CRT, CER, root PEM and client PEM
#!/bin/bash
# This lists the contents of a PFX file
# This is the last resort in case everything else fails.
# Just see its contents as a text file, cut whatever you need from it and
# paste manually onto separate files.
openssl pkcs12 -info -in input.pfx
# Found this in the internet. Not tested at all!
openssl pkcs12 -in input.pfx -out mycerts.crt -nokeys -clcerts
@frgomes
frgomes / thunderbird_exchange_server.md
Last active May 28, 2019 09:48
Thunderbird - connect to Exchange Server
@frgomes
frgomes / instanceOf.rs
Created April 11, 2019 18:15
Rust - instanceOf
enum FooBar {
Foo(u8),
Bar(u8)
}
fn test(v: bool) -> FooBar {
if v {
FooBar::Foo(5)
} else {
FooBar::Bar(10)
@frgomes
frgomes / git_rebase1.sh
Created April 4, 2019 08:01
git - rebase (B from A from master) onto (B from master)
#!/bin/bash
git rebase --onto master A B
@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")
@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}"))
}
object TypelevelPolymorphic extends App {
object square extends Poly {
import scala.language.reflectiveCalls
implicit val is = at[Int] { i => i * i }
implicit val fs = at[Float] { f => f * f }
implicit val ds = at[Double] { d => d * d }
}
trait Poly {