Posts by hkotsubo • 55,826 points
1,422 posts
-
3
votes2
answers1061
viewsA: Convert dd-mm-yy date to yyyy-mm-dd in Java
Depends: the field in the database is as string (varchar)? Because dates are usually saved in databases in a field with the specific type (date, datetime, timestamp, etc). If this is the case, there…
-
1
votes1
answer55
viewsA: Linux Package . TAR Autoinstallable
You are using tail +$skip $0 1, and as the value of skip is 4, the result is tail +4 $0 1. That way, he thinks +4 and 1 are filenames, hence errors "could not open "+4" for reading" and "could not…
-
2
votes1
answer100
viewsA: File Additions and Deletions in a commit
Let’s understand why it looks like git "displays a number of changes per file greater than the total number of changes". Let’s assume I have a 3-line file: primeira linha do arquivo segunda linha do…
-
2
votes4
answers1201
viewsA: Check for parameter in javascript URL
An alternative is to use new URL(endereco) to create an object URL and then use a URLSearchParams to manipulate URL parameters. By the method set you can add the new parameter. Then just update it…
-
2
votes1
answer434
viewsA: How to do "Semantic Quotes" with the <q> tag, but it is with a different font-family
One way to do this is by defining the font-family differentiated only for pseudo-elements after and before tag q: p { font-size: 32px; font-family: serif; } q:before { content: open-quote;…
-
1
votes2
answers2915
viewsA: Compare dates using Localdate
One option is to add 2 days, and if the result falls on a Saturday or Sunday, set the date for next Monday. You can use the class java.time.temporal.TemporalAdjusters, who already owns a adjuster…
-
11
votes2
answers1242
viewsA: Regex to extract email address from a string
An expression between square brackets represents a character class. For example, [abc] means "the letter to, or the letter b or the letter c" (only one of them). If you remove the clasps (abc) then…
-
12
votes3
answers2334
viewsA: What are the differences between "soft, Mixed, hard" in git reset?
To show better what the git reset makes, first let’s establish a "base repository" and from it use the different options of reset. So the first part will be about the setup of the "scenario", which…
-
25
votes2
answers2203
viewsA: What are the differences between the states of the git files (untracked, unmodified, modified, staged)?
I think we can better understand these states by creating a project from scratch. First I will create a folder called "project" and enter it: $ mkdir projeto $ cd projeto/ For now it is empty. I…
-
6
votes1
answer6191
viewsA: Check if Arraylist has identical items
When you create the class Pessoa: public class Pessoa { private String nome; private String cidade; public Pessoa(String nome, String cidade) { this.nome = nome; this.cidade = cidade; } // ...…
-
4
votes3
answers1422
viewsA: Convert string with HTML tags into an array
You can use DOMParser to make the HTML text Parsing. From there, just manipulate the HTML to get the elements you need: // parsing do trecho HTML var texto = 'Esse é um texto de <span…
javascriptanswered hkotsubo 55,826 -
2
votes2
answers1498
viewsA: Concatenate SH command results on a line
An alternative is to use awk with the command printf, since it prints the content of each line, but without adding the line break: awk '{printf $0 " ";}' psResults.csv With this all the lines of the…
-
2
votes1
answer979
viewsA: How to catch the date and minimum time of the day with Localdatetime
MIN is a constant that represents the least possible value for a LocalDateTime (see the documentation). More precisely, it represents 1 January of the year -999999999 (year "minus 999 million") at…
-
2
votes1
answer749
viewsA: Regular expression that accepts letters, numbers and underline
The clasps ([]) define a character class, that is, accepts whatever is inside them. Ex: [ab] means "the letter a or the letter b". But when the first character inside the brackets is a ^, you will…
-
13
votes2
answers1420
viewsA: How to split a String that contains white spaces at the beginning?
This is a known problem of split when the String begins with spaces, including already discussed in the Soen. The simplest solution is to use the method trim(), that removes the spaces from the…
-
1
votes1
answer118
viewsA: Type Mismatch: cannot Convert from Unmarshaller to Pool.Unmarshaller
The method createUnmarshaller() class javax.xml.bind.JAXBContext returns a javax.xml.bind.Unmarshaller. But in your code you did the import of another class (which has the same name, but is in…
-
3
votes1
answer138
viewsA: Edit configuration file
You can use awk with the option -F, which indicates which character will be used to separate the value field in each line. In this case, I will use =, to separate the field name from its value. Then…
-
1
votes3
answers3885
viewsA: Javascript/Jquery - Calculating days between two "DD/MM/YYYY" dates
In accordance with the reply from @Gabriel, in fact with native Javascript the only way is to do the accounts manually. If you have no objections to using an external library, I recommend Moment…
-
3
votes3
answers7481
viewsA: Compare Two dates and time
Just to complement the previous responses, from Java 8 you can use the API java.time. There are some details to consider when working with the old API (java.util.Date) and the new one…
-
6
votes2
answers1861
viewsA: How to consult birthday and month in SQL on Oracle?
Complementing the reply from @Ricardo, one of the ways to do it is to use EXTRACT. As you want to "consult day and month birthday", you should extract these fields (day and month) from the date of…
-
9
votes3
answers5107
viewsA: Working days and Java 8 API, how to check?
For this you need to define your own list of holidays. There are several Apis that provide this type of information, such as the jollyday (never used, but seems to have the holidays of various…
-
2
votes2
answers54
viewsA: Change button value without showing alert
To prevent the alert from appearing, simply remove the call from alert(). Already to update the text button (which is not the same as the attribute value), you should also update the property…
-
1
votes3
answers187
viewsA: Comparison of dates in Javascript
If you want to compare the date and time, but ignoring the seconds, an alternative is to use the method setSeconds and change the value of seconds to zero. I recommend also change the milliseconds,…
-
13
votes1
answer166
viewsA: Implement Java Functional Programming Loop
The syntax Permissao::getNome is a method Reference, or a reference to the method getNome class Permissao. It’s different from a method call, so it can’t be in the body of lambda. To use the method…
-
11
votes2
answers3690
viewsA: Regex to capture words between two characters
To reply by @Leandrade explains very well how to solve the problem. I would just like to add an explanation about your attempt (why it didn’t work), in addition to proposing some alternatives.…
-
5
votes1
answer250
viewsA: Add 1 minute to the hour
As in your code you have the constant MIDNIGHT, I’m assuming the class Time represents hours of the day. So simply adding 1 to minutes can bring invalid values when you have one Time which…
-
3
votes3
answers3476
viewsA: Grep with multiple parameters
You can use the delimiters [], that take all the characters inside them (to \ must be escaped, so stay \\): grep -e "[\\|]" See examples of this regex here. As reported in the comments, the grep…
-
1
votes1
answer184
viewsA: Extract private key from file with extension . DER
If I’m not mistaken x509 only works if the file contains a certificate (without the private key). As in your case the file only has the RSA private key (as stated in the comments), the option rsa…
-
3
votes2
answers184
viewsA: I cannot format date
Supposing rs is a java.sql.ResultSet First, an explanation of what happens. The method rs.getDate() returns a java.sql.Date, and the code only works because this is a subclass of java.util.Date. But…
-
5
votes6
answers2089
viewsA: Check if a String contains two words
indexOf(" ") returns the position the space is in String, therefore it will not necessarily be 1. It would be right to test if the value is different from -1, since this is the value returned if…
-
3
votes1
answer123
viewsA: Error in recursive logic
First, your function does not need 3 parameters. If you want to calculate "b to n", you only need two parameters (b and n). Now let’s check how the function should be potencia. Thinking of…
-
1
votes1
answer4788
viewsA: Distance between two points
If this entrance: -2.5 0.4 12.1 7.3 Corresponds to: x1 y1 x2 y2 Then first you must correct the order in which things are read. You are considering that the first line has X1 and x2, when in fact it…
-
2
votes2
answers327
viewsA: Exact number of times a given character must repeat Regex
The other characters can only be zeros, or they can be anything other than 1? Anyway, I’m using the expression [^1] (everything that is not 1) together with ^ (string start) and $ (end of string),…
-
6
votes5
answers23968
viewsA: How to get and format current date and time?
In the question title is mentioned "date and current time", but in the question body specific values are mentioned. Anyway, it follows a solution for both. The other answers use SimpleDateFormat,…
-
1
votes2
answers300
viewsA: Error formatting date:
By error message we may have a clue of the problem: Unparseable date: "2016-07-28T21:58:58" Note that enter the date (2016-07-28) and the time (21:58:58) there’s a letter T. This letter is the…
-
3
votes4
answers10421
viewsA: How can I get a date (day, month, year, time, minute, and second) converted into milliseconds in Java?
Just to complement, a point that was not addressed in the other replies. Timestamp In accordance with the reply from @utluiz explains, the amount you are asking for (returned by date.getTime()) is…
-
3
votes2
answers87
viewsA: Variable to validate 'Login' field?
When you use ^ in square brackets ([]), you are saying that nay either the characters in the brackets - this expression is also called Negated Character Class. But if you want an expression that…
-
7
votes4
answers320
viewsA: Check if a string is only composed of 0
If you are testing strings, an alternative is to use regular expressions: var palavra = "00000"; var palavra2 = "a00a0"; console.log(/^0+$/.test(palavra)); // true…
javascriptanswered hkotsubo 55,826 -
0
votes2
answers1598
viewsA: Send value of a <a> onclick
If you want Javascript to be executed by clicking on a link, do not use href, and yes onclick. Other details: the tag a has no attribute value. Then an alternative is to pass the value directly to…
-
3
votes2
answers117
viewsA: String match does not work with 1 character
Let’s break the last part of the expression ([a-zA-Z0-9-].+) to better understand: [a-zA-Z0-9-]: means "a letter, number or stroke" .: means "any character" +: means "one or more occurrences" of the…
-
2
votes2
answers902
viewsA: Ignore the first line
Use the command tail with the option -n: tail -n +2 arquivo.csv In the case, -n +2 will display only from the second line onwards (you can change the number to any value you need). The sign of + is…
-
1
votes1
answer84
viewsA: Regular expression to validate a field
If you want the "1 digit, 2 letters" pattern to repeat at most 3 times, you can use the quantifier {}, indicating the minimum and maximum amount of times. In case, the minimum is 1, and the maximum…
-
0
votes2
answers1096
viewsA: Error formatting string for python datetime
(Assuming that you’re using dateutil.parser) When you call parser.parse, the return (datetime_object) is a variable of the type datetime. And this object can be formatted directly, through the…
-
2
votes1
answer36
viewsA: take the html of a $('a'). index(this);
You must use html(), but not in the i (which is the index of the element), but in the element itself that was clicked (in this case, this): $(document).ready(function(){…
-
3
votes1
answer206
viewsA: How to select a text that does not have a certain term in the middle?
The problem of quantifiers * and + is that they are "greedy", that is, they try to take as many characters as possible that satisfies the expression. To cancel this "greedy" behavior is enough put a…
-
1
votes2
answers169
viewsA: Only one class can instantiate another class, how do we do that?
If only one Administrador can create a Colaborador, that means that no one else can create it, that is, its builders cannot be public. Remove the public of the builders of Colaborador and their…
-
4
votes1
answer336
viewsA: Delete chunk from a string with replaceAll
You almost got it right. To remove the whole section, you must use a regex that has the fixed part, followed by the "any text" part, but using a quantifier, as * or +: String s =…
-
2
votes2
answers1214
viewsA: Use of A1 digital certificate installed on the server
Rather, a short summary of how certificates and digital signature work. At the end of the reply I left references, after all it is a complex subject and the details would not fit here. In general,…
-
1
votes1
answer942
views -
1
votes1
answer104
viewsA: Error Arrayindexoutofboundsexception
The problem lies within the for: for (int i = 0; i < vet.length; i++) { list.add(Integer.parseInt(vet[1])); } Instead of taking the position of the array indicated by the loop (i), you are always…