Skip to content

Instantly share code, notes, and snippets.

Avatar

Jeff Potts jpotts

View GitHub Profile
@jpotts
jpotts / MemberOfGroupFromProperty.java
Last active September 29, 2021 07:52
This is a custom Share evaluator that checks if the current user is a member of a group. The group to check is grabbed from a property on the node. The node is specified in the evaluator config. If you know the group to check at compile time, there is already an OOTB evaluator for that.
View MemberOfGroupFromProperty.java
import java.util.ArrayList;
p
import org.alfresco.web.evaluator.BaseEvaluator;
import org.alfresco.web.extensibility.SlingshotEvaluatorUtil;
import org.json.simple.JSONObject;
import org.springframework.extensions.surf.RequestContext;
import org.springframework.extensions.surf.support.ThreadLocalRequestContext;
public class MemberOfGroupFromProperty extends BaseEvaluator {
protected SlingshotEvaluatorUtil util = null;
@jpotts
jpotts / jmeter-results.conf
Created August 30, 2014 21:28
Logstash config that can be used to read in JMeter test results and store them in Elasticsearch
View jmeter-results.conf
input {
file {
path => [ "/Users/jpotts/Documents/code/es-test/results.csv"]
}
}
filter {
if ([message] =~ "responseCode") {
drop { }
} else {
csv {
@jpotts
jpotts / InvokeSearchTemplate.java
Last active August 22, 2020 01:39
Code snippets that go along with an ecmarchitect.com blog post on Elasticsearch search templates.
View InvokeSearchTemplate.java
Map<String, Object> params = new HashMap<String, Object>();
params.put("search_term", "elasticsearch");
params.put("since", "now-30d");
Template template = new Template("tweets", ScriptService.ScriptType.FILE, MustacheScriptEngineService.NAME, null, params);
SearchRequestBuilder request = client.prepareSearch(INDEX).setTemplate(template);
SearchResponse response = request.execute().actionGet();
@jpotts
jpotts / addSecondaryType.java
Last active June 20, 2019 20:11
Adding an aspect (known in CMIS 1.1 as a "secondary type") by modifying cmis:secondaryObjectTypeIds. This requires that you connect using the CMIS 1.1 service URL. You do not need the Alfresco OpenCMIS Extension when using this approach. Works with Alfresco 4.2.e Community Edition and higher.
View addSecondaryType.java
List<Object> aspects = doc.getProperty("cmis:secondaryObjectTypeIds").getValues();
if (!aspects.contains("P:cm:geographic")) {
aspects.add("P:cm:geographic");
HashMap<String, Object> props = new HashMap<String, Object>();
props.put("cmis:secondaryObjectTypeIds", aspects);
doc.updateProperties(props);
System.out.println("Added aspect");
} else {
System.out.println("Doc already had aspect");
}
@jpotts
jpotts / example.sh
Created November 13, 2014 15:39
Need a better approach to sorting semantic version strings in Elasticsearch
View example.sh
# Delete the example index
curl -XDELETE "http://localhost:9200/sortable-version-test?pretty=true"
# Create a new example index
curl -X POST "http://localhost:9200/sortable-version-test?pretty=true"
# Set the mapping. Assumes version.groovy resides in $ES_HOME/config/scripts
curl -XPOST "http://localhost:9200/sortable-version-test/version/_mapping?pretty=true" -d'
{
"version": {
@jpotts
jpotts / user.properties
Created August 30, 2014 21:24
Apache JMeter user.properties that configures test settings as well as the CSV format for the test results
View user.properties
jmeter.save.saveservice.output_format=csv
jmeter.save.saveservice.data_type=false
jmeter.save.saveservice.label=true
jmeter.save.saveservice.response_code=true
jmeter.save.saveservice.response_data.on_error=false
jmeter.save.saveservice.response_message=false
jmeter.save.saveservice.successful=true
jmeter.save.saveservice.thread_name=true
jmeter.save.saveservice.time=true
jmeter.save.saveservice.subresults=false
@jpotts
jpotts / team_member.json
Created March 2, 2018 20:53
Example Team Member JSON
View team_member.json
{
"data": {
"type": "node--team_member",
"id": "d56fd5ed-65f8-4f31-b4c0-29f33ea67bfb",
"attributes": {
"nid": 16,
"uuid": "d56fd5ed-65f8-4f31-b4c0-29f33ea67bfb",
"vid": 17,
"langcode": "en",
"status": true,
@jpotts
jpotts / headshot.json
Last active March 2, 2018 20:53
Example Team Member and Headshot JSON
View headshot.json
{
"data": {
"type": "file--file",
"id": "311f36ae-b233-4db9-84ba-803525307e42",
"attributes": {
"fid": 2,
"uuid": "311f36ae-b233-4db9-84ba-803525307e42",
"langcode": "en",
"filename": "gravatar.png",
"uri": "public://2018-03/gravatar.png",
@jpotts
jpotts / fetch-blog-content.js
Created November 2, 2014 03:27
Use the prismic.io API to fetch blog posts
View fetch-blog-content.js
var Prismic = require('prismic.io').Prismic;
var testRepo = 'https://your-repo.prismic.io/api';
Prismic.Api(testRepo, function(err, api) {
if (err) console.log(err);
api.form('blogPosts').ref(api.master()).submit(function(err, docs) {
if (err) console.log(err);
for (var i = 0; i < docs.results.length; i++) {
@jpotts
jpotts / Reindexer.java
Created January 19, 2015 15:20
Use a scroll and the bulk api to reindex docs in an Elasticsearch index within the same cluster
View Reindexer.java
public class Reindexer extends BaseElasticsearchUtility {
private static Log logger = LogFactory.getLog(Reindexer.class);
public static void main(String[] args) {
if (args.length != 5) {
doUsage();
System.exit(-1);
}