Skip to content

Instantly share code, notes, and snippets.

Avatar

David Cassel dmcassel

View GitHub Profile
View perle-hop.json
{
"hop": {
"type": "Perle (DE)",
"uri": "/hop/perle-de.json",
"use": "boil",
"time": {
"units": "min",
"amount": 60
},
"aau": 4.5
View bitemp-query.xquery
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 Oct 14, 2015
MarkLogic 8 for Node.js Developers
View Contributor.json
{
"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 Sep 23, 2015
REST API Setup steps
View configure-db.sh
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 Sep 23, 2015 — forked from evanlenz/ex01.sh
Code samples for MarkLogic REST API
View ex01.sh
curl -X GET \
--anyauth --user rest-writer:x \
'http://localhost:8011/v1/search?q=chicken&format=json'
View sjs-tutorial-http.sjs
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
View sjs-tutorial-js-eval.sjs
(:
: 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"})
)
View sjs-tutorial-values.sjs
/*
* 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")
)
View sjs-tutorial-oop.sjs
/*
* 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;
View sjs-tutorial-markup-results.sjs
[
{
"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 ",
{