Zachary Griggs

Rancher
+ Follow
since Apr 29, 2016
Cows and Likes
Cows
Total received
14
In last 30 days
3
Total given
0
Likes
Total received
58
Received in last 30 days
4
Total given
118
Given in last 30 days
27
Forums and Threads
Scavenger Hunt
expand Rancher Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Zachary Griggs

I recommend making your project a Maven project and then importing the crawler4j dependency in your pom file: https://mvnrepository.com/artifact/edu.uci.ics/crawler4j
You also need to look into how to make it into a .jar with ALL dependencies included since that's not default Maven behavior. You use the maven shade plugin to do this. Your goal is "shade" and phase is "package". You can also use a compiler plugin like this to set the java version:



I'm assuming you linked a .jar into IntelliJ before. While this can work, it's less consistent than using a package manager like Maven.
3 days ago
Java is not the best language to understand callbacks since you can't directly pass in code as an argument. That may be part of the confusion here. So in order to understand callbacks, we can use pseudo code.

First: an explanation of callbacks.

Assume as have a piece of code that executed asynchronously. This means that the calling code will not wait for it to finish before it continues. As in:


Assuming this executes asynchronously, it wouldn't wait for asyncMethod to finish before calling print("execute").

This is all well and good, but consider the problem of this: what if we want some code to notify the user when asyncMethod finishes. Maybe it shows a new form or something. Well there's no easy way of running that because we don't know when the asynchronous method finishes. What we can do is give the asyncMethod() a function to run when it finishes. The asyncMethod() doesn't have to know what function we want to run, all it needs is a pointer to the method. Like this (pseudo code)



In this code, we pass in the method we want to be executed after the asyncMethod finishes. That is a callback.

Note: this type of code is not allowed in java. However plenty of other languages allow you to pass in a method as a callback. This is especially common in Javascript. There are also more applications of callbacks than just running asynchronous code.

In Java, we need to work with interfaces in order to use callbacks. So we create a Callback interface with a single method that we can execute, and then create a class based on this Callback interface and pass this in instead.



And finally to answer your first question: the class cannot call en.interestingEvent() because en does not implement InterestingEvent. Rather, en uses an InterestingEvent. I also feel like the code example there doesn't give a strong reason for using callbacks in the first place there, unfortunately.
6 days ago
That is very true; to clarify, it doesn't matter to the compiler.
1 week ago
Try it out! Assign a different value to both of them and then write code:


The answer is: yes, you can.
The fact that they have the same name doesn't matter. They are distinct variables.
1 week ago
You'd probably have got more feedback if you posted in a different forum.

Anyways I'll code review
---

General comment: No javadoc comments on anything. This isn't good.

General comment: Including unit tests would have been a good idea if you had time to do so.


This line of code would be cleaner if you set it up a as a Map<Product, List<Product>>


Code can go in a constructor if you make this stuff non-static.


Reduce the size of your main method to a single line run call. For example move all of this code into a private (non-static) method called "run" and then call:



Poor exception handling here. What does a NumberFormatException mean? Tell that to the user.
Why make the call to showMenu() again? The try won't break the loop.


I don't like this scanner.nextLine(). It's better to always consume the newline rather than only if they enter something wrong.


This code has no purpose


Magic number here (and other) needs to be refactored into a constant.


I'd prefer this be handled with a loop than a recursive method call.


This exception type doesn't make sense for the context it's thrown in.


Split up long lines with newlines.


Purpose of remove here is unclear and should be commented.


Non-descriptive enum value names here


Intention of this code is unclear and should be explained (maybe this is just because it's called A, B, C)


Functionality of this line is unclear.
1 week ago
As someone who graduated recently and has now been coding professionally for over a year, I can say that programming professionally has taught me far, far quicker than academic learning. Obviously the classroom knowledge is critical to success as well, but working in a real codebase has taught me practical things that I wouldn't be able to learn anywhere else. Such as how to pick up a massive project and get familiar with it; how to manage technical debt in a project and get features out at the same time; how to code in a genuine team setting with 50+ developers. Things like that.

The technology stack we use at my job is entirely different than what I learned in school. I basically had to learn everything about our technology from scratch, and that's ok. Being able to pick up new things quickly is a skill and it's one that I am happy to be constantly developing. For me, I don't understand something until I use it. I can read 1000 tutorials and still not understand it. Play around with it for a little bit and I start to get a grasp on it. How are you trying to learn Spring? Maybe you're just going about it in a way that doesn't work for you.

To answer the question of, "do you need to know frameworks in order to get hired" - Well it depends on the job of course. If it's a java senior developer job working on a Spring application, then you probably do. An entry level Java developer, it is definitely not expected. Desktop programs are not obsolete. I mean there are still a lot of companies who use languages and technologies that are from the 1990s. Also jobs always list their ideal candidate but that doesn't mean you shouldn't apply if you don't meet every single bullet point. You never know until you try.
1 week ago
This javadoc shows all possible Entity types:
https://hc.apache.org/httpcomponents-core-ga/httpcore/apidocs/org/apache/http/HttpEntity.html

Specifically here, the ByteArrayEntity seems like it's the most dynamic: https://hc.apache.org/httpcomponents-core-ga/httpcore/apidocs/org/apache/http/entity/ByteArrayEntity.html

Can you find out the bytes that you're sending with your Postman request?
If you can, then you'll be able to re-create this in Java using this entity.
1 week ago
After writing this, I realize I may have misinterpreted it. My interpretation was that each of the split Lists need to be of the same size (the size <= 6). If that's not true, then not all of my answer will apply.

My approach here would be to first discover the sublist length before you begin splitting it into sublists. You really don't want to get halfway through and then find out your sublists need to be shorter than you originally thought.

Here's what I'd do. First write a method to calculate the total characters from index a to b of a List of Strings:


After that, write a method to calculate the sublist size required. You'll probably need a nested for loop of some kind, basically you're going to try starting with 6, see if the rules are violated. If not, you return 6. If so, you decrease by 1 and try again.

After you find the sublist size, write a method to break a list into multiple lists.

Your approach here will probably be to use another for loop going to the sublist size. Each iteration of the for loop will create a new List<String> and add it to the List<List<String>>. At the end, each inner list of string will be of the desired size.
1 week ago
I'm writing something of an IDE for a little-known language and I use a syntax tree to parse the code into logical representations. Essentially breaking it down into a variables section, functions, statement, and then finally argument to a statement. This approach works for most of the code files I've tested it against, but unfortunately some of my files are extremely large. As in, 100,000+ lines long. When it attempts to read these, it can run out of memory - especially because I made the tree immutable and so any code transformation needs to copy the tree (looking back on it, maybe a poor design decision).

Has anyone run into Java memory issues later? Are there best practices to increase efficiency or increase memory?
When I run my jar, I add the following command to it: -Xmx1g
Since I read that allows more memory use.
2 weeks ago
How much manual effort is allowed?

If there should be no manual effort, this will be extremely difficult and I don't think anyone here is going to be able to give you a direct answer on how to do this. Machine learning algorithms are not highly reliable when you don't have a huge dataset and powerful computing to process it, and achieving 95% accuracy would be an amazing result for this. While even this would likely be unacceptable for this application since it would result in a decent chunk of lost/misplaced translation (and you probably won't achieve 95% accuracy)

If you can take some manual input, simple; just have a human enter the timestamps when one person starts speaking and then divide the audio file based on those timestamps.
2 weeks ago


I can tell you right away that the given code isn't correct and won't compile. That Circle class doesn't extend anything (besides Object of course) so you can't use super like that. Also class Circle defines a constructor of Shape, which is not allowed. Is this a homework assignment? What do you think the answers are, or what have you learned about inheritance so far?
2 weeks ago
First of all, I would avoid using these "static" methods that all get called from main. Rather, have the main method instantiate your class and call a method on it, and then have all other methods used not be declared static. For example:


Methods should be declared private unless there is a reason to not declare them private. The method countCommas has no access modifier, so it is protected, not private.

I don't think countCommas should declare that it throws an IOException
You catch IOException here. You could also move the lines above (that may throw IOException) into this try block.

So it can't throw any IOException.

Speaking of exception handling - displaying the stack trace is rarely the correct way of doing so.
The user doesn't want to see a stack trace. It means nothing to them, and it exposes some of the code internals which isn't a good thing.
Rather consider - why would an IOException be thrown and what does it mean for the user? How about FileNotFound exception, what does that mean to the user? How can you tell them what went wrong in a nice way.


I don't like this line.
What is the meaning of 44?
Of course I know what the meaning is because I know ASCII but others might not.
If you have to use a number like this, at least make it a named constant so it shows its meaning clearly. You could also probably say i == ','. Not entirely sure if that'll compile but it's worth trying.


This code would just display a number to the user. What does that number mean? You could say: System.out.println("Number of commas: " + count);


This comment is unnecessary.


Not that there's anything wrong with this, but why not just use a Scanner? It's probably simpler.
Actually you could use a Scanner for reading the file too, instead of a FileInputStream. Scanner is the simplest solution for text-only files.


I would add Javadoc comments on this, explaining the intention of the code, assumptions, etc. Anything that's useful to know about it.

General comment: this method could be split into two. One method to prompt a file, and one to count the commas from the file.


This readLine is entirely unprompted. If the user runs this application, they will be greeted with a blank screen.
Instead, prompt them:
System.out.print("Enter a filename to count the commas of: ");
3 weeks ago
You'll probably need to enable TLS/SSL. I haven't used this particular software but in my experience that secures the connection and allows you to use HTTPS.

You may also wish to enable ssl connector to further secure access to the web console and other web resources of the broker. To do that, go to the ${ACTIVEMQ_HOME}/conf/jetty.xml and make sure you have the secure connector enabled. In versions 5.7 and newer just uncomment a predefined config. In any case make sure your connectors settings looks similar to this.

3 weeks ago
It sounds like you might want to look into open source contributions. Either by starting and maintaining an open source project yourself and advertising it to communities who might be interested in it, or finding existing open source software and contributing to it. Not only does that provide something of a community you can develop in and talk with, but it also provides great evidence for your resume that you know how to program.

Since you mention an interest in AWS, why not go to Terraform and complete one of the issues there? It's open source software that can deploy to multiple different cloud provider, AWS included. There are 1304 of them so you have plenty to choose from. https://github.com/hashicorp/terraform
3 weeks ago

The first check here .charAt(0) is safe, because you can't have a String of zero length because you checked it with an if statement.
How can you be sure that s has a character at index 1?
Remember that Java is zero-indexed, so index 0 is the first character. Index 1 is the second character.
Can you always be sure that this String s has two characters? What if it only has one?

This check:

Only happens the first time, since this code is in the public-facing method, not the private helper method that you use.
When you trim characters off of the String (using substring) the length changes.

It's useful if you post the error message you get here as well. Just saying that you get an error doesn't help much.
The error message can also give you a hint as to what's going wrong so that you can solve it yourself. Like in this case, the error probably tells you that index 1 is out of range.

I also recommend that you include the start brace and end brace around your if/else statements. This can help avoid logic errors if additional lines are added to that if/else statement.
1 month ago