Skip to content

Instantly share code, notes, and snippets.

View sllynn's full-sized avatar

Stuart Lynn sllynn

View GitHub Profile
@sllynn
sllynn / plot_graphviz.py
Created August 18, 2020 17:57
Display a graphviz Graph or Digraph in a notebook
def plot_graphviz(graph):
from tempfile import NamedTemporaryFile
from base64 import b64encode
with NamedTemporaryFile(suffix=".png") as fh:
graph.plot(to_file=fh.name)
img = b64encode(fh.read()).decode("UTF-8")
displayHTML(f"<img src='data:image/png;base64,{img}'>")
@sllynn
sllynn / module_reload.py
Created August 19, 2021 11:55
Reload a python module
import sys
try:
sys.modules.pop("tests.test_advanced")
from tests.test_advanced import AdvancedTestSuite
except KeyError as e:
pass
@sllynn
sllynn / unzipper.scala
Created April 27, 2022 17:50
Unzip a lot of zip files from DBFS
import org.apache.spark.sql.functions._
import spark.implicits._
import sys.process._
val paths = dbutils.fs.ls("/FileStore/shared_uploads/[email protected]/shapefiles/").toDF
.select("path", "name")
.where(col("path").endsWith(".zip"))
.withColumn("path", regexp_replace($"path", "dbfs:/", "/dbfs/"))
.withColumn("root", regexp_replace($"path", $"name", lit("")))
.drop("name")