org.apache.commons.jexl2.JexlArithmetic: bitwiseXor in JEXL sandbox - jexl

I'm working in a native JEXL sandbox, so there is no need of
expression e = jexl.createExpression
Actually I am able to get this working:
foo = new ("org.apache.commons.jexl2.JexlArithmetic", false);
tmp = foo.multiply("123","123");
with those two lines I can access the var tmp.
Now I want to make a XOR operation like this:
tmp2 = foo.bitwiseXor("3","5");
This results in an error message as following:
org.apache.commons.jexl2.JexlException: unknown or ambiguous method
any ideas how to make this working?

found the answer by myself ;)
the method bitwiseXor is available only in JEXL version 2.1 and newer.
the version I am using in my sandbox is 2.0, which was a little bit hard to find out.
cheers

Related

"Error: Undeclared identifier" when trying to return a <Node> from a procedure

I post here a specific problem using a library (grim) in Nim, but the underlying concepts are still not super clear to me so I appreciate a solution coming with an explanation.
I would like to make a procedure returning a node. The example below is not really useful but makes the point: I want to return node but I apparently don't know what type it is.
import grim
import sequtils
proc get_a_node_with_label(graph: Graph, label: string): Node =
for node in graph.nodes:
if node.label == label:
return node
var g = newGraph("graph")
let n1 = g.addNode("n1", %(Name: "first"))
let n2 = g.addNode("n2", %(Name: "second"))
var aNode = get_a_node_with_label(g, "n2")
i get an Error: undeclared identifier: 'Node', but the type of "node" in the loop is "Node", if I echo node.type.
How should I deal with types on this occasion? What output should I declare in the procedure?
Thanks
Andrea
PS: I apologize if the question is not well asked, and I'm happy to improve it with your guidance.
You probably installed the grim library through nimble install grim. That gave you the grim-0.2.0, released early this year. The point is that Node was private in that release, so your code cannot access it.
You can opt to install the latest code, which at some point this year made Node and others public, with:
$ nimble uninstall grim
$ nimble install grim##devel
Or you can make the object public in your computer, editing (probably) ~/.nimble/pkgs/grim-0.2.0/grim/graph.nim:
30 Node = ref object
to
30 Node* = ref object
The former includes the latest code, and includes 40ish commits. On the downside, your build will be hard to reproduce, because you cannot pin the grim version.
The later should allow you to compile locally, but you will run into problems if you intend to distribute your code (i.e. forcing you or your users to patch the grim source).
You could also open an issue at the github repo, asking the author to tag a new version.
You can get objects which class is Node (aka Node objects), but you cannot write "Node" in your code, and the only way of creating a Node object is through code that has access to the Node private class (i.e. in the same file). It is usually some kind of newNode or getNode.
So you could get a Node inside your code, and pass it around, but cannot write "Node". E.g.
import grim
var g = newGraph("graph")
let n1 = g.addNode("n1", %(Name: "first"))
# This works happily
let node = g.node(n1) # This assigns a Node object to "node"
echo node # This passes the Node object to a $ proc.
# This fails to compile, albeit being functionally the same code,
# because your program doesn't know what "Node" is.
let node1: Node = g.node(n1)

Why is require-atomic-updates found here?

The help text for require-atomic-updates talks exclusively about statements that both set and consume the same variable.
I have some old† code that looks something like this (I think I've included everything that is relevant):
var someFunction = async function someFunction () {
switch(someVariable) {
case 0:
if (maybe) {
await doSomething();
}
break;
case 1:
//similar to above
}
someVariable = 0; // Error detected on this line
return
}
var someVariable = 0;
someFunction is invoked during some event processing later, while someVariable can be adjusted by multiple code paths
As far as I can tell, the line on which the error is reported is an atomic update, it doesn't read the value or set the new value based on anything else.
I can't understand why eslint thinks there is a possible race-condition here?
The code has been functional for a long time now, so I'm happy to just disable the rule on this line to stop it complaining. But I'd like to understand the reason that eslint highlighted it.
† The original code was written long ago, but has been adjusted more recently to be async
If you upgraded to eslint 6.0.1 like I just did, you're encountering a recently introduced bug.
There are several open github issues referencing this bug, but the gist of it is that require-atomic-updates is currently broken.
I recommend downgrading eslint or disabling the rule as a workaround.
Bug reports on the issue here:
https://github.com/eslint/eslint/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+require-atomic-updates

How can I override a Nix derivative without throwing `cannot coerce a set to a string`?

Or, the goal: How can I take a single package from Nix unstable in a declarative manner?
I'm new to NixOS and currently trying to install a newer version of Consul than the default 0.5.2 of my NixOS version (latest stable). I'm attempting this by overriding the derivative in my /etc/nix/configuration.nix.
I'd like to keep running stable, but I found unstable had the version of Consul that I wanted (0.7.0) already, and so I decided to use this package's attributes as a starting point to override https://github.com/NixOS/nixpkgs/blob/master/pkgs/servers/consul/default.nix
I copied it for most part into my configuration.nix, here are the relevant sections:
nixpkgs.config.packageOverrides = pkgs: rec {
consul = pkgs.lib.overrideDerivation pkgs.consul (attrs: rec {
version = "0.7.0";
name = "consul-${version}";
rev = "v${version}";
goPackagePath = "github.com/hashicorp/consul";
src = pkgs.fetchFromGitHub {
owner = "hashicorp";
repo = "consul";
inherit rev;
sha256 = "04h5y5vixjh9np9lsrk02ypbqwcq855h7l1jlnl1vmfq3sfqjds7";
};
# Keep consul.ui for backward compatability
passthru.ui = pkgs.consul-ui;
});
};
environment.systemPackages = with pkgs; [
vim
which
telnet
consul-ui
consul-alerts
consul-template
consul
];
I'm running nix-build (Nix) 1.11.2 which throws:
$ nixos-rebuild switch
building Nix...
building the system configuration...
error: cannot coerce a set to a string, at /etc/nixos/configuration.nix:19:7
(use ‘--show-trace’ to show detailed location information)
When I look at line 19 it's where name is set to "consul-${version}".
Why there is type-coercion going on here? Any tips will be greatly appreciated!
I'm also wondering if there is a better way to run just a single package in unstable, yet doing so declaratively from configuration.nix, rather than imperatively?
To add to what Rok said:
Which should point you that an error actually happens at passthru, line. If you comment it out it will probably build. I'm assuming some recursive calls are at play here and error occurs when it tries to evaluate consul/consul-ui packages.
If you're just starting out, you can safely ignore what follows and perhaps come back to it if/when you're curious about the nitty-gritty.
The problem here is that overrideDerivation is a kind of low-level approach to overriding things. Behind stdenv.mkDerivation, we have a much smaller primitive function called derivation. The derivation function takes some attributes and (more or less -- see the docs for the finer details) just passes those attributes as environment variables during the build. The stdenv.mkDerivation function, on the other hand, has a whole bunch of smarts layered on top that massages the attributes given to it before passing them onto derivation -- and in some cases, as is the case with passthru, it doesn't pass the attribute to derivation at all.
Back to overrideDerivation: it takes the final, tweaked attributes that stdenv.mkDerivation would pass to derivation, and just before that happens it allows you to override those attributes with the function you give it (e.g. that implies that, at that point, passthru has already been removed). When your function adds a passthru, that makes its way into derivation, which then wants to coerce the value of passthru into a string so it can make passthru an environment variable during the build; however, because passthru now points at a attribute-set, and such coercion isn't supported, Nix then complains.
So this sort of puts us in an odd situation. To illustrate, I'll copy the source for the consul package here:
{ stdenv, lib, buildGoPackage, consul-ui, fetchFromGitHub }:
buildGoPackage rec {
name = "consul-${version}";
version = "0.6.4";
rev = "v${version}";
goPackagePath = "github.com/hashicorp/consul";
src = fetchFromGitHub {
owner = "hashicorp";
repo = "consul";
inherit rev;
sha256 = "0p6m2rl0d30w418n4fzc4vymqs3vzfa468czmy4znkjmxdl5vp5a";
};
# Keep consul.ui for backward compatability
passthru.ui = consul-ui;
}
(Note that buildGoPackage is a wrapper around stdenv.mkDerivation.)
You might be familiar with e.g. consul.override, which allows you to supply different inputs (e.g. maybe a different version of consul-ui, or buildGoPackage), but it doesn't allow you to override things that aren't inputs (e.g. src, passthru, etc). Meanwhile, overrideDerivation allows you to modify the attrs given to derivation, but not the ones given to stdenv.mkDerivation. Ideally there would be something in-between, that would allow for manipulating the attrs given to stdenv.mkDerivation, and it so happens that there's a PR open to address this:
https://github.com/NixOS/nixpkgs/pull/18660
Welcome to Nix/NixOS :)
Whenever you need to know more about the error you can use --show-trace and that would give you more verbose error. In your case you would see something like
error: while evaluating the attribute ‘passthru’ of the derivation ‘consul-0.7.0’ at /home/rok/tmp/consul.nix:6:3:
cannot coerce a set to a string, at /home/rok/tmp/consul.nix:6:3
Which should point you that an error actually happens at passthru, line. If you comment it out it will probably build. I'm assuming some recursive calls are at play here and error occurs when it tries to evaluate consul/consul-ui packages.
As for overriding only one package from unstable channel something like this is needed
let
unstable_pkgs = import ./path/to/unstabe/nixpkgs {};
# or
# unstable_pkgs = import (pkgs.fetchFromGitHub {...}) {};
in {
...
nixpkgs.config.packageOverrides = pkgs: rec {
consul = unstable_pkgs.consul;
};
...
}
I haven't try the above, but I'm assuming it will work.

AutoMapper version 5.0.0-beta-1 - Created Mapper shows exceptions

I updated automapper package today and it got updated to 5.0.0-beta and i immediately got few build errors. Going through the latest changes in their wiki page i found that CreateMap is deprecated. So i followed their instruction and here is my code below.
The created mapper shows these exception about which i have no clue. I am not able to continue further. Should i do something extra with this new version of AutoMapper? Any help would be greatly appreciated. My POCO classes are just regular ones with int and strings.
You can just create a new Mapper instance now:
var mapper = new Mapper(config);
builder.RegisterInstance(mapper).As<IMapper>();
Or, if you prefer the old static way, just use Mapper.Initialize().

Swift 2 and Linux/OS X differences

I'm trying to port some basic app from OS X to Linux but it seems that even basic stuff is missing on Linux platform. Is there some documentation what is missing ??
Here is example:
exmcast.swift:7:20: error: value of type 'String' has no member 'stringByReplacingOccurrencesOfString'
let name: String = address.stringByReplacingOccurrencesOfString(".", withString: "_")
This simple code works on OS X. On Linux - you see results.
It's very hard to port anything when there is no basic info what is missing.
And it looks like even basic stuff is missing..
Swift 3 will be released in fall 2016.
The recently open-sourced Swift and the Linux port are work in progress:
The port is still a work in progress but we’re happy to say that it is usable today for experimentation.
You can go to Swift.org and github.com/apple and enjoy the fantastic work.
When you find something not yet implemented, you can file a bug and/or help implement the feature.
New versions of the open source Swift will be posted regularly on Swift.org.
The method you are trying to call is actually part of NSString. String is bridged behind the scenes to NSString and that is why you are able to use that method on OS X. NSString is part of the Foundation framework, and Foundation is not totally implemented for Linux. You can check the status of the various parts of Foundation here: Foundation Status. NSString is currently only partially implemented.
On OSX you still need to import Foundation
You are free to use pure Swift solution, in your case
let str = "alfa.beta"
// (1)
let str1 = str.characters.map {
$0 == "." ? "_": $0
}.reduce("") { (str, c) -> String in
str + String(c)
}
// (2)
let str2 = String(str.characters.split(".").joinWithSeparator(["_"]))
print(str,str1,str2) // alfa.beta alfa_beta alfa_beta
for something more advanced, you have powerful functions
mutating func replaceRange<C : CollectionType where C.Generator.Element == Character>(subRange: Range<Index>, with newElements: C)
or
mutating func replaceRange(subRange: Range<Index>, with newElements: String)

Resources