Skip to content

Instantly share code, notes, and snippets.

View aamedina's full-sized avatar

Adrian Medina aamedina

View GitHub Profile
@aamedina
aamedina / atlas-tactics.ttl
Created May 8, 2024 18:54
ATLAS Tactics (D3FEND)
@prefix d3f: <http://d3fend.mitre.org/ontologies/d3fend.owl#> .
@prefix dcterms: <http://purl.org/dc/terms/> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix skos: <http://www.w3.org/2004/02/skos/core#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
d3f:AML.TA0006 rdf:type owl:Class , owl:NamedIndividual , d3f:ATLASTactic;
rdfs:isDefinedBy <https://atlas.mitre.org/tactics/AML.TA0006>;
@aamedina
aamedina / z3.clj
Last active April 28, 2024 22:41
shelling out to z3 from clojure 1.12
;; rdfs:seeAlso <https://microsoft.github.io/z3guide/docs/logic/Lambdas>
(require '[clojure.edn :as edn])
(require '[clojure.java.process :as proc])
(require '[clojure.java.io :as io])
;; TODO: this can be simplified with a clojure macro (load-z3 forms...)
(let [input (java.io.File/createTempFile "input" ".z3")]
(doseq [form '[(declare-const a Int)
@aamedina
aamedina / enterprise-attack.ttl
Created April 21, 2024 23:24
Enterprise ATT&CK 14.1 in RDF (WIP)
This file has been truncated, but you can view the full file.
@prefix : <https://github.com/mitre-attack/attack-stix-data/raw/master/enterprise-attack/enterprise-attack-14.1.json#> .
@prefix d3f: <http://d3fend.mitre.org/ontologies/d3fend.owl#> .
@prefix dcterms: <http://purl.org/dc/terms/> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix skos: <http://www.w3.org/2004/02/skos/core#> .
@prefix stix: <http://docs.oasis-open.org/cti/ns/stix#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
(use-package lsp-mode
:ensure t
:bind (:map lsp-mode-map
("M-." . lsp-find-definition)
("TAB" . company-indent-or-complete-common))
:hook ((typescript-ts-mode . lsp-deferred)
(js-mode . lsp-deferred)
(js2-mode . lsp-deferred)
(js-jsx-mode . lsp-deferred)
(tsx-ts-mode . lsp-deferred)
@aamedina
aamedina / carousel.md
Created November 10, 2023 20:32
The Carousel of Dreams: A Wikipunk Story by Abulafia
@aamedina
aamedina / rdf_loader.py
Created September 19, 2023 22:17
An extremely basic generic RDF loader for PyG HeteroData
# extended from https://pytorch-geometric.readthedocs.io/en/latest/_modules/torch_geometric/datasets/entities.html#Entities
import os
import os.path as osp
import requests
from collections import defaultdict
from sklearn.preprocessing import MultiLabelBinarizer
import torch
import rdflib as rdf
from torch_geometric.data import HeteroData, InMemoryDataset
(in-ns 'dev)
; this function creates a database suitable for testing the system with a complete datomic schema derived from loaded RDF models (SPDX etc)
(def boot-db (db/test-bootstrap (:db system)))
; make-test-db forks the boot-db with tx-data parsed from the SPDX SBOM (RDF/XML) and lightly massages it for Datomic:
; note how any conforming SPDX RDF SBOM can be ingested
(def sbom (make-test-db boot-db [(rdf/parse "https://github.com/spdx/spdx-spec/raw/development/v2.3.1/examples/SPDXRdfExample-v2.3.spdx.rdf.xml")]))
^{:dcat/downloadURL
"https://www.w3.org/TR/vocab-ssn/integrated/examples/ice-core.ttl",
:rdf/ns-prefix-map
{"geo" "http://www.w3.org/2003/01/geo/wgs84_pos#",
"rdf" "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
"xsd" "http://www.w3.org/2001/XMLSchema#",
"time" "http://www.w3.org/2006/time#",
"sosa" "http://www.w3.org/ns/sosa/",
"ssn" "http://www.w3.org/ns/ssn/"}}
[{:rdfa/uri "http://example.org/data/WellDrilling/4578",
^{:dcat/downloadURL
"https://www.w3.org/TR/vocab-ssn/integrated/examples/seismograph.ttl",
:rdf/ns-prefix-map
{"geo" "http://www.w3.org/2003/01/geo/wgs84_pos#",
"qudt-unit-1-1" "http://qudt.org/1.1/vocab/unit#",
"rdf" "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
"qudt-1-1" "http://qudt.org/1.1/schema/qudt#",
"xsd" "http://www.w3.org/2001/XMLSchema#",
"rdfs" "http://www.w3.org/2000/01/rdf-schema#",
"sosa" "http://www.w3.org/ns/sosa/",
^{:dcat/downloadURL
"https://www.w3.org/TR/vocab-ssn/integrated/examples/tree-height.ttl",
:rdf/ns-prefix-map
{"qudt-unit-1-1" "http://qudt.org/1.1/vocab/unit#",
"rdf" "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
"qudt-1-1" "http://qudt.org/1.1/schema/qudt#",
"xsd" "http://www.w3.org/2001/XMLSchema#",
"rdfs" "http://www.w3.org/2000/01/rdf-schema#",
"sosa" "http://www.w3.org/ns/sosa/",
"ssn" "http://www.w3.org/ns/ssn/"}}