Skip to content

Instantly share code, notes, and snippets.

View Shelrothman's full-sized avatar
:octocat:
coding

Shelby Rothman Shelrothman

:octocat:
coding
View GitHub Profile
@fauxneticien
fauxneticien / _all-in-one_reprex.R
Last active March 30, 2022 16:56
String parsing using Nearley within R
library(tidyverse)
library(zoo)
library(V8)
lexicon <-
'\\lx rouge
\\ps adjective
\\de red
\\xv La chaise est rouge
\\xe The chair is red
Postman is an exceptionally useful tool for testing ReST apis.
The following is an example of how to use the xml2Json method in a test if you are getting back xml and want to test elements in the response. The reason that I am posting this is that I could not get xml2Json to work until I discovered (using the new console in Version 4.7.2) that I needed the include the .$. in the object reference.
So that this is completely self contained all this is doing is setting an env var with an xml string, getting that
var, converting it to json and then evaluating the content.
postman.setEnvironmentVariable("testresponse", "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><myResponse isError=\"false\"/>");
var xmlresponse = postman.getEnvironmentVariable("testresponse");
@iwek
iwek / find-in-json.js
Created October 20, 2012 21:43
Searching through JSON
//return an array of objects according to key, value, or key and value matching
function getObjects(obj, key, val) {
var objects = [];
for (var i in obj) {
if (!obj.hasOwnProperty(i)) continue;
if (typeof obj[i] == 'object') {
objects = objects.concat(getObjects(obj[i], key, val));
} else
//if key matches and value matches or if key matches and value is not passed (eliminating the case where key matches but passed value does not)
if (i == key && obj[i] == val || i == key && val == '') { //