Skip to content

Instantly share code, notes, and snippets.

@ssullivan
ssullivan / Example.java
Created May 26, 2020 19:50
XSD Validation Java
public static boolean validateXMLSchema(String xsdPath, String xmlPath){
try {
SchemaFactory factory =
SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = factory.newSchema(new File(xsdPath));
Validator validator = schema.newValidator();
validator.validate(new StreamSource(new File(xmlPath)));
} catch (IOException | SAXException e) {
@ssullivan
ssullivan / Example.txt
Created May 22, 2020 00:58
AutoHotKey - Swap Alt and Command
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#::
Send, !
!::
Send, #
return
@ssullivan
ssullivan / Example.java
Last active April 26, 2020 19:13
Recurse through multi dimensional arrays
// these probably need some input checks
// recursive
private static Object getValue(Object baseArray, int dim, int[] coordinates) {
if (dim + 1 >= coordinates.length) {
return Array.get(baseArray, coordinates[dim]);
}
else {
return getValue(Array.get(baseArray, coordinates[dim]), dim + 1, coordinates);
}
@ssullivan
ssullivan / Example.java
Created April 16, 2020 01:22
Daffodil Parse
public static ProcessorFactory compileSchema(final String schema)
throws URISyntaxException, IOException {
Compiler compiler = Daffodil.compiler();
ProcessorFactory factory = compiler.compileSource(Resources.getResource(schema).toURI());
if (factory.isError()) {
factory.getDiagnostics()
.forEach(diagnostic -> {
LOGGER.error(diagnostic.getMessage(), diagnostic.getSomeCause());
});
@ssullivan
ssullivan / example.yml
Created April 15, 2020 20:46
buildspec cf
version: 0.2
phases:
install:
commands:
- pip install cfn-lint
build:
commands:
- cfn-lint --template ./template.yaml --regions $AWS_REGION
- aws cloudformation validate-template --template-body file://$(pwd)/template.yaml
@ssullivan
ssullivan / Example.bash
Created March 27, 2020 18:33
Locator Example Curl
curl 'https://findtreatment.samhsa.gov/locatorExcel' \
-H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:74.0) Gecko/20100101 Firefox/74.0' \
-H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' \
-H 'Accept-Language: en-US,en;q=0.5' \
--compressed \
-H 'Content-Type: multipart/form-data; boundary=---------------------------11366494723913231758399599945' \
-H 'Origin: https://findtreatment.samhsa.gov' \
-H 'Connection: keep-alive' \
-H 'Referer: https://findtreatment.samhsa.gov/locator' \
-H 'Cookie: _ga=GA1.2.646319725.1548901673' \
@ssullivan
ssullivan / Example.cs
Created February 6, 2020 01:47
DotNet Gremlin Get InVertex/OutVertex/Edge
var x = g.V(new []{1, 2, 3}).BothE().OtherV().Path().By(__.ValueMap<object, Path>(true)).Range<Path>(0, 10).ToList();
@ssullivan
ssullivan / Example.cs
Created December 27, 2019 03:33
Gremlin
g.E()
.Union<IDictionary<object, object>>(__
.Project<object>("e", "v", "IN", "OUT")
.By(__.Id())
.By(__.ValueMap<object, object>(true))
.By(__.InV().Union<object>(__.Id(), __.Label()).Fold())
.By(__.OutV().Union<object>(__.Id(), __.Label()).Fold()))
.ToList()
@ssullivan
ssullivan / Example.cs
Created December 18, 2019 04:45
DotNet Gremlin
using System.Collections;
using System.Collections.Generic;
using GraphStore.Models;
using Gremlin.Net.Process.Traversal;
using Gremlin.Net.Structure;
using static Gremlin.Net.Process.Traversal.AnonymousTraversalSource;
using static Gremlin.Net.Process.Traversal.__;
using static Gremlin.Net.Process.Traversal.P;
using static Gremlin.Net.Process.Traversal.Order;
using static Gremlin.Net.Process.Traversal.Operator;
@ssullivan
ssullivan / userdata.sh
Created November 12, 2019 01:03
AWS Neptune User Init Script
sudo yum install -y java-1.8.0-devel
sudo /usr/sbin/alternatives --config java
mkdir -p /opt/
wget https://archive.apache.org/dist/tinkerpop/3.4.1/apache-tinkerpop-gremlin-console-3.4.1-bin.zip
mv apache-tinkerpop-gremlin-console-3.4.1-bin.zip /opt/
unzip /opt/apache-tinkerpop-gremlin-console-3.4.1-bin.zip
cd apache-tinkerpop-gremlin-console-3.4.1 && wget https://www.amazontrust.com/repository/SFSRootCAG2.pem
cat <<EOF > /opt/apache-tinkerpop-gremlin-console-3.4.1
hosts: [your-neptune-endpoint]
port: 8182