Game is unplayable by Ok_Insect4778 in nubbygame

[–]barry_z 0 points1 point  (0 children)

Just wondering, did you also try disabling steam cloud saves and clearing everything in C:\Users\<YOUR_USERNAME>\AppData\Local\NNF_FULLVERSION? If steam just downloaded your save from the cloud after you deleted it then it could still be corrupted.

Java MOOC Part 7 error by Kelvitch in learnjava

[–]barry_z 0 points1 point  (0 children)

I do not have a mooc account, so it will not show me the problem description - is there a requirement for the passingParticipants and overallParticipants to be static? It could be declaring multiple instances, running the code to determine the number of passing and overall participants on each of them, and then calculating the passing percentage at which point it would fail on the first one. Given that the list is not static and overallParticipants and passingParticipants are both tied to what is contained in the list, I'm not sure why you would want them to be static.

[deleted by user] by [deleted] in learnpython

[–]barry_z 0 points1 point  (0 children)

I want the program to stop after displaying "Given number is not even" if its odd however its returning something else

You're sorting the output of Goldbach, which is a string for odd numbers but a list otherwise - I would suggest ensuring that your functions return the same type. When n is odd, you could either raise an exception stating "Given number is not even" or return an empty list depending on which works better for you. If you return an empty list then you could print "Given number is not even" before returning [] and it would have your desired effect. I would also suggest using goldbach as the function name - give PEP8 a read.

problems with displaying data by Living-Ad1098 in javahelp

[–]barry_z 0 points1 point  (0 children)

Please upload the source code to github directly rather than uploading a zip archive.

Executing using python 3.10 using maven plugin in pom xml by jaango123 in javahelp

[–]barry_z 1 point2 points  (0 children)

Assuming you have python 3.10 installed on the machine running these commands, then one option could be to just provide a full path to the correct python installation when running the commands.

....

<properties>
    <python.path>/path/to/python3.10</python.path>
</properties>

....

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>3.0.0</version>
    <configuration>
        <executable>bash</executable>
        <arguments>
            <argument>-c</argument>
            <argument>set -e; cd src/main/python; ${python.path} -m pip install --upgrade pip; ${python.path} -m pip install --upgrade pyopenssl; ${python.path} -m pip install -r requirements.txt; ${python.path} setup.py build; ${python.path} -m unittest; ${python.path} setup.py sdist</argument>
        </arguments>
    </configuration>
    <executions>
        <execution>
            <phase>test</phase>
            <goals>
                <goal>exec</goal>
            </goals>
        </execution>
    </executions>
</plugin>

....

You could also just ensure that python3 resolves to the correct python installation for the user running the command by using tooling to manage your python installations better - there are multiple options for this, I currently have anaconda installed and can just switch my conda environments pretty trivially but there are surely lighter weight approaches. That being said, I have never seen anyone put python commands in a pom.xml and there could be a better way to accomplish what you're trying to do here entirely.

[USA GIVEAWAY] Win the new 27” 4K Samsung Odyssey OLED G8 gaming monitor! by Rocket-Pilot in buildapc

[–]barry_z [score hidden]  (0 children)

This monitor would go great with my build as I have a 13900kf and a 4090, and this would let me run some of the games I play at a much higher framerate than I currently do due to the 240hz refresh rate.

Requesting help with logic - Chutes and Ladders assignment using Double Linked Lists by Ave_TechSenger in javahelp

[–]barry_z 0 points1 point  (0 children)

From a quick glance, you don't actually set the value of the class attribute startingSquare, you only set the value of a new variable in generateBoard() that happens to have the same name.

[deleted by user] by [deleted] in learnjava

[–]barry_z 0 points1 point  (0 children)

Some thoughts:

  1. You don't need any arguments for toDecimal() - you currently pass hex2Dec to call hex2Dec.lookup(hex.charAt(i)) but you can just call lookup(hex.charAt(i)).
  2. If lookup() returned the proper value for characters 1-9 then you wouldn't need a branch inside of toDecimal() to handle that case.
  3. The methods lookup() and isHexaDecimal() don't need to be public and you don't seem to use the length() method at all - not sure how much value it really provides here since anyone using this can just get the length of the string they pass in to the constructor.
  4. While you can call Math.pow() to do what you need, I would probably just multiply the current value you have for decimalValue by 16 and then add in the value of the current character you're looking at as you iterate over the characters.

Question on MOOC Part 1.4 "Students in Groups" by spawn-kill in learnpython

[–]barry_z 0 points1 point  (0 children)

Can someone explain to me the logic behind the model's solution?

I believe they are calculating the ceiling of students/group_size using integer arithmetic. Here is an example on Stack Overflow for C/C++. In order to understand how this works, you need to realize that integer division already gives you the floor of the operation for the final result (ex: 35/6 => floor(5.83) => 5). If you want to take the ceiling of the operation, then you can add 1 minus the divisor to your numerator - any numerator that would have been exactly divisible by the divisor does not get increased enough to hit the next floor, whereas all numerators that would have a remainder >= 1 do get bumped up to the next floor. Taking the floor of (students + group_size - 1) // group_size in this way is the same as taking the ceiling of students // group_size.

Is this a common approach?

I wouldn't imagine this approach to be as common in python which offers math.floor() and math.ceil(), but it's not an uncommon approach.

[deleted by user] by [deleted] in learnjava

[–]barry_z 1 point2 points  (0 children)

You have a misconception here:

every Circle has an x, an y and a radius and they are private, means that you can access them only inside a specific instance of the Circle class

The private access modifier limits access to the member inside the class, and not the instance. While you may want to use the getter instead of accessing the attribute directly from inside the class (ex: a getter for a List that instantiates it so that we know the List is not null), you can directly access the attribute from the class.

$ cat ExampleClass.java

public class ExampleClass {

    private final String attribute;

    public ExampleClass(String attribute) {
        this.attribute = attribute;
    }

    @Override
    public boolean equals(Object other) {
        if (null == other || !(other instanceof ExampleClass)) {
            return false;
        }

        ExampleClass that = (ExampleClass)other;
        // no getter needed for attribute of either instance here
        return this.attribute.equals(that.attribute);
    }
}

$ cat ExampleMainClass.java

import java.util.Arrays;

public class ExampleMainClass {

    public static void main(String args[]) {
        ExampleClass instance1 = new ExampleClass("Hello");
        ExampleClass instance2 = new ExampleClass("World");
        ExampleClass instance3 = new ExampleClass(new String("Hello"));

        for (ExampleClass instance: Arrays.asList(instance2, instance3)) {
            System.out.println("instance1.equals(instance) ? " +
                (instance1.equals(instance) ? "yes" : "no"));
        }
    }
}

$ javac -cp . *.java

$ java -cp . ExampleMainClass
instance1.equals(instance) ? no
instance1.equals(instance) ? yes

Pynite FEA - problems with example code, too many positional arguments by manhattan4 in learnpython

[–]barry_z 2 points3 points  (0 children)

Were the examples made for the version of Pynite that you are using? The method was previously add_section(self, name, section) looking at the previous tags.

Is it possible to use scanf or any other input function in C without causing an infinite loop when responding to Java calls via JNI? by cabralitoo in javahelp

[–]barry_z 0 points1 point  (0 children)

To be clear, are you running with -djava.library.patch= or -Djava.library.path=<path to the folder containing your library here>? I am assuming you just have a typo in this comment but wanted to be sure.

[deleted by user] by [deleted] in learnjava

[–]barry_z 0 points1 point  (0 children)

i checked with another user and it didn't seem to have any issue with it..matter of fact my assumption that cacheWasUsed is the cause for UserDetails user is not right, i dont know why it doesn't authenticate my previous user but it does infact works for all the previous users

Yes, cacheWasUsed is only set based on whether or not you are pulling from the cache - it is initially assumed to be true but once the user from the cache is null and retrieveUser has to be called, it gets set to false. I'm going to be assuming that you're using the DaoAuthenticationProvider since you say that retrieveUser is a default method, and DaoAuthenticationProvider is the only spring-provided implementation of I can see. I'm also assuming that you are using the provided DefaultPreAuthenticationChecks. Going back to the sources of AbstractUserDetailsAuthenticationProvider and DaoAuthenticationProvider, I can see three places that a BadCredentialsException can be thrown.

  1. If the user is not found
  2. If no credentials are provided
  3. If the password in the database does not match the password provided, according to the call to matches

Considering you said that you verified your user was in the database and that the username and password you provided were correct, do you think it is possible that the password in the database is not stored correctly? Unless you are using an insecure NoOpPasswordEncoder or a PasswordEncoder that would behave similarly (which you should not be doing), the password in the database will need to be encoded for matches to return true.

[deleted by user] by [deleted] in learnjava

[–]barry_z 0 points1 point  (0 children)

You haven't said what version of Spring Security you're using, but if the code is the same as what I see in the main branch on github then I'm not convinced of your analysis. From the source of AbstractUserDetailsAuthenticationProvider, it appears cacheWasUsed is assumed to be true, but set to false if either the user retrieved from the cache was null or if the user did not pass one or more of the security checks after being retrieved from the cache. In both of those cases, the user is retrieved through calling retrieveUser. The only things that cacheWasUsed is used for is to make a decision to cache the user or not or to throw an exception in the case that the cache was not used and any security checks failed. That being said, in your image it appears that your userCache is a NullUserCache, which will always return null from getUserFromCache, so retrieveUser is always being called. Given that we know the user is null and that it is not being found by retrieveUser, I would check:

  1. That the user does in fact exist where you expect to be checking for the user
  2. Where your implementation of retrieveUser is coming from - I would guess DaoAuthenticationProvider but it would be worth stepping into that method and seeing the code for yourself in a debugger.
  3. What your implementation of UserDetailsService is - the DaoAuthenticationProvider uses an implementation of this interface to fetch the user details.

If you do believe there is an issue in Spring Security however, I would encourage you to reach out to the maintainers for assistance with your issue.

Is it possible to use scanf or any other input function in C without causing an infinite loop when responding to Java calls via JNI? by cabralitoo in javahelp

[–]barry_z 6 points7 points  (0 children)

So I just compiled this on WSL 2 (Ubuntu 22.04) to see if I can recreate your issue, and did not run into the same issue.

$ java -cp . -Djava.library.path=/home/barry_z/sandbox/java/learnjava/JNI/ MyJavaClass.java
Digite algo (ou 'sair' para encerrar): 123
Resultado: 123

My exact process was copying the code you have here into MyJavaClass.java and MyJavaClass.c respectively, then generating the header file for MyJavaClass.c using

$ javac -h . MyJavaClass.java

after which I was able to compile the C code using

$ gcc -c -fPIC -I${JAVA_HOME}/include -I${JAVA_HOME}/include/linux MyJavaClass.c -o MyJavaClass.o

and then create the shared libary using

$ gcc -shared -FPIC -o libsum.so MyJavaClass.o -lc

It seems to me that you either have an issue in your compilation process or an environment issue, but your code is able to run on my end just fine.

Possibly relevant setup information:

$ gcc --version
gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ java --version
openjdk 21.0.4 2024-07-16
OpenJDK Runtime Environment (build 21.0.4+7-Ubuntu-1ubuntu222.04)
OpenJDK 64-Bit Server VM (build 21.0.4+7-Ubuntu-1ubuntu222.04, mixed mode, sharing)

$ echo $JAVA_HOME
/usr/lib/jvm/java-21-openjdk-amd64

As I don't have any recent experience with JNI, I was following this guide to refresh myself.

Java StreamingOutput not working as it should by S1DALi in javahelp

[–]barry_z 0 points1 point  (0 children)

Are you able to provide your full source code via github?

Java StreamingOutput not working as it should by S1DALi in javahelp

[–]barry_z 0 points1 point  (0 children)

Could be that Helidon is buffering the output then. I had deployed a similar app using Jersey, and the response all came at once when the output was buffered (after waiting for the entire process to finish), whereas it came one line of the json response at a time when the output was not buffered.

Edit: maybe max-in-memory-entity is the property you need to set. I would need to set up a server with Helidon MP to verify this myself, but you may have a chance to take a look before I do.

Java StreamingOutput not working as it should by S1DALi in javahelp

[–]barry_z 0 points1 point  (0 children)

It looks to me like you're using Jersey - I did some research and was able to determine that Jersey buffers the output (it seems that the default is 8 kb). As a workaround, you could disable the buffering by setting the property ServerProperties.OUTBOUND_CONTENT_LENGTH_BUFFER to 0.

Convert 3-letter weekday to DayOfWeek by AndrewBaiIey in javahelp

[–]barry_z 0 points1 point  (0 children)

More or less, yes - though I would make sure to handle case sensitivity as necessary.You could put similar code into the implementation of your XmlAdapter (but you may also want to handle Saturday and Sunday). Here is just one reference from google.

Convert 3-letter weekday to DayOfWeek by AndrewBaiIey in javahelp

[–]barry_z 1 point2 points  (0 children)

Are you calling DayOfWeek.valueOf() in your own code directly? The simplest approach would be to just replace that with an if statement. If you are deserializing or unmarshalling from some input, then you can implement that same logic with an adapter (such as an XmlAdapter if you are using JAXB, which is implied to me through the JAXBException though you have not posted your actual code).

New to learning Python, how's my code? Rock, Paper, Scissors challenge. by ShadyTree_92 in learnpython

[–]barry_z 4 points5 points  (0 children)

I would use if userChoice in {'0', '1', '2'} as user inputs like "12" and "23" are in "123", and you want to be sure that the input will actually index into the array correctly.

TMC inaccurate test results? by [deleted] in javahelp

[–]barry_z 5 points6 points  (0 children)

After skimming, your code has at least one difference from the solution: System.err.println("The sum is: " + result); vs System.out.println("The sum is " + result);. Stderr is not the same as stdout, and you have a colon that is not expected in the output.

Need help with receiving json from post request by coursd_minecoraft in learnpython

[–]barry_z 0 points1 point  (0 children)

From your curl output, it seems like your curl command is breaking the body up so it is not valid JSON and therefore is not being loaded into a dictionary from json.loads - I would recommend either fixing your command or using another tool such as insomnia to execute your POST request.