Skip to content

Instantly share code, notes, and snippets.

@ryanjdew
ryanjdew / merging.sjs
Created February 20, 2020 22:08
Patch to Data Hub merging step
/**
Copyright 2012-2019 MarkLogic Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
@ryanjdew
ryanjdew / es6.ebnf
Last active August 15, 2018 21:27 — forked from avdg/es6.ebnf
ES6 bnf grammer - See https://avdg.github.io/es6.xhtml
/* ebnf file for es 6 - MAY CONTAIN ERRORS / DISAMBIGUITY */
/* Edited by @ryanjdew for compatiblity with REx Parser: es6.ebnf -ll 1 -backtrack -javascript -faster */
Program ::= (Shebang? Grammar+|Script|Module) EOF
Grammar ::= Statement
/* Expressions */
IdentifierReference ::= Identifier | /* [~Yield] */ "yield"
BindingIdentifier ::= Identifier | /* [~Yield] */ "yield"
LabelIdentifier ::= Identifier | /* [~Yield] */ "yield"
Identifier ::= /* IdentifierName but not ReservedWord */ IdentifierName
@ryanjdew
ryanjdew / full-marklogic-ikm-export.xml
Last active August 18, 2016 20:30
ODI Jython ML call
<?xml version="1.0" encoding="ISO-8859-1"?>
<SunopsisExport>
<Admin RepositoryVersion="05.02.02.04" IsLegacyIdCompatible="false" />
<Encryption algorithm="AES" keyLength="128" exportKeyHash="w8MQnwAtjLTLZbjtHP3JO36rrz+IgVYbr7AcR8Sp9aM=" keyVect="4EpM8hmiUAzuarPMEHMUgw==" exportKeySalt="9930fb83-6422-4a5a-88ea-4071ee6efb22" containsCipherText="false"/>
<Object class="com.sunopsis.dwg.dbobj.SnpTrt">
<Field name="CleanupOnError" type="java.lang.String">null</Field>
<Field name="CompType" type="java.lang.String"><![CDATA[DATASTORE]]></Field>
<Field name="DelegateClass" type="java.lang.String">null</Field>
<Field name="DelegateScript" type="java.lang.String">null</Field>
<Field name="ExpectedAstClass" type="java.lang.String">null</Field>
@ryanjdew
ryanjdew / gulpfile.js
Last active August 29, 2015 14:22
Example using MarkLogic Node API to deploy code with gulp task
/*jshint node: true */
'use strict';
var gulp = require('gulp');
var config = require('konphyg')(__dirname+'/config');
var appConfig = config('app');
var marklogic = require('marklogic');
var qb = marklogic.queryBuilder;
@ryanjdew
ryanjdew / finish-ml-udf.cpp
Created May 25, 2014 12:49
C++ finish MarkLogic UDF function
template<class T>
void Bucketeer<T>::
finish(OutputSequence& os, Reporter& reporter)
{
// start the MarkLogic map
os.startMap();
// interate over the unique keys
// note the use of buckets.upper_bound() to ensure we get a key only once
for (typename std::multimap<String, T>::iterator it = buckets.begin(); it != buckets.end(); it = buckets.upper_bound(it->first)) {
std::pair <typename std::multimap<String,T>::iterator, typename std::multimap<String,T>::iterator> ret;
@ryanjdew
ryanjdew / encode-decode-ml-udf.cpp
Created May 25, 2014 12:47
C++ encode/decode MarkLogic UDF functions
/*
* Encode the map in a flattened state.
*/
template<class T>
void Bucketeer<T>::
encode(Encoder& e, Reporter& reporter)
{
std::map<String, int> keys_w_count;
int key_count = 0;
// determine key count and collect unique keys
@ryanjdew
ryanjdew / reduce-ml-udf.cpp
Created May 25, 2014 12:44
C++ reduce MarkLogic UDF function
template<class T>
void Bucketeer<T>::
reduce(const AggregateUDF* _o, Reporter& reporter)
{
/* Merge matches found */
const Bucketeer<T> *o = (const Bucketeer<T>*)_o;
typename std::multimap<String, T> o_buckets = o->buckets;
for (typename std::multimap<String, T>::iterator it = o_buckets.begin(); it != o_buckets.end(); it++) {
buckets.insert(typename std::pair <String, T> (it->first, it->second));
}
@ryanjdew
ryanjdew / map-ml-udf.cpp
Created May 25, 2014 12:41
C++ map MarkLogic UDF function
void BucketeerRegex::
map(TupleIterator& values, Reporter& reporter)
{
int reti = 0;
for(; !values.done(); values.next()) {
if(!values.null(0)) {
String cur;
values.value(0,cur);
/* Execute regular expression */
regmatch_t pmatch[1];
@ryanjdew
ryanjdew / start-ml-udf.cpp
Created May 25, 2014 12:39
C++ start MarkLogic UDF function
void BucketeerRegex::
start(Sequence& arg, Reporter& reporter)
{
overflow_bucket = "bucketeer:overflow";
case_insensitive = false;
capture_overflow = false;
int reti;
int case_sensitive = 0;
int extended = 0;
arg.value(regex);
@ryanjdew
ryanjdew / mem-op-functional-example.xqy
Last active October 19, 2018 16:25
Example functional way of using my memory operations library
xquery version "1.0-ml";
import module namespace mem = "http://maxdewpoint.blogspot.com/memory-operations" at "/memory-operations.xqy";
import module namespace mem-fun = "http://maxdewpoint.blogspot.com/memory-operations/functional" at "/memory-operations-functional.xqy";
declare variable $test-xml := <html>
<head>
<title>This is a title</title>
</head>
<!-- old comment -->
<body>