Skip to content

Instantly share code, notes, and snippets.

View lonniev's full-sized avatar
🧙‍♀️
Orchestrating Value Monetization

Lonnie VanZandt lonniev

🧙‍♀️
Orchestrating Value Monetization
View GitHub Profile
@lonniev
lonniev / GremlinGroovyCountOfTypesInThread.groovy
Created September 2, 2022 21:21
Perform a Gremlin Query that counts within a Digital Thread the kinds of Types therein
g.E().has( 'Relation', 'container', 'Drone-006' ).bothV().dedup()
.where( and(
out( 'hasType' ),
out( 'ownedBy' ).or(
has( 'name', 'DronesFlow' ),
has( 'name', 'Drone_MDO_With_Mid_Fid_Aero' ),
has( 'name', 'Esteco_Drone03-StructureAndParametrics_a' ) ) ) )
.group().by( out( 'hasType' ).values( 'name' ) ).by( count() )
@lonniev
lonniev / GremlinGroovyWhoWhenQuery.groovy
Last active November 25, 2022 21:38
Perform a Gremlin Query that looks up who changed a particular thread and when
userName = { u,t -> userGet = new URL( "http://syndeia.company.com:9000/users/${u}" ).openConnection(); userGet.setRequestProperty( "Accept", "application/json" ); userGet.setRequestProperty( "X-Auth-Token", t ); userGet.getResponseCode(); j = new groovy.json.JsonSlurper().parseText( userGet.getInputStream().getText() ); j.resources.name }
signInToken = { -> signInPost = new URL( "http://syndeia.company.com:9000/signIn" ).openConnection(); message = '{ "username": "[email protected]", "password": "pass-phrase", "rememberMe": false }'; signInPost.setDoOutput( true ); signInPost.setRequestProperty( "Content-Type", "application/json" ); signInPost.getOutputStream().write( message.getBytes( "UTF-8" ) ); signInPost.getResponseCode(); j = new groovy.json.JsonSlurper().parseText( signInPost.getInputStream().getText() ); j.resources.token }
g.E().has( 'Relation', 'container', 'DZSB19' )
.group()
.by( values( 'modifiedDate' )
.map{ ( LocalDateTime.parse( it.get(), java.time.format.DateTimeFormatter.IS
@lonniev
lonniev / GremlinGroovyPartsRequirementsQuery.groovy
Created September 1, 2022 12:22
Perform a Gremlin Query that finds Parts that have related Requirements and which groups by the Part
g.V().has( 'ArtifactType', 'name', 'Part' )
.match(
__.as( 't' ).in( 'hasType' ).as( 'p' ),
__.as( 't' ).out( 'ownedBy' ).as( 'r' ),
__.as( 'r' ).out( 'hasType' ).filter{ it.get().value( 'name' ).contains( 'Windchill' ) }.as( 'rt' ),
__.as( 'p' ).both( 'Relation' ).as( 'o' ),
__.as( 'o' ).out( 'hasType' ).filter{ it.get().value( 'name' ) ==~ /(?i).*?((requirement)|(task)).*/ }
)
.group()
.by( select( 'p' ) ).unfold().project( 'part', 'requirements' )
@lonniev
lonniev / GrelimGroovyQueryWithJiraDetails.groovy
Last active September 1, 2022 12:15
Perform a Gremlin Query that retrieves Jira Detail
reqPriority = { r,e -> reqPost = new URL( "http://some.host.com:9000/external/jira/${r}/artifacts/external/id?includeAttributes=priority" ).openConnection(); reqPost.setRequestProperty( "Content-Type", "application/json" ); reqPost.setRequestProperty( "Accept", "application/json" ); reqPost.setRequestProperty( "Ext-Auth-Token", "SOMETOKEN" ); reqPost.setRequestProperty( "User-Id", "SOMEUSER" ); reqPost.setDoOutput( true ); message = /{ "externalId": "${e}" }/; reqPost.getOutputStream().write( message.getBytes( "UTF-8" ) ); reqPost.getResponseCode(); j = new groovy.json.JsonSlurper().parseText( reqPost.getInputStream().getText() ); j.resources.attributes.priority.get( 'name' ) }
g.V().has( 'ArtifactType', 'name', 'Story' ).where( out( 'ownedBy' ).filter{ it -> it.get().value( 'name' ).contains( "Intercax" ) }.out( 'hasType' ).has( 'name', "JIRA Repository Type" ) ).in( 'hasType' ).limit( 1 ).as( 'e' ).out( 'ownedBy' ).out( 'ownedBy' ).as( 'r' ).select( 'r', 'e' ).by( 'sKey' ).by( 'externalId' ).map { it -> re
@lonniev
lonniev / GremlinGroovyQueryWithRestStep.groovy
Last active September 1, 2022 12:17
Perform a Gremlin Query which makes an authenticated REST call during one Step
signInToken = { -> signInPost = new URL( "http://some.host.com:9000/signIn" ).openConnection(); message = '{ "username": "[email protected]", "password": "my-password", "rememberMe": false }'; signInPost.setDoOutput( true ); signInPost.setRequestProperty( "Content-Type", "application/json" ); signInPost.getOutputStream().write( message.getBytes( "UTF-8" ) ); signInPost.getResponseCode(); j = new groovy.json.JsonSlurper().parseText( signInPost.getInputStream().getText() ); j.resources.token }
userName = { u,t -> userGet = new URL( "http://some.host.com:9000/users/${u}" ).openConnection(); userGet.setRequestProperty( "Accept", "application/json" ); userGet.setRequestProperty( "X-Auth-Token", t ); userGet.getResponseCode(); j = new groovy.json.JsonSlurper().parseText( userGet.getInputStream().getText() ); j.resources.name }
g.V().limit(1).map { it -> userName( it.get().value( 'modifiedBy' ), signInToken() ) }.find()
@lonniev
lonniev / GroovyHttpPost.groovy
Created August 30, 2022 11:43
Make an HTTP Post call in Groovy and parse the JSON response
signInPost = new URL( "http://some.host.com/login" ).openConnection()
message = '{ "username": "email", "password": "somepass", "rememberMe": false }'
signInPost.setDoOutput( true )
signInPost.setRequestProperty( "Content-Type", "application/json" )
signInPost.getOutputStream().write( message.getBytes( "UTF-8" ) )
signInPost.getResponseCode()
j = new groovy.json.JsonSlurper().parseText( signInPost.getInputStream().getText() )
j.resources.token
@lonniev
lonniev / jarSniffer.groovy
Last active November 23, 2021 13:53
A small Groovy script that scans a directory of folders for jar files and extracts POM-like dependency statements out of relevant content
package com.intercax.groovy.jarSniffer
import java.util.jar.*
/**
* @author Lonnie VanZandt fluent version
* @author Ivan Krizsan original idea
*/
// map of manually-resolved jars by their file names
@lonniev
lonniev / encrypt_data_bag.rb
Created April 20, 2017 11:59
Small Ruby script borrowed from someone else to encrypt a data bag
#!/usr/bin/env ruby
if ARGV.length < 2
puts "usage: #{$0} databag.json new_encrypted_databag.json [encrypted_data_bag_secret]"
exit(1)
end
databag_file = ARGV[0]
out_file = ARGV[1]
if ARGV.length >= 3
@lonniev
lonniev / Partition a Set into Subsets using a Predicate
Last active March 27, 2017 02:47
Given one collection, split it into several subsets based on either a Function or a Function based on a Predicate.
// partition a collection of properties into the two sets
// of those that satisfy a predicate and those that do not
final ImmutableListMultimap<Boolean, Entry<String, Object>> propertiesPair =
Multimaps.index(domainModelDTO.getProperties().entrySet(),
Functions.forPredicate(predicateMethod()));
final FluentIterable<Entry<String, Object>> truePropertiesList =
FluentIterable.from( propertiesPair.get( true ) );
final FluentIterable<Entry<String, Object>> falsePropertiesList =
@lonniev
lonniev / RuntimeTypeHelper.java
Created March 27, 2017 02:31
Determine the actual type of a method's first parameter at runtime when that parameter is generic.
public static Class<?> getTypeOfFirstParameter( final Method method )
{
final Type type = method.getGenericParameterTypes()[0];
// Now get the parametrized type of the generic.
if (!(type instanceof ParameterizedType))
{
return method.getParameterTypes()[0];
}