Posts by hkotsubo • 55,826 points
1,422 posts
-
3
votes1
answer253
viewsA: How to generate a value containing the "last Friday of the month" using Java Localdate?
You can use the class java.time.temporal.TemporalAdjusters, that has the method lastInMonth, passing as parameter a java.time.DayOfWeek corresponding to Friday. Ex: // alguma data em janeiro (1 de…
-
5
votes3
answers1067
viewsA: Index or key in Javascript object
In Javascript, an object is a set of several key/value pairs, separated by the two points (i.e., chave : valor). About the keys The key can be a string: // a chave é uma string (está entre aspas)…
-
1
votes2
answers203
viewsA: date.getHours with 0 more elegant
An alternative is to use padStart. Since this method is only available for strings, you first need to turn the numeric values into string, and then use the padStart: let d = new Date(); let…
-
11
votes4
answers5739
viewsA: How to separate the letters of a string that are inserted into a list and place them in an array?
You can use list() to turn strings into lists. If you do list(string), the result is a list in which each element is a string character. Ex: print(list('teste')) This prints: ['t', 'e', s', t', 'e']…
-
0
votes3
answers212
viewsA: Problem with number guessing game
One of the main tips is on reply from @nosklo: you’re repeating code unnecessarily, which could use a loop (that’s why the loops serve, to perform something over and over again). Another detail is…
-
3
votes1
answer2219
viewsA: AssertThat method and use of Matcher
I did the tests below with Java 8, Junit 4.12 and hamcrest-all 1.3 At first it seems to use assertThat would not be necessary, as similar results can be obtained with the other methods assertXXX.…
-
9
votes4
answers1730
viewsA: How to maintain a project in 2 repositories?
The other answers suggest creating a remote for each remote repository (e.g., one for Github, one for Bitbucket), and then do push for each of them. It is a perfectly valid solution, but it is also…
-
13
votes3
answers259
viewsA: Negative lookbehind only works on Google Chrome, is there an alternative to other browsers?
As others have said, the problem is the stretch (?<!,), which is a Negative lookbehind. In this case, it checks whether nay there is a comma before the desired character (which in this case is…
-
1
votes2
answers1361
viewsA: Form validation using regex and Javascript
In the button type="submit", you call the function validar() when the button is clicked (onclick="return validar()"). But then, in the onsubmit of form, calls the function again. Then the first…
-
1
votes1
answer285
viewsA: How to create a regex in Python to get a specific text?
First of all, you don’t need two sets of parentheses in a row. When there are parentheses, they form a catch group. That is, what is inside them will be available in a group, if regex finds a match.…
-
1
votes1
answer301
viewsA: Regex by PHP position
In the question it is mentioned that you want to catch only the first number, but then it says you also want to catch them all. So I left a solution for every case. Only catch the first number If…
-
2
votes2
answers511
viewsA: Bring only the first occurrence of a regex
When you do a query like this: select campo from tabela where campo REGEXP '[0-9]{2}/[0-9]{2}/[0-9]{4}'; You are bringing the field (in case, all the value 30/09/2018 e 14/10/2018 e 21/10/2018),…
-
3
votes4
answers2763
viewsA: Add array elements in Arraylist and print values
In Java it is not possible to initialize a List in the same way as an array, using the syntax int v[] = {1, 2, 3}. There is even a proposal for language to have this resource, but for now the only…
-
2
votes1
answer1825
viewsA: Secure PHP password (Password verification)
The brackets define a character class. When you do [A-Za-z], that means "a letter of a to z or of A to Z". That is, it can be either a lowercase or a uppercase letter. So if it has a capital letter,…
-
1
votes1
answer583
viewsA: Read a txt file from a particular layout
You don’t need to read each separate snippet based on positions. An easier approach is to simply read the whole line and then use substring to get each section of the line separately: String…
-
4
votes2
answers3800
viewsA: Long or Date in JSON
Depends on what you need. The giant number, representing a long, is a timestamp. It represents a single instant, a point in the timeline, which corresponds to the amount of milliseconds since the…
-
5
votes1
answer219
viewsA: How to create/use schema Builder?
I’m not in the habit of using these JSON schemas, but come on... In fact, the documentation code is wrong, because it doesn’t even compile. The mistake "Illegal line end in string literal" you…
-
3
votes2
answers386
viewsA: Regular expression C# console application
Although I don’t program professionally in C# (I have a vacancy notion), I will talk a little about the regex in question. The website you quoted (regex.) uses the syntax /expressão/flags. That is,…
-
0
votes1
answer58
viewsA: Alerts the user that he did not choose a type=radio;
The problem is before the if (minhaEscolha === null), in this passage: document.querySelector("input[type='radio']:checked").value You’re looking for a radio marked (checked). But if none is marked,…
-
6
votes1
answer181
viewsA: Return date reversed in PHP
According to the documentation of strtotime, when the string passed is using / as separator, it is assumed that it is in format m/d/y (month/day/year). In the case of start_date, the value is…
-
3
votes1
answer22410
viewsA: How to calculate how many weeks a given month has with Javascript?
Taking into account that a week has 7 days and 4 weeks is 28 days, so every month has 4 weeks, plus a certain number X of days, where "X" may be zero (for February), 1 (for February in leap years),…
-
7
votes1
answer1756
viewsA: Is it possible to create a certificate in PFX format and set an OID for some parameters?
For starters, some details: THE OID 2.16.76.1.3.1 does not only contain the CPF, but a series of information that must be in the correct format for the certificate data to be read correctly. The…
-
7
votes3
answers1491
viewsA: MYSQL and REGEX Phone Number
If it is the users themselves who put the phones in the comments, then there is not much control over the format. Of course you can consider some more common formats. By their examples, I saw that…
-
1
votes1
answer337
viewsA: Convert String to Offsetdatetime (dd 'from' MMMM 'from' yyyy 'to' HH:mm:ss)
By code, I’m assuming DATE_TIME_PATTERN is a java.util.regex.Pattern. Well, the pattern using in a java.util.regex.Pattern should be a regular expression (regex), which is quite different from…
-
3
votes2
answers106
viewsA: Infinite Loop when reading Scanner values
The problem is you’re calling nextInt() twice in a row: System.out.println("Informe a quantidade de cédulas de CEM para Depósito: "); deposito.setQtdCem(lerInfo.nextInt());…
-
3
votes2
answers787
viewsA: How to select the logUser attribute only on the main JSON object using Regex
Don’t use regex for that You may think regex is a good idea for this case, but believe me, it’s not. You probably thought it would be something as simple as "logUser"\s*\:([^\,]+), (the word logUser…
-
3
votes2
answers750
viewsA: Formatting Date, Time and Time in PHP
A string 2019-05-13T10:00:00.000Z represents a date and time in the format ISO 8601. To turn this string into a date, you can pass it directly to the constructor DateTime: $str =…
-
1
votes1
answer47
viewsA: How to place successive matrices in vector
In Java, matrices are actually arrays of arrays. That is, an array in which each element is another array. Then, to place these arrays in another array, just make an "array of arrays", ie an "array…
-
4
votes2
answers156
viewsA: How to "fix" an exception?
Instead of trying to "fix" the exception after it happens, you could simply prevent it from happening. In this case, it would be sufficient to test the position by checking whether the value is…
-
4
votes1
answer226
viewsA: Java methods?
The problem of methods listar() and buscar() is that cont will always be zero. When you declare the static variable: static int cont; By default it is initialized with the value zero. Then if you…
-
1
votes3
answers2117
viewsA: Regular expression to return text between keys
It is even possible to make a regex that takes the content you need, but there are a few points. The first is what has already been mentioned in the other answers: regex is not the best tool to…
-
5
votes2
answers902
viewsA: Function Encode() and hash creation
By your code, I’m assuming you’re using the module hashlib. The problem is that the method update, according to the documentation, is cumulative: calling update(a) and then update(b) is equivalent…
-
3
votes1
answer290
viewsA: Add months to a Calendar without modifying the original instance
The fact of getInstance() static does not mean that Calendar is a Singleton. A Singleton means there will be only one instance of the class in the JVM. But getInstance() always returns a new…
-
4
votes3
answers345
viewsA: An array index error
The problem is in Arrays.asList(vet). When you pass an array of int, the result is a List<int[]> - that is, a list of int[] (arrays of int), and not a list of int. Example: int v[] = { 1, 2,…
-
5
votes3
answers927
viewsA: Remove a part of the URL
Complementing the other answers, another alternative is: const url = "https://teste.teste.pt/sites/teste/Normativo/NormasDeProcedimentos/Documents/Histórico/"; const regex = /\/Normativo\/([^\/]+)/;…
-
1
votes1
answer60
viewsA: Regex backreference within group with OR
You don’t need the "OR" (|), because it means that only one of the excerpts will already satisfy the expression. In this case, you have the "CREATE" on one side of the | and the other’s "ALTER".…
-
5
votes2
answers166
viewsA: Vector (array) log-in validation. java
The error has nothing to do with "the compiler not respecting the condition". In fact the program is doing exactly what you requested. In this case, the if(check = true) is doing the following:…
-
8
votes2
answers1799
viewsA: Operator "AND" in Regex
An alternative is to use lookaheads: ^(?=.*\b\d{6}\b)(?=.*\b\d{14}\b) Each Lookahead is bounded by (?= and ) and his idea is Lookahead look for the expression inside it, and if you find, go back to…
-
7
votes2
answers396
viewsA: Using REGEX in PHP to capture any number that is not within single quotes
Although it is possible to make a regex - possibly very complicated - involving lookaheads and lookbehinds, find it easier to use a small "trick" that uses capture groups. Basically, if you have a…
-
2
votes1
answer90
viewsA: Format Time using initBinder
According to the error message: ... [Failed to Convert Property value of type 'java.lang.String' to required type 'java.util.Date' for Property 'final time'; nested Exception is…
-
5
votes4
answers146
viewsA: Performing functions with and without creating local variables
Complementing the other answers, a simple way to compare performance is to use the module timeit. import timeit def exemplo_1(x): output = x + 1 return output def exemplo_2(x): return x + 1 n =…
-
2
votes2
answers1740
viewsA: Comparing datetime with minutes interval
Date format To generate the variables webtime and localtime, you are using respectively time.strftime and datetime.strftime, which are 2 methods that return strings, and not dates. Dates and times…
-
11
votes3
answers7344
views -
1
votes1
answer86
viewsA: Read matrix elements and print them
As explained in the comments, in accordance with the documentation, when you do Array(3,3), you are creating an array with 2 elements (and both elements are the number 3): let arrayCom2Elementos =…
-
3
votes2
answers183
viewsA: Problem with Regex in PHP
This is because within a string (between the quotes), the backslash must be escaped and written as \\ (as described in documentation). That’s why, \/ should be written as \\/, and \\ should be…
-
7
votes2
answers3118
viewsA: How to format date with the name of the month in Portuguese and capitalized in Moment.js?
As already said in william’s response and in the comments, the names of the months in Portuguese begin with lower case letter. But if you still want them to capitalize, an alternative is to download…
-
7
votes2
answers899
viewsA: Javascript function for email validation does not enter Else
The function replace is for making replacements. In this case, it uses regex to fetch a snippet of the string, which you can replace with another (and this other snippet may include the return of a…
-
3
votes2
answers1446
viewsA: JSON PARSE returning 'Object Object'
Your JSON is an array (as it is bounded by [ ]), and within this array there is a Object (delimited by { }), who holds the key "title". Then just take the first element of the array, and then take…
-
2
votes1
answer1546
viewsA: Remove score from a Python file
Within brackets, the hyphen has special meaning: it serves to define character ranges, as an example [a-z], which means "a letter of a to z (lowercase)". The detail is that these ranges are not…
-
0
votes2
answers1097
viewsA: How to search for a word in a file and pull the phrase where it is together with the result?
The ideal solution depends a lot on your definition of "phrase" and "word". The simplest (and naive, and probably wrong) approach is to consider that each line is a sentence and all words are…