Skip to content

Instantly share code, notes, and snippets.

@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];
}
@lonniev
lonniev / svnaid.zsh
Last active December 2, 2016 15:06
A utility script for managing svn "super projects" that consist of numerous separate svn projects (depends on zsh and parallel)
#!/usr/bin/zsh
#
# https://creativecommons.org/licenses/by/4.0/
# Original Author: Lonnie VanZandt
# Creation Date: 04 November 2016
# Summary: Simplify using Subversion SVN for Super Projects consisting of multiple independent sub-projects
# try to deduce the remote repo URL, superproject root, and local workspace root from available local files
SUPERURL=$'( [[ -d .svn ]] && echo `svn info --show-item repos-root-url` ) || echo "https://server.foo/svn/superproject"'
SUPERURL=`eval $SUPERURL`
@lonniev
lonniev / elevated_shell.ps1.erb
Created September 25, 2016 00:11
An Alternative construction of the TaskDefinition for Vagrant's 1.8.5 winrm communicator
param([String]$username, [String]$password, [String]$encoded_command, [String]$execution_time_limit)
# Try to get the Schedule.Service object. If it fails, we are probably
# on an older version of Windows. On old versions, we can just execute
# directly since priv. escalation isn't a thing.
$schedule = $null
Try {
$schedule = New-Object -ComObject "Schedule.Service"
} Catch [System.Management.Automation.PSArgumentException] {
powershell.exe -EncodedCommand $encoded_command
@lonniev
lonniev / Vagrantfile
Created August 10, 2015 03:39
Vagrantfile for Vagrant 1.74 that exhibits Chef-solo rsych problems
Vagrant.require_version ">= 1.7.4"
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.boot_timeout = 600
config.omnibus.chef_version = :latest
config.vm.guest = :windows
config.windows.set_work_network = true
config.vm.synced_folder ".", "/vagrant", type: "rsync"
config.vagrant.host = :detect
config.vm.define "sl-win-obeo" do | cci |
@lonniev
lonniev / hashify_nested_to_properties_list.rb
Created June 29, 2015 18:57
Given a nested hash, pretty print a list of corresponding dotted property = value lines
require 'JSON'
require 'pp'
def hashList( list, value )
head, *tail = list
head.sub!( /\[(.+)\]/, '\1' )
case tail