Skip to content

Instantly share code, notes, and snippets.

View tomsaleeba's full-sized avatar

Tom Saleeba tomsaleeba

View GitHub Profile
@tomsaleeba
tomsaleeba / async-await-error-handling.js
Created July 24, 2018 03:16
NodeJS async/await error propagation
// direct as promise
;(function () {
const prefix = '[direct-promise level]'
async function direct () {
throw new Error(`${prefix} explosion`)
}
direct().then(() => {
console.log(`${prefix} success`)
}).catch(err => {
@tomsaleeba
tomsaleeba / README.md
Last active May 18, 2018 04:25
Bulk file rename

Assume have a directory of files in an Angular.io project. We need to clone them all but rename and do a find+replace in them to work with another model name. The old model is plot and the new model is photo.

  1. Clone the directory and contents
    cp -r plot photo
    cd photo
  2. create a script to receive the results from our find:

blah.sh

@tomsaleeba
tomsaleeba / README.md
Created May 15, 2018 08:01
Deleting batches of records with SPARQL

I learned this when trying to clear our records in AWS Neptune. I was hitting the query timeout when trying to drop an entire graph. If you don't want to/can't raise the timeout, you can drop smaller parts of the graph in each transaction.

curl -sX POST http://<cluster-prefix>.rds.amazonaws.com:8182/sparql --data-urlencode 'update=
DELETE {
  GRAPH <http://aws.amazon.com/neptune/vocab/v01/DefaultNamedGraph> { ?s ?p ?o }
}
WHERE {
  GRAPH <http://aws.amazon.com/neptune/vocab/v01/DefaultNamedGraph> {
 {
@tomsaleeba
tomsaleeba / README.md
Last active May 16, 2018 00:32
Concatenating RDF Turtle files

ttlcat

When you have a series of *.ttl files in a directory and you want to cat them all together, you need to make sure you strip out the @prefix and only prepend it once to the output.

Use the following commands

# run *in* the directory with the TTL files
head -n 50 -q *.ttl | grep '^@prefix' | sort -u > header
time cat *.ttl | grep -v '^@prefix' | cat header - | gzip > $(basename $(pwd)).ttl.gz
rm header
@tomsaleeba
tomsaleeba / bash-wait-demo.sh
Created March 9, 2018 00:23
BASH wait command demo
#!/usr/bin/env bash
# short demo on how to wait for multiple jobs
echo 'start'
sleep 2 &
job1=$!
echo "do things that don't require job 1 output"
sleep 4 &
job2=$!
echo "do things that don't require job 2 output"
wait $job1

Keybase proof

I hereby claim:

  • I am tomsaleeba on github.
  • I am tomsaleeba (https://keybase.io/tomsaleeba) on keybase.
  • I have a public key ASCQLgwf5nOen0sIm5tyL5yq_ZO2slYSfrfH69tm02Y91go

To claim this, I am signing this object: