Skip to content

Instantly share code, notes, and snippets.

View erikerlandson's full-sized avatar

Erik Erlandson erikerlandson

View GitHub Profile
@erikerlandson
erikerlandson / symbol.scala
Created January 31, 2023 23:36
get the value type of a scala 3 symbol as a TypeRepr
def symbolValueType(using Quotes)(
sym: quotes.reflect.Symbol
): quotes.reflect.TypeRepr =
import quotes.reflect.*
val TermRef(tr, _) = sym.termRef: @unchecked
// widen is important here otherwise you may get singleton or by-name types
tr.memberType(sym).widen
import java.lang.{ClassLoader, Package}
def allDefinedPackages(loader: ClassLoader): Vector[Package] =
if (loader == null)
Vector.empty[Package]
else
allDefinedPackages(loader.getParent()) ++ loader.getDefinedPackages()
def allClassPathURLs(loader: ClassLoader): Vector[java.net.URL] =
loader match
object code:
import scala.quoted.*
trait Context[T]:
val t: Int
given Context[Int] with
val t = 7
transparent inline def aMacro[T]: Int = ${ aMacroImpl[T] }
@erikerlandson
erikerlandson / ray_pi.py
Created April 22, 2021 14:21
SimpleRDD implemented in Ray
def ray_pi(n = 1000, k = 10):
c = SimpleRDD(range(n*k), k=k) \
.map(lambda _: (random.uniform(-1,1), random.uniform(-1,1))) \
.filter(lambda p: p[0]*p[0] + p[1]*p[1] <= 1) \
.count()
return 4 * c / (n*k)
package repro
trait ResZero[V]:
type Res
object ResZero:
transparent inline given [V]: ResZero[V] = ${ macros.resZeroImpl[V] }
end ResZero
trait SomeTrait[V]:
type Res
// This module isn't really a ScalaModule, but we use it to generate
// consolidated documentation using the Scaladoc tool.
object docs extends ScalaModule {
def scalaVersion = "3.0.0-M3"
def docSource = T.source(millSourcePath)
def moduleDeps = Seq(
...
)
@erikerlandson
erikerlandson / podman-s2i-dir.sh
Created February 19, 2021 23:19
Example of chaining s2i podman image build using --as-dockerfile
#!/bin/bash
set -e
if [ $# -lt 2 ]; then
echo "usage: $0 <src-dir> <img-tag> [ <s2i-args> ... ]"
exit 1
fi
fail() {
echo $1
@erikerlandson
erikerlandson / sparkcluster.yaml
Created January 15, 2021 00:03
example of new SparkCluster CR starting with ODH 0.9
apiVersion: radanalytics.io/v1
kind: SparkCluster
metadata:
name: spark-cluster-example
spec:
customImage: 'quay.io/radanalyticsio/openshift-spark-py36:2.4.5-2'
env:
- name: SPARK_METRICS_ON
value: prometheus
master:
@erikerlandson
erikerlandson / imagestream.yaml
Created January 14, 2021 21:31
example imagestream from dockerfile with reference policy
apiVersion: image.openshift.io/v1
kind: ImageStream
metadata:
name: spark-app-s2i
spec:
lookupPolicy:
local: true
tags:
- name: latest
from:
@erikerlandson
erikerlandson / template-fragment.yaml
Last active December 8, 2020 20:41
notebook pod service template
# https://github.com/opendatahub-io/odh-manifests/blob/master/jupyterhub/jupyterhub/base/jupyterhub-spark-operator-configmap.yaml#L6-L19
notebookPodServiceTemplate: |
apiVersion: v1
kind: Service
metadata:
labels:
name: "jupyterhub-nb-{{ user }}"
spec:
clusterIP: None
selector: