How can I create a Regex filter in Slate Platform Editor? - palantir-foundry

I’m using Slate Platform Editor and I would like to create an object set with a filter using a Regular Expression (Regex). How can I do that?

As you may have noticed, the Platform tab's Object Set panel is ideal for simple filtering:
Or for using multi-term filters and wildcard filters:
To perform more advanced search with Regular Expression, you will have to use the Platform tab's Foundry functions panel and create a specific function for your filtered object set:
Please find here an example with an input being a Regex to illustrate how you can proceed (you can also remove the input and specify the Regex directly in the function):

Related

How can I add a namespace when I use XPath using $x function in Google Chrome?

I usually use $x() function on Google Chrome development console. However, when XML file has a namespace the query does not work. I could not find any way to add the namespace. I was wondering if I am missing something or is a missing feature.
I don't know if there is a way to include namespaces in the function, but it's possible to (try to) avoid them altogether by using local-name().
For example, if your element is (picked randomly for an EDGAR filing):
<edgar:companyName>Federal Bank of Boston</edgar:companyName>
This expression
$x('//*[local-name()="companyName"]')
should select it.

Is that possible to create a custom input widget in Foundry Slate?

I know how to use input widget in Slate but I have a use case where I need to create several inputs from an array. Maybe one, maybe more, let's say around 10 or 15. Is that possible to create a input and to catch the user entry just by using an HTML widget.
One other way to say shoud be: I would like to have a table of 1 to 15 rows with one column dedicated to an input area. Number of row depend of the source data, so I want that the input is created dynamically. Is it possible in foundry-slate ?
Best regards
You can't do this in a plain HTML widget - the dependency graph can't read state from arbitrary HTML input elements.
There are a couple other options here; the one that most directly works they way you would like it to in your question, would be to use the Code Sandbox widget, which effectively let's you build your own widget and wire it up to the Slate dependency graph for interaction with the rest of the app. You can use a 3rd-party library, assuming you have the license, to do something more advanced (you can search your Foundry instance for some examples in the Slate Reference Examples) or simply use HTML and Javascript to build the widget as you would in normal web development as you have access to the DOM and JQuery when working in the Sandbox.
Slightly more in-line with how Slate might expect you to build this functionality, you can use a single input widget, but toggle what you do with the associated input based on other state, for example what row the user has selected. This, in combination with a button that stores the input into a Variable with a click event, can be used to let users build up a "bag" of edits, that you can then apply with Actions (or you can apply them immediately - all depends on the workflow). You'll find some examples of that pattern in the "Events" folder in the Slate Reference Examples.
Thinking a bit more expansively, if you model your data in the ontology, you can set up an editable table pattern in Workshop and have a quite straightforward experience once you have the right Action and Object Type configuration. You'll find the documentation on this on your Foundry instance at https://www.palantir.com/docs/foundry/workshop/widgets-object-table/#inline-edits-or-cell-level-writeback and an example in the Flight Alert Inbox example application.

how to pass a gensym to a function name in common lisp

I'm using Lucerne to build an api, and experimenting with generating those apis based off of a list (they're very simple endpoints). The problem is that the views lucerne uses are just functions, so if I pass (gensym) to the macro at runtime the name of that view function is just set to (gensym) (or it fails, can't remember which).
I'd like to dynamically name a set of those view functions in a macro that will be in a loop of some kind, each time the code that macro has expanded too is run the functions have a new name (so if I just use a standard gensym each time the macro was run each of the functions would always have the same name, and overwrite each other). Is there some way to do this?
You probably want to use intern to create "public" symbols (that the users will be calling by name) and make-symbol for "private" symbols (that are stored somewhere).

Match current domain with XPath

Is it anyhow possible (with newer XPath version maybe) to get following thing working:
//a/#href[not contains("DOMAIN OF THE CURRENT PAGE")]
DOMAIN OF THE CURRENT PAGЕ should work like variable, which gets the domain - something like {HTTP_HOST}.
I want to get all external links on this way.
If the domain of the current page exists as content of the current page, then, yes, you can select it and use it in an XPath predicate. Otherwise, no, there is no standard, universal variable defined in XPath for the domain of the current page.
Any given XPath hosting language or tool may have a mechanism to provide the domain of a page. For XPath 3.0, they might leverage the standard environment variable functions, fn:environment-variable and fn:available-environment-variables.
Alternatively, you could construct the XPath dynamically within the hosting language that knows the page – see How to pass variable parameter into XPath expression?.

Best practice for writing equivalent powershell scripts and functions

I have a script that takes in multiple parameters, and that I've documented with proper help comments (e.g. .SYNOPSIS, .DESCRIPTION, .PARAMETER). Several different users in my organization are going to use this powershell script, some who know powershell and will call it from powershell with specific parameter values, and some who don't know powershell and will simply right-click on the script file in Windows Explorer and choose Run with PowerShell (so the parameters will use their default values).
My conundrum is what is the best way to do this in powershell without a bunch of duplicate code. The way I see it, these are my options:
1 - Just write a DoStuff.ps1 script that provides default values for all parameters. This allows it to be ran directly from Windows Explorer, but feels clunky for the powershell users that want to use it as a function from their own scripts, since instead of writing:
Do-Stuff param1 param1
they will be doing:
.\DoStuff.ps1 param1 param2
2 - Within DoStuff.ps1, move the operations it performs into a DoStuff function, and after the function declaration call the DoStuff function with the parameters passed into the script. This would still allow the script to be ran from Windows Explorer, as well as developers to dot source the script into their own scripts so they can access the function. The downside is that when the developers dot source the script, the script is going to call the function with the default parameters (unless I allow them to provide an optional Switch parameter to the script that triggers the function to not be called). Even with this though, it means that I would have to duplicate all of the scripts help text so that it shows for both the script and the function (description, parameter descriptions, etc.).
I can't think of any other options. Ideally I would just be able to write functions in .ps1 file and tag a function with a "default" keyword so that if the script is called, that function is ran by default; but I don't think PowerShell provides anything like this.
What do you think is the best approach in this situation. Is there something I'm overlooking or don't know about? Thanks.
but feels clunky for the powershell users that want to use it as a function from their own scripts
Default parameters would seem, based on your description, to be the best (or, at least, least-worse) approach.
But rather than naming your script DoStuff.ps1 name it and call it so it can be called more like an internal function:
Name it with the dash: Do-Stuff.ps1
Remember you don't need to specify the ps1
If the script is in a folder in $env:Path then you don't need to specify a path.
Also consider a script can load a module from a relative path: you could put most of the code in a script module which the front end (right click on it) script loads and calls into it. Script authors load the module themselves.