Maybe is a stupid question but I failed to retrieve information from Google.
As the title say, I get a stack trace if a try to parse this simple line:
<span th:if="${1 < 0}">
The error is:
org.xml.sax.SAXParseException; lineNumber: 14; columnNumber: 43; The value of attribute "th:if" associated with an element type "null" must not contain the '<' character.
But if i try this:
<span th:if="${0 > 1}">
Everything is fine, my question is: Why I get this error?
I believe is related to my lack of experience with Java and thymeleaf, but I don't get why by just changing the position of the elements it work as I expect (return always false).
It is a bug in the parsing of the expression (as checking if 1 is lower than 0 is forbidden by some parser rule) or is just a weird XML parsing issue?
Thank you to all who will even just read.
You have to escape the symbol by using
< for <
> for >
≤ for <=
≥ for >=
So your code should look like :
<span th:if="${1 < 0}">
You can find the whole doc about this in the 'Using Thymeleaf' tutorial on their website, in the comparators-and-equality section.
≤ for <=
≥ for >=
didn't work for me. I had to use:
<= for <=
>= for >=
It seems that ≤ and ≥ are not accepted as well-formed XML.
This solves the "IllegalStateException: Cannot handle (8804) '≤' " problem.
I have come with same problem, but shows different exception and my code is here:
<div class="text-center m-1" th:if="${totalCount} > 0">
<span> Showing user # [[${startCount}]] to [[${endCount}]] of [[${totalCount}]] </span>
</div>
Here is my stack trace:
Caused by: org.attoparser.ParseException: Cannot execute GREATER THAN comparison: operands are "null" and "0"
So, I have changed to:
<div class="text-center m-1" th:if="${totalCount} != 0">
<span> Showing user # [[${startCount}]] to [[${endCount}]] of [[${totalCount}]] </span>
</div>
It works.
Related
I am using Flex (fast lexical analyser generator) tool. I have defined my reges as such:
value [0-9]|[1-9][0-9]*
id [a-zA-Z][a-zA-Z0-9]*
plus "+"
...
I have a few more keywords and operators defined like those. Here is one sample output that helps you understand my problem:
> 123
VALUE: 123 (123)
> name
IDENTIFIER: name
> 1230
VALUE: 1230 (1230)
> 0123
VALUE: 0 (0)
VALUE: 123 (123)
> 123x
VALUE: 123 (123)
IDENTIFIER: x
> x+
IDENTIFIER: x
OP_PLUS: +
As long as it fits a token to a proper class, it finishes and goes to the start state int the DFA again. Doing it just as it should. But I don't know how to handle this in Flex.
And I believe numbers with leading zeros regex working just fine, yet it crashes because of the same reason. A proper output I am waiting for:
> (+ x 3)
OPEN_P: (
PLUS: +
IDENTIFIER: x
VALUE: 3 (3)
CLOSE_P: )
> 0123
SYNTAX ERROR
> 123X
SYNTAX ERROR
> 123+
SYNTAX ERROR
I don't want this sequence 123x to be shown as like this:
VALUE: 123
ID: x
Instead I want to get a syntax error. Because 123x is not a valid sequence for me. or 0123, or 123+ etc.
I ran into a weird problem in Dafny. I tried to extract it as much as possible here: https://rise4fun.com/Dafny/F7sK
The thing is, after the modification of truthAssignment, stack.valid fails even if stack.valid doesn't know about truthAssignment.
assert stack.valid();
truthAssignment[variable] := 1;
assert stack.valid(); // assertion violation
The reason Dafny fails to verify the assertion assert stack.valid(); is the last conjunct in the body of valid():
(forall c :: c in contents ==>
exists i,j :: 0 <= i < stack.Length
&& 0 <= j < |stack[i]|
&& stack[i][j] == c)
It has the form forall ... exists ..., and proving such a condition to be invariant is difficult for the verifier. Once you have figured out that this is the part of valid() that the verifier cannot prove (which you can do by, for example, manually inlining the definition of valid() in place of your assertion), then the solution is to give the verifier some assistance.
When the verifier--or a human, for that matter--tries to prove something for the form forall c :: P(c), then it makes up an arbitrary c and then tries to prove the "P(c)" for it. (Logicians call this rule "universal introduction".) Easy. Then, to prove something of the form exists i,j :: Q(i,j), the verifier looks for a witness to the "Q(i,j)". (This is known as "existential introduction".) Here, the verifier is not particularly creative and often needs help. Sometimes, you have to figure out some i and j yourself and then assert Q(i,j). Other times, it suffices to just mention some component of the needed Q(i,j) and the verifier will then figure out the rest. Exactly what to do can be a trial-and-error process.
What makes James's remedy above work is the fact that it mentions stack.stack[..] after the update truthAssignment[variable] := 1;. This tickles the verifier in a way that lets it see the light. Just writing the trivially proved assertion:
assert 0 <= |stack.stack[..]|; // mentioning stack.stack[..] helps the verifier in the next line
after the update also works in this case.
Rustan
The following verifies for me:
assert stack.valid();
ghost var old_stack := stack.stack[..];
truthAssignment[variable] := 1;
assert stack.stack[..] == old_stack;
assert stack.valid();
I don't really understand why this works, but it falls under the general category of "extentional equality for sequences is hard for Dafny".
I am trying to solve a HackerEarth problem using Ruby
The problem is provided in the following link:
https://www.hackerearth.com/problem/algorithm/find-product/
My solution for the problem is here :
n = gets.chomp.to_i
a = Array.new
if n <= 1000
n.times do
a << gets.chomp.to_i
end
end
a.each { |m| print m.to_s + " " }
print "\n"
answer = 1
a.each do |m|
answer = ( answer * m ) % ( (10**9) + 7)
end
puts "#{answer}"
The code throws a Runtime Non zero exit code (NZEC).I am not able to understand the concept of NZEC and what particulary wrong I am doing in this code. Can someone pls help me to understand NZEC and find a work around for it.
The NZEC error appears because, you read the problem a bit quickly.
The first line must contain a single integer n, and the second line must contain each element separated by a space.
When I launch your script, it seems I need to press enter between each entry of the array. so when you test your code in hackerhearth I presume that execution failed because it receives no response after the second entry.
There is also a similar problem with your output, you print the full array before display the answer. The problem definition specifies you have to only display the answer.
One possible solution could be the following:
n = gets.chomp.to_i
a = gets.chomp.split.map(&:to_i)
answer = 1
a.each do |m|
answer = ( answer * m ) % ( (10**9) + 7)
end
puts "#{answer}"
I'm trying to make a formula in my project.rb model in my rails 4 app.
I have an attribute in an preference table, called delay. I want to calculate whether the tolerance on one user's part, is close to the delay required by another user.
In my project.rb, I've tried to do this as follows:
def publication_delay_variance
if #current_user.profile.organisation.preference.delay >= #project.profile.organisation.preference.delay
'No problems here'
elsif #current_user.profile.organisation.preference.delay * 90% >= #project.profile.organisation.preference.delay
"Close, but not quite there"
else #current_user.profile.organisation.preference.delay * 50% >= #project.profile.organisation.preference.delay
"We're not in alignment here"
end
end
the current user is the current user who is currently logged in and interacting with the page. The other user is the user who created the project. Each user has an organisation. Each organisation has preferences. I'm trying to compare them.
Can anyone see what I'm doing wrong? I don't have much experience with this. My current attempt generates this error:
syntax error, unexpected >=
...ence.publication_delay * 90% >= #project.profile.organisatio...
..
The problem is that 90% isn't valid in Ruby. You probably meant to use 0.9 instead. Also, your last else should be an elsif:
def publication_delay_variance
if #current_user.profile.organisation.preference.delay >= #project.profile.organisation.preference.delay
'No problems here'
elsif #current_user.profile.organisation.preference.delay * 0.9 >= #project.profile.organisation.preference.delay
"Close, but not quite there"
elsif #current_user.profile.organisation.preference.delay * 0.5 >= #project.profile.organisation.preference.delay
"We're not in alignment here"
end
end
Of course, without an else you don't have a default case, so you should consider what behavior you want if none of those three conditions is true.
P.S. You can make this a lot more readable by assigning those values to local variables with shorter names:
def publication_delay_variance
user_delay = #current_user.profile.organisation.preference.delay
project_delay = #project.profile.organisation.preference.delay
if user_delay >= project_delay
"No problems here"
elsif user_delay * 0.9 >= project_delay
"Close, but not quite there"
elsif user_delay * 0.5 >= project_delay
"We're not in alignment here"
end
end
P.P.S. 0.9 and 0.5 are magic numbers. Consider moving their values into constants.
In Ruby, % is the modulus operator, which takes two arguments x % y and returns the remainder of x / y. It doesn't make sense to have >= immediately after it, which is what the error message is telling you. To represent a percentage in Ruby, use a decimal number, eg 0.9.
So I am Having some problems when applying Luhn algorithm
Here are the general rules: http://www.codeproject.com/Tips/515367/Validate-credit-card-number-with-Mod-algorithm
and here is my code
def luhn(credit_card)
result = 0
nums = credit_card.split("")
nums.each_with_index do |item, index|
if index.even?
if item.to_i*2>9
result+= item.to_i*2-9
else
result+= item.to_i*2
end
else
result +=item.to_i
end
end
if (result % 10) == 0
self.validation = "valid"
else
self.validation = "invalid"
end
end
It works on the majority of cards
VISA: 4111111111111111 (valid)
VISA: 4111111111111 (invalid)
VISA: 4012888888881881 (valid)
Discover: 6011111111111117 (valid)
MasterCard: 5105105105105100 (valid)
MasterCard: 5105105105105106 (invalid)
Unknown: 9111111111111111 (invalid)
But when it comes to this one
AMEX: 37828224631000(invalid)
For some reason my code says its not valid,but it should be according to the official testing card list.
I have seen a bunch of other codes that are working but I want to correct the mistake and understand my mistake. I will appreciate some explanation why is it working like this.
Are you sure that your Amex number should be valid?
Can you edit your question to show us where you're getting your testing numbers?
Here's what I see in other Lunh test suites:
"378282246310005" should be true
"37828224631000" should be false
Also, here are items for you to look at:
Your code is moving through the numbers the wrong way: you're moving left-to-right, whereas Lunh is right-to-left.
Your code iterating on the check digit, whereas Lunh doesn't iterate on the check digit.
Try peeling off the check digit before you loop, and reversing your order, such as:
def luhn(credit_card)
(*digits, checksum_digit) = s.split('').map(&:to_i)
result = 0
digits.reverse.each_with_index do |item, index|
…
After you calculate the sum, then add the checksum digit, then compare % 10.