Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View frgomes's full-sized avatar

Richard Gomes frgomes

View GitHub Profile
@frgomes
frgomes / proxmox_openwrt.txt
Last active March 16, 2024 22:08
proxmox: install openwrt
proxmox / local / CT Templates
------------------------------
Download from URL: https://images.linuxcontainers.org/images/openwrt/23.05/amd64/default/20240316_11%3A57/rootfs.tar.xz
SHA-256: d6df8e1abeb24965146e22186b7aa767e3d42fac7fd71be0805cbc0c82377917
proxmox console
---------------
pct create 201 /var/lib/vz/template/cache/openwrt-20240316.tar.xz --arch amd64 --hostname openwrt --rootfs local-lvm:201 --memory 1024 --cores 2 --ostype unmanaged --unprivileged 1 --net0 name=eth0 --net1 name=eth1 --storage local-lvm
@frgomes
frgomes / RuntimeTypeTag.scala
Last active February 25, 2023 01:42
Scala / Spark: allows obtaining schema from runtime TypeTag obtained from class loaded over the wire
import scala.reflect.runtime.universe._
import scala.reflect.api
def runtimeTypeTagOf(name: String, parent: ClassLoader, url: java.net.URL): TypeTag[_] =
runtimeTypeTagOf(name, parent, Seq(url))
def runtimeTypeTagOf(name: String, parent: ClassLoader, urls: Seq[java.net.URL]): TypeTag[_] =
runtimeTypeTagOf(name, new java.net.URLClassLoader(urls.toArray, parent))
def runtimeTypeTagOf(name: String, cl: ClassLoader): TypeTag[_] = {
val c = Class.forName(name, true, cl)
val mirror: Mirror = runtimeMirror(cl)
@frgomes
frgomes / TypeTag2ClassTag.scala
Last active January 31, 2023 12:52
Scala: obtain ClassTag from TypeTag
import reflect.runtime.universe._
import reflect.ClassTag
def typeTag2ClassTag[T: TypeTag]: ClassTag[T] = {
ClassTag[T]( typeTag[T].mirror.runtimeClass( typeTag[T].tpe ) )
}
@frgomes
frgomes / SimilarSchema.scala
Last active December 18, 2022 03:58
Spark - Compare schemas, ignoring ``nullable`` settting
package object spark {
import org.apache.spark.sql.types.StructType
implicit class StructTypeExtension(schema: StructType) {
import org.apache.spark.sql.types.StructField
implicit def similar(other: StructType): Boolean = _similar(schema, other)
implicit val fieldOrdering: Ordering[StructField] = Ordering.by(field => field.name)
private final def _similar(_this: StructType, _other: StructType): Boolean =
@frgomes
frgomes / ProductExtension.scala
Created October 29, 2022 01:37
Scala - obtain field names and field types from case class employing TypeTag
import scala.reflect.runtime.universe.TypeTag
implicit class ProductExtension[T <: Product : TypeTag](o: T) {
def productElementNames: Iterator[String] = {
import scala.reflect.runtime.universe._
typeOf[T].members
.collect { case m: MethodSymbol if m.isCaseAccessor => m.name.toString }
.toList.reverse.toIterator
}
@frgomes
frgomes / SparkExampleTests.scala
Created April 10, 2022 21:50
Spark - template for integration tests
package com.example
import utest._
object SparkExampleTests extends TestSuite {
import scala.util.{Try,Success,Failure}
import org.apache.spark.sql.SparkSession
val _spark: Try[SparkSession] =
Try {
@frgomes
frgomes / Configs.scala
Last active April 10, 2022 12:47
SBT - multiproject build with projectmatrix and additional configurations
//file: project/Configs.scala
import sbt._
object Configs {
val FunctionalTest = config("ft") extend (Test)
val AcceptanceTest = config("at") extend (Test)
val PerformanceTest = config("pt") extend (Test)
val Tools = config("tools") extend (Test)
}
@frgomes
frgomes / sbt_disable_publishing.sbt
Last active March 28, 2022 23:49
SBT - disable publishing
def disablePublishing: Seq[Setting[_]] =
Seq(
publish/skip := true,
publishLocal/skip := true
)
@frgomes
frgomes / SlickConfig.scala
Created March 9, 2022 19:50
Scala - Read database credentials from file
trait SlickConfig {
import scala.util.{Try, Success, Failure}
private val RegexDB2 = "^jdbc:(db2):.*//(.*):(.*)/([^;]*)[?:;](.*)".r
private val RegexDerby = "^jdbc:(derby):.*//(.*):(.*)/([^;]*)[?:;](.*)".r
private val RegexH2 = "^jdbc:(h2):(?:mem):()()([^;]*)[?:;](.*)".r
private val RegexHsqlDB = "^jdbc:(hsqldb):.*//(.*):(.*)/([^;]*)[?:;](.*)".r
private val RegexSqlServer = "^jdbc:(sqlserver)://(.*):(.*);DatabaseName=([^;]*)[?:;](.*)".r
private val RegexjTDS = "^jdbc:(jtds):sqlserver://(.*):(.*)/([^;]*)[?:;](.*)".r
private val RegexMySQL = "^jdbc:(mysql):.*//(.*):(.*)/([^;]*)[?:;](.*)".r
@frgomes
frgomes / sequence.scala
Created March 7, 2022 21:40
FP - sequence :: Seq[Try[T]] to Try[Seq[T]]
import scala.util.{Try,Success,Failure}
def sequence[T](seq: Seq[Try[T]]): Try[Seq[T]] =
seq
.foldRight(Try(List.empty[T])) {
case (item, acc) => for { a <- acc; i<- item } yield i :: a
}