Share your WarpScript macros

share your WarpScript macros

A short article to remind everyone how simple macro sharing is between WarpScript developers!

No package, no publication process!

Remember that a macro is a succession of WarpScript statements enclosed with the marks <% and %>. It is the equivalent of a function in another language.

WarpScript resolver

This feature appeared in Warp 10™ release 2.0.3.

Open your /etc/conf.d/20-warpfleet.conf:

// Comma separated list of default WarpFleet™ repositories
warpfleet.macros.repos = https://warpfleet.senx.io/macros

By default, the only public macro repo is the SenX one. The list of all available macros on this repo is not disclosed, but we do communicate on interesting ones. You can already access them from any up-to-date Warp 10 instance in the world.

For example, you can generate random numbers with a gaussian distribution with this macro:

// // generate 10 random numbers, gaussian distribution 10 @senx/rand/RANDNORMAL

An example

Today, I want to share with you a very simple dataviz macro: juxtaposeGTS. Imagine you want to focus on very short and scarce events. For example, on thousands of race car acquisitions, you only want to view >7200rpm sequences. 65 points selected in 26 million...

[ $READTOKEN '~.*enginerpm' { } NOW -100000000 ] FETCH 'AllRpm_gtsList' STORE [ AllRpm_gtsList 7200.0 mapper.gt 0 0 0 ] MAP
Not really readable

There are very few events that last a few seconds, on several years. That's really a pain to zoom on each one. I want to shift every GTS close to the previous one, to juxtapose them. The solution is a simple WarpScript that will take the GTS list on top of the stack:

0 'firstTick' STORE <% DROP DUP FIRSTTICK -1 * $firstTick + TIMESHIFT //shift //current lasttick will be the next one first tick DUP LASTTICK 'firstTick' STORE %> LMAP
Readable davaviz, no need to zoom in anymore

Share it!

First, wrap your code in a typical macro, with documentation inside. This is not mandatory but will be convenient for online help later. To get an empty documented macro skeleton, just type "macro" in VSCode.

Then, upload your macro to a GitHub repo, or anything that could be used as a static web server. I uploaded my macro here: https://github.com/pi-r-p/warpscript. The path is viz/juxtaposeGTS.mc2. So, for master branch, the raw path is: https://raw.githubusercontent.com/pi-r-p/warpscript/master/viz/juxtaposeGTS.mc2

Import macros (first method)

You manage your Warp 10 instance, or the sysadmin is your friend... Just edit your configuration /etc/conf.d/20-warpfleet.conf, and add your master branch to the repo:

// Comma separated list of default WarpFleet™ repositories
 warpfleet.macros.repos = https://warpfleet.senx.io/macros, https://raw.githubusercontent.com/pi-r-p/warpscript/master

You're done. Check with WF.GETREPOS that you have now two repositories. You can now call @viz/juxtaposeGTS in any WarpScript on your instance.

Import macros (second method)

You do not manage the Warp 10 instance, you already asked 10 times to your sysadmin to add 10 repositories... You can import repositories from within WarpScript with WF.ADDREPO function. But this is forbidden by default in Warp 10 configuration (always remember that Warp 10 is secure BY DEFAULT)

First, you need to define a local macro in your macro to allow some URL or some URL patterns. If you want to allow anything, create a new macro (for example /macros/admin/allowRemoteRepos.mc2) with this content:

// combined with other wildcard settings, 
// that is a security risk…
<% DROP true %>

If you didn't explicitly allow WEBCALL or REXEC to any domain, there are few security risks, the main one being that your Warp 10 instance could be used for a DoS attack. If you allow WEBCALL or REXEC to any domain, beware that some external macros could try to steal secrets from your script and export them somewhere.

Then, kindly ask your sysadmin for a last change... Edit your configuration /etc/conf.d/20-warpfleet.conf, and set warpfleet.macros.validator with your local macro name.

# Name of WarpFleet repository macro. This macro consumes a URL and emits a boolean.
warpfleet.macros.validator = admin/allowRemoteRepos

Restart your Warp 10, and try to import a new repo:

// @endpoint https://sandbox.senx.io/api/v0/exec // on the sandbox, raw.githubusercontent.com urls are allowed 🙂 'https://raw.githubusercontent.com/pi-r-p/warpscript/master' WF.ADDREPO WF.GETREPOS // check... [] @viz/juxtaposeGTS

Import macros (third method)

You work in a big company. You don't even know the sysadmin. You checked with WF.GETREPOS, Warpfleet SenX repository is here...

Your company has a support contract with SenX... Make sure you didn't put any secrets into the macro and just ask us to host your macros.

Import macros (winner method)

You work in a big company. You don't even know the sysadmin. You checked with WF.GETREPOS, Warpfleet SenX repository is here...

Your company hasn't any support contract with SenX… BUT YOUR MACRO IS GREAT. Really great. Just ask us to host it on WarpFleet. It will be reviewed by the greatest WarpScript experts... We will publish it and send you goodies if really exceptional.

Conclusion

Sharing a WarpScript macros is easy. Since Warp10 2.0.3, importing it from any Warp 10 instance is easy too!

Share