Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I don't know why whenever I run this code in CMD ,I got this error:
Syntax error, unexpected =>
Here's my code:
hash_brown = (
"topping_1" => "Sour Cream",
"topping_2" => "Butter",
"topping_3" => "Salt",
"topping_4" => "Ketchup"
)
puts hash_brown["topping_2"]
first_hash = Hash.new
first_hash["first_name"] = "Jacob"
first_hash["nick_name"] = "Day"
first_hash["last_name"] = "Williams"
puts first_hash["first_hash"]
$end
Please let me know what is wrong with it cause I have checked it thousands of times & didn't found anything!
You should use curly braces ({}) to define Hash objects:
hash_brown = {
"topping_1" => "Sour Cream",
"topping_2" => "Butter",
"topping_3" => "Salt",
"topping_4" => "Ketchup"
}
Related
Can someone explain what I'm doing wrong!?
if response[:result]
response[:credentials].each do |cred|
AntHQ.logger.debug "==> #{cred}"
c = app_instance.credentials.find_by(name: cred[:name])
if c && cred[:value]
c.value = cred[:value]
c.expiry = cred[:expiry]
c.save!
end
end
end
Error
TypeError: no implicit conversion of Symbol into Integer
File "/usr/local/lib/ruby/gems/2.1.0/bundler/gems/ant_light_tasks-01095a3ea065/lib/ant_light_tasks/app/update_credentials.rb" line 16 in []
Line 16:
c.value = cred[:value]
Example "response":
{:result=>true, :credentials=>[{:name=>"access_token", :value=>"...", :expiry=>"..."}]}
Hi guys I appreciate your answers.
The real cause was because our jenkins agent wasn't deploying the code to all our instances.
This question already has answers here:
chai test array equality doesn't work as expected
(7 answers)
Closed 6 years ago.
it('GET /customers/ with wrong id', (done) => {
request
.get(`/customers/${wrongId}`)
.end((err, res) => {
expect(res.body).to.equals({});
expect(res).to.have.status(404);
done();
});
});
1) Customers CRUD GET /customers/ with wrong id:
Uncaught AssertionError: expected {} to equal {}
+ expected - actual
You want to use deep if you're trying to compare objects:
expect(res.body).to.deep.equal({});
Or use the eql method:
expect(res.body).to.eql({});
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I faced with strange problem with sorting Files.
Given env
Dev: Mac OS X 10.11.3 OracleJDK 1.8.0_45
PreProduction env: FreeBSD 10 OpenJDK 1.8.0_72
Code
public static String getLatestTag() {
File tagsDir = new File("./.git/refs/tags");
...
File[] tags = tagsDir.listFiles();
List<File> tagsList = Arrays.asList(tags);
Collections.sort(tagsList, (f1, f2) -> {
if(f1.lastModified() > f1.lastModified()) {
return 1;
} else if(f1.lastModified() == f2.lastModified()) {
return 0;
} else {
return -1;
}
});
logTagsList(tagsList);
String latestTag = tagsList.get(0).getName();
Logger.info("Application version is: %s", latestTag.replaceAll("[^\\d.]", ""));
return latestTag;
}
private static void logTagsList(List<File> tags) {
if(Logger.isDebugEnabled()) {
Logger.debug("Tags found");
for(File tag : tags) {
Logger.debug("Tag: %s, Date modified: %s", tag.getName(), tag.lastModified());
}
}
}
Gives an output
At Mac:
17:49:50,601 DEBUG ~ Tags found
17:49:50,602 DEBUG ~ Tag: v0.97, Date modified: 1457277455000
17:49:50,602 DEBUG ~ Tag: v0.95, Date modified: 1455809758000
17:49:50,602 INFO ~ Application version is: 0.97
At FreeBSD:
18:52:49,902 DEBUG ~ Tags found
18:52:49,903 DEBUG ~ Tag: v0.95, Date modified: 1456038720000
18:52:49,903 DEBUG ~ Tag: v0.97, Date modified: 1457277515000
18:52:49,904 INFO ~ Application version is: 0.95
In both cases user who is running an application has read access to .git directory.
Steps to reproduce:
1) git init
2) bootstrap java application (or play framework 1.4 application for complete reproduce)
3) add given code
4) make 2 commits to git
5) label those commits
6) run application
7) examine logs
You got an error in your comparison: if(f1.lastModified() > f1.lastModified()) - you are comparing f1 with f1 here. And if both files are not modified at the same time, you are always returning -1, no matter what you compare. And this leads to unpredictable behaviour.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I'm looking at various aspects of Java SE 8. I've encountered a number of situations where compilable code leads to runtime exceptions or apparent inconsistencies. Here is one, where a construct operates as expected in one context, but appears to fail in another. Is it a bug or am I missing something?
import java.util.stream.IntStream;
import java.util.stream.LongStream;
import java.util.stream.DoubleStream;
import static java.lang.System.*;
public class Stream06 {
public static void main(String[] args) {
out.println(IntStream.rangeClosed(2,5)
.reduce((i,j)->i+j).getAsInt()); // OK
out.println(IntStream.rangeClosed(2,5)
.reduce(0,(i,j)->i+j)); // OK
out.println(IntStream.rangeClosed(2,5)
.reduce((i,j)->i*j).getAsInt()); // OK!
out.println(IntStream.rangeClosed(2,5)
.reduce(0,(i,j)->i*j)); // zero!!!
out.println();
out.println(LongStream.rangeClosed(2,5)
.reduce((l,m)->l+m).getAsLong()); // OK
out.println(LongStream.rangeClosed(2,5)
.reduce(0,(l,m)->l+m)); // OK
out.println(LongStream.rangeClosed(2,5)
.reduce((l,m)->l*m).getAsLong()); // OK!
out.println(LongStream.rangeClosed(2,5)
.reduce(0,(l,m)->l*m)); // zero!!!
out.println();
out.println(DoubleStream.of(2.5, 1.3, 6.8)
.reduce((d,e)->d+e).getAsDouble()); // OK
out.println(DoubleStream.of(2.5, 1.3, 6.8)
.reduce(0,(d,e)->d+e)); // OK
out.println(DoubleStream.of(2.5, 1.3, 6.8)
.reduce((d,e)->d*e).getAsDouble()); // OK (usual rounding issue)
out.println(DoubleStream.of(2.5, 1.3, 6.8)
.reduce(0,(d,e)->d*e)); // zero!!!
}
}
reduce i*j starting from zero leads to zero... well, that's quite expected :-)
This has completely baffled me on a number of configurations. I keep reading the documentation, and I just don't get it. Here is my registration code:
ForRequestedType<SimpleWorkItemProcessor>().TheDefault.Is.OfConcreteType<SimpleWorkItemProcessor>();
ForRequestedType<WorkItemRetryProcessor>().TheDefault.Is.OfConcreteType<WorkItemRetryProcessor>()
.CtorDependency<IWorkItemProcessor>().Is(x => x.OfConcreteType<SimpleWorkItemProcessor>())
.WithCtorArg("busyDelay").EqualTo(TimeSpan.FromMilliseconds(20))
.WithCtorArg("overallTimeout").EqualTo(TimeSpan.FromSeconds(60));
ForRequestedType<WorkItemQueue>().TheDefault.Is.OfConcreteType<WorkItemQueue>()
.CtorDependency<IWorkItemProcessor>().Is(x => x.OfConcreteType<WorkItemRetryProcessor>());
As it is, it says there's no default instance for IWorkItemProcessor (which is correct). Switching the last line to this:
ForRequestedType<IWorkItemProcessor>().TheDefault.Is.OfConcreteType<WorkItemQueue>()
.CtorDependency<IWorkItemProcessor>().Is(x => x.OfConcreteType<WorkItemRetryProcessor>());
...Makes a stack overflow exception.
How do you chain classes together that both implement an interface, and take in that same interface in their constructor?
This works, but I can't explain why. From what I know, the first version should work just as well.
ForRequestedType<SimpleWorkItemProcessor>().TheDefault.Is.OfConcreteType<SimpleWorkItemProcessor>();
var retryProcessor = ForRequestedType<WorkItemRetryProcessor>().TheDefault.Is.OfConcreteType<WorkItemRetryProcessor>()
.CtorDependency<IWorkItemProcessor>().Is(x => x.OfConcreteType<SimpleWorkItemProcessor>())
.CtorDependency<TimeSpan>("busyDelay").Is(x => x.Object(TimeSpan.FromMilliseconds(20)))
.CtorDependency<TimeSpan>("overallTimeout").Is(x => x.Object(TimeSpan.FromSeconds(60)));
ForRequestedType<IWorkItemProcessor>().TheDefault.Is.OfConcreteType<WorkItemQueue>()
.CtorDependency<IWorkItemProcessor>("workItemProcessor").Is(x => x.Instance(retryProcessor));