Skip to content

Instantly share code, notes, and snippets.

View dmcassel's full-sized avatar

David Cassel dmcassel

View GitHub Profile
{
"hop": {
"type": "Perle (DE)",
"uri": "/hop/perle-de.json",
"use": "boil",
"time": {
"units": "min",
"amount": 60
},
"aau": 4.5
cts:search(fn:doc(), cts:and-query((
cts:period-range-query(
"valid",
"ALN_CONTAINED_BY",
cts:period(xs:dateTime("2015-01-09T00:00:00"),
xs:dateTime("2015-01-11T23:59:59.99Z"))),
cts:period-range-query(
"system",
"ALN_CONTAINED_BY",
cts:period(xs:dateTime("2015-01-13T13:00:00"),
@dmcassel
dmcassel / Contributor.json
Last active October 14, 2015 00:47
MarkLogic 8 for Node.js Developers
{
"com.marklogic.samplestack.domain.Contributor": {
"aboutMe": "Twitter: [@maryadmin](http://twitter.com/maryadmin) Disclaimer: This is not me. MaryAdmin _doesn't exist_!",
"displayName": "MaryAdmin",
"id": "9611450a-0663-45a5-8a08-f1c71320475e",
"location": "Barrow",
"originalId": null,
"reputation": 100,
"userName": "mary@example.com",
"voteCount": 5,
@dmcassel
dmcassel / configure-db.sh
Last active September 23, 2015 20:16
REST API Setup steps
curl -v -X PUT --anyauth -u admin:admin \
--header "Content-Type:application/json" \
-d '{"collection-lexicon":true}' \
http://localhost:8002/manage/v2/databases/TutorialDB/properties
@dmcassel
dmcassel / ex01.sh
Last active September 23, 2015 13:29 — forked from evanlenz/ex01.sh
Code samples for MarkLogic REST API
curl -X GET \
--anyauth --user rest-writer:x \
'http://localhost:8011/v1/search?q=chicken&format=json'
xdmp.setResponseContentType("application/json");
switch(xdmp.getRequestMethod()) {
case "GET":
// Get the criterion out of the URL query string
var q = cts.wordQuery(xdmp.getRequestField("q"));
// Unwind the iterator into an Array
var results = cts.search(q).toArray();
xdmp.addResponseHeader("X-Result-Count", results.length + "");
// Serialize the JavaScript results object as JSON
(:
: Evaluate JavaScript from XQuery, passing in external variables and returning
: results as XQuery types.
:)
xdmp:javascript-eval(
"var result = []; for(var p in param) {result.push(p); result.push(param[p]);} result;",
(xs:QName("param"), object-node { "a": "A", "b": "B"})
)
/*
* Access the values from a range index.
* (Note: This assumes you've created the path range index on the
* balance.value field in "Import XQuery")
*/
cts.values(
// Any reference to a range index
cts.pathReference("balance/value")
)
/*
* Demonstrate an object-oriented style of programming. Declare a Person type
* and instantiate an instance. Convert that instance into a JSON node, for
* example to persist it to the database, and convert it back.
*/
// The Person constructor, e.g. var p = new Person(…)
Person = function(fname, lname) {
if (fname) this.fname = fname;
if (lname) this.lname = lname;
[
{
"guid": "986af6e1-e0f1-450f-b1f0-2eff54357840",
"about": [
"Skateboard pop-up kogi, ethnic Vice disrupt Truffaut twee fashion axe forage occupy biodiesel. Bespoke umami yr, ",
{
"match": "flannel"
},
" kogi XOXO bitters butcher ugh DIY lomo. Flexitarian distillery ",
{