Posts by Woss • 73,416 points
1,476 posts
-
1
votes1
answer72
viewsA: Creation of Recursive Folders
A practical way (a few lines) is to create a vector with the values of the variables and filter them with the function array_filter. Then you can unify the remaining values with the function…
-
3
votes1
answer96
viewsA: Gping must be called as first argument
The error happens because you are calling the method statically without instantiating the class. While doing: gp = GPing You are not creating a class instance, but passing the class reference to…
-
17
votes11
answers37801
viewsA: Compute sum of digits of a number
If you want to explore alternative solutions, I propose one that escapes the hint of the statement. n = input("Digite um número inteiro: ") print(sum(int(i) for i in n)) The native function sum…
-
3
votes4
answers1061
viewsA: How to take the units of a two-digit number
To get the unit, just calculate the rest of the division by 10: $num = 25; echo $num % 10; // Imprime 5 And for the ten, just take the entire part of the division by 10: $num = 25; echo intdiv($num,…
-
6
votes2
answers55
viewsA: < and > check in php
If your intention is to compare three values, the final order should always be the same: $curva_a > $curva_b > $curva_c You can only compare the adjascent values: if ($curva_a <= $curva_b)…
-
14
votes1
answer10500
viewsA: When to use lists and when to use tuples?
Both are types of data sequences, but one is mutable and the other immutable. Both list and tuple are data sequences and have many common properties, but the basic difference is that the list is…
-
1
votes1
answer682
viewsA: how to use filter_input NO $_POST
Just get all the field names with the function array_keys and iterate on them: foreach(array_keys($_POST) as $var) { $filtered[$var] = filter_input(INPUT_POST, $var, FILTER_SANITIZE_SPECIAL_CHARS);…
-
94
votes4
answers4098
viewsA: What is pythonic code?
What is Pythonico? The expression pythonic, originated in English, pythonic, is a vague expression, that is, without an exact meaning. It is usually used to reference a code idiomatic in Python. The…
-
7
votes9
answers23719
viewsA: Inverting sequence (PYTHON 3)
Problems: The excerpt while n == 0 will produce an infinite loop and so will print infinitely numbers on the screen (we do not want this). The value seq[i] will be an entire value and therefore is…
-
23
votes5
answers13505
viewsQ: Difference between Object and Instance
Object-oriented programming is often spoken of in both class and object instances. Seeking the meaning of each one, I realized that now the concepts are unified and the same are treated as synonyms,…
-
25
votes1
answer2677
viewsA: How does Yield* work in Javascript?
Generators The syntax function* is used to define a generator and yield is the analogue to return for a generator. What is? Generator is considered as a special function, responsible for creating an…
javascriptanswered Woss 73,416 -
3
votes1
answer919
viewsA: Problems with url using Thymeleaf
By default, as per documentation, the tool adds variables to the query string of the URL. If you want to enter the URL’s value, use the syntax {nomeDaVariavel}, according to the third example of the…
-
3
votes4
answers724
viewsA: Logical doubt: How to find out if an hour is between the hours interval (independent of the day)
Solution in PHP In my view, since we are working with schedules, the easiest is to use the class Datetime PHP. First, let’s define the tests shown in the statement: $tests = [ [ "inicio" =>…
-
1
votes1
answer75
viewsA: insert date sequence in sequence in the bank
Agree to compare an integer value $i with a string $data_fim doesn’t make any sense? If you want to work with date ranges, you can use the native PHP class Datetime. First, setting the start and end…
-
2
votes2
answers46
viewsA: Element problem with char and number
If the goal is just to return the value multiplied by 3, you can recover the string: var cent = document.getElementById("Centesimas").firstChild.data; Remove the character : with the function slice:…
-
3
votes3
answers243
viewsA: Python "list out of the range"
There are some problems in your code: The function write just wait one string as parameter. If you want to write multiple items at once, use the function writelines, which accepts a list of string…
-
3
votes2
answers1417
viewsA: Why doesn’t the background-color appear?
Incompatibility occurs between properties position, defined as absolute, height, with relative values. This is because using the property position: absolute you will be removing the element from the…
-
2
votes1
answer91
viewsA: How to get a result type n1 + N2 + n... = x?
A very simple way to do this is to store the number dividers in an auxiliary vector and, if perfect, display them. The main limitation is that the number of divisors will be limited by the size of…
-
4
votes1
answer64
viewsA: How to make a cookie last only one request after being created in php
On the error display page, you simply display the cookie and delete it immediately after: <?php if (isset($_COOKIE["message"])) { echo $_COOKIE["message"]; unset($_COOKIE["message"]); // ^-- Aqui…
-
1
votes2
answers66
viewsA: How to change the delimiter of the Php array obtained via POST by replacing the comma?
To really do what you’re asking, you can use the function preg_match_all and locate the appropriate values with a regular expression: $reference = "2,7 cm, 3,1 cm, 20,0 dm, 0,89 m, 0,0001 km"; if…
-
0
votes2
answers126
viewsA: Hover in two Ivs within the same column
What you can do is properly select the child elements from the event hover of the parent element. For example, if you want to change both the font color and the border of the child elements, you can…
-
4
votes2
answers2185
viewsA: How popular select from another select using python and Django?
To understand why you can’t implement the way you tried, only with Python, you’ll need to understand the differences between frontend and backend. Maybe this discussion help you with something. But…
-
29
votes1
answer3647
viewsA: What is shadow DOM?
Shadow DOM The shadow gift, or shadow Tree, is an HTML node tree just like any other tree we already know (a light Tree), but which is attached to a specific element of light Tree, not the document…
-
1
votes2
answers333
viewsA: Calculate minimum number of permutations to sort
There are several sorting algorithms, but the main among them is the Quick Sort. It consists of defining one of the elements of the list as a pivot element. In the example below, it is considered…
-
11
votes2
answers7292
viewsA: Filter elements from a Python list
Answer is somewhat outdated and lacks some additional details. I fixed what was most grotesque and the night I will rewrite it. You can filter your list of 3 possible ways: Using the function filter…
-
3
votes1
answer72
viewsA: I can not run this giving error of indexing what is wrong
I don’t know where this class is coming from Queue, but if it is from Python itself, from the module queue, there are many errors in your program. But considering that it is its own implementation…
-
3
votes1
answer1643
viewsA: How to call a function within an anonymous function?
The problem of defining the function within an anonymous function is that it will only belong to the context of this function, and will cease to exist when the anonymous function has finished…
javascriptanswered Woss 73,416 -
3
votes1
answer111
viewsA: Numbers are not adding up correctly
This is because by default PHP considers the character . as decimal part separator, which is the standard in the US, for example. We write 1,234.00 to represent the number one thousand two hundred…
-
0
votes2
answers107
viewsA: div based on radius - border-Radius or other method?
I believe you can increase the width of the div, so that the edge radius is softer, but so that it does not spoil the layout, use overflow: hidden in the mother div. .container { width: 100%;…
-
4
votes2
answers257
viewsA: string formatting
You can also do it with regular expressions, considering that the pattern is always the same: (número-número) número Where número would be any sequence of digits (i.e. non-negative integers), the…
-
6
votes2
answers811
viewsA: Printing specific lines from a text file
Logic The implemented logic is simple: The contents of the file are read and stored in content Stores in date the desired date With regular expressions, search the file for all dates in the format,…
-
1
votes1
answer33
views -
1
votes1
answer103
viewsA: Validate multiple forms at once - Simulated
First, you don’t need multiple forms on your page. Only one can handle it. The only change you need to make to do this is to differentiate the fields between the questions. You can define the value…
-
2
votes2
answers85
viewsA: How to get element id from find method?
If it’s just to concatenate, you can do something like: I made the id appear as the value of input to facilitate the display of these. $("#addRow").click(function() { $clone = $('#tabela…
-
13
votes4
answers14684
viewsA: Javascript Regular Expression for Phone with IDD
You can use the following expression: /^(?:\+)[0-9]{2}\s?(?:\()[0-9]{2}(?:\))\s?[0-9]{4,5}(?:-)[0-9]{4}$/ Hard to understand? It was generated through the tool Simple Regex Language: begin with…
-
5
votes2
answers262
viewsA: How secure is my code, with private variables?
In the paradigm of object orientation, there is what is called encapsulation of properties and methods. It is quite common to find materials in which it is said that the function of encapsulation is…
-
2
votes2
answers55
viewsA: Function to convert letter size to SASS
Solution taken from Converting Your Typographic Units with Sass: @function convert($value, $currentUnit, $convertUnit){ @if $currentUnit == px{ @if $convertUnit == ems{ @return $value / 16 + 0em; }…
-
0
votes1
answer131
viewsA: error sending email in php using phpmailer
So that the PHPMailer work properly four files are required: - PHPMailerAutoload.php - class.phpmailer.php - class.pop3.php - class.smtp.php Download these four files directly from repository…
-
1
votes1
answer814
viewsA: How to update time automatically using strftime
Yes, this requires Javascript. HTTP requests do not store states on the server (stateless) and, therefore, the PHP script stops running after returning the reply to the request. This way, only the…
-
3
votes2
answers1019
viewsA: PDO Statement Dúvidas
Considering the query: SELECT email, senha FROM tbl_usuario WHERE email = ? Utilise bindValue: $searchSQL->bindValue(1, $email, PDO::PARAM_STR); Or pass the value through execute:…
-
3
votes1
answer83
viewsA: Ignore certain indices in a Python list
[lista[i:i+2] for i in range(0, len(lista), 4)] First, I used the list compression to generate the new list. The values of this list will always be the values of the original list in the indexes i…
-
2
votes2
answers1849
viewsA: Slimframework: Method not allowed. Must be one of: GET
In the Slim framework, when setting the route as: $this->get('/p/{pag_slug}', function($req, $res, $args) { // ... })->setName('site.pagina'); You will be mapping the URL /p/{pag_slug} only…
-
12
votes2
answers790
viewsA: What are Try/Catch blocks?
To understand the block try/catch it is necessary to understand the concept of exception. Do not be alarmed, it is quite common that this concept causes strangeness when you begin to study the…
-
7
votes3
answers715
viewsA: Calculation of incorrect multiplication
As you already have the answer of how to get around the situation, I will leave here the excerpt from documentation which explains why this happened. Accuracy of floating point numbers Floating…
-
3
votes2
answers45
viewsA: Possible problems with logical operators
There is the difference, but I don’t know if it exactly applies to the case presented. The difference between using !(condition) and condition === false is that PHP naturally considers some values,…
-
0
votes1
answer36
viewsA: Interacting all items on a list
AP_X = [1,2,3,4,5,30] AP_Y = [1,2,3,4,5,30] demanda_X = [1,2,3,4,5,30] demanda_Y = [1,2,3,4,5,30] ap = list(zip(AP_X, AP_Y)) demanda = list(zip(demanda_X, demanda_Y)) distancia = [] for i in ap: for…
-
2
votes1
answer174
viewsA: Check coincident times within an array
The logic is simple: Scroll down the list (foreach) - could be array_map; Converts the data to an object \DateTime; Checks if the range does not match any previously checked (array_walk); 3.1. If…
-
2
votes1
answer106
viewsA: Traversing a file and splitting its contents into other separate files using Python
Yes, just make the file name variable. Something like open('time{}.txt'.format(i), 'w') where i is an accountant. from scapy.all import * pkts = rdpcap("lalalao2.pcap") i = 1 # ^--- Inicia o…
-
4
votes2
answers1215
viewsA: How to pass arguments by value in Python?
In theory: A basic search on the Internet, I found this reply: Python passes Ferences-to-Objects by value (like Java), and Everything in Python is an Object. This Sounds simple, but then you will…
-
1
votes2
answers1791
viewsA: Catch string inside PHP div
Since this is a piece of HTML code, you can use the class DOMDocument: $qtd = '<div id="itens"> <span> 435 itens encontrados </span> </div>'; $doc = new \DOMDocument();…