Skip to content

Instantly share code, notes, and snippets.

@justin2004
justin2004 / session.sh
Created January 19, 2024 03:21
`sort -n` in APL
# `sort -n` will treat as many leading characters as digits as it can and it will do a numeric sort with whatever it was
# able to treat as a number
#
# e.g.
$ echo -e '123 file.txt\n65 exit.c\n465 words.rtf'
123 file.txt
65 exit.c
465 words.rtf
$ echo -e '123 file.txt\n65 exit.c\n465 words.rtf' | sort -n
@justin2004
justin2004 / session.sh
Last active February 1, 2024 19:55
Dyalog APL/S-64 Version 18.2.45405 -- dyalogscript reading inconsistently from /dev/stdin
# let's read from /dev/stdin
$ cat some.apl
⍝⎕←⍴⊃⎕NGET 'zeros.txt'
⎕←⍴⊃⎕NGET '/dev/stdin'
$ dd if=/dev/zero count=1 bs=100000 | dyalogscript <(cat some.apl)
1+0 records in
1+0 records out
100000 bytes (100 kB, 98 KiB) copied, 0.0149497 s, 6.7 MB/s
100001
@justin2004
justin2004 / example.txt
Last active November 2, 2023 02:16
github issues as RDF
first run SPARQL Anything (https://github.com/SPARQL-Anything/sparql.anything) as a
service then you can invoke a SPARQL query as demonstrated below.
you can also run SPARQL Anything not as a service but 1 query at a time
e.g. `java -jar sparql-anything.jar --query some.rq`
curl --silent 'http://localhost:3000/sparql.anything' \
--header "Accept: text/csv" \
@justin2004
justin2004 / example.sh
Last active October 26, 2023 21:36
Using APL in shell
# I needed to find the length of the longest filename
$ ls -1 *ttl
DatesAndTimes.ttl
download.ttl
exercise_log.ttl
gistHR0.2.0.ttl
nobel-prize-metaphacts-shacl-ontology.ttl
sample.ttl
SemArts2.0.0.ttl
visits_no_bnodes.ttl
@justin2004
justin2004 / example.md
Last active September 8, 2023 17:26
Using SPARQL Anything with parquet files

this approach relies on the fx:command property to transform the parquet file into csv

justin@X~/github/sparql.anything$ bash -c "python3 -c \"import pandas as pd ; pd.read_parquet(\\\"some.parquet\\\").to_csv(\\\"/dev/stdout\\\")\""
,name,age
0,bob,45
1,fred,3

then running the query below like this:

@justin2004
justin2004 / some.sparql
Created August 1, 2023 20:45
adding a duration to a time instant with SPARQL
e.g. 1 hour
bind(?start + xsd:dayTimeDuration("PT1H") as ?end)
@justin2004
justin2004 / a.txt
Created July 20, 2023 18:40
fuseki union graph by default
if you want to make the default graph the union graph (of all named graphs) you have to update the config file
for the jena dataset like this:
```
<#dataset> rdf:type tdb:DatasetTDB ;
tdb:location "DB" ;
tdb:unionDefaultGraph true ;
.
```
@justin2004
justin2004 / shell_session_with_apache_jena.txt
Last active April 26, 2023 16:52
Stardog -- remote jsonld context bug?
justin@parens:/tmp$ cat a.json
{ "@context":"http://18.221.230.193:9090/some.json",
"title": "the world according to garp",
"writer":"john irving",
"ical:date": "some date here",
"@type":"book"
}
justin@parens:/tmp$ curl 'http://18.221.230.193:9090/some.json'
{
@justin2004
justin2004 / some.json
Created April 26, 2023 15:42
a jsonld context
{
"@context": {
"ical": "http://www.w3.org/2002/12/cal/ical#",
"xsd": "http://www.w3.org/2001/XMLSchema#"
}
}
@justin2004
justin2004 / 1_readme.txt
Last active April 18, 2023 14:42
it is not safe to interpret jsonld as vanilla json in all cases
the 2 files below are equivalent when interpreted as jsonld but they are not equivalent vanilla json files.