Posts by Woss • 73,416 points
1,476 posts
-
2
votes2
answers42
viewsA: Iterate indexes of a vector
Then to get the desired result, you will need two loops: one to go through the index that will be subtracted and the other the indices that will subtract. That is, the first part of the list will be…
-
3
votes1
answer598
viewsA: declare variable passing constant inside the object
I did not understand the question of "good practice", but the error occurs because it is not possible to initialize constants with any value other than a constant expression. Vide documentation: The…
-
1
votes2
answers50
viewsA: Delete and recreate variables in the same scope of different functions
As commented on the question - and if I understand the problem correctly - you do not need to change the super global variables to generate a file log. Honestly, it doesn’t even seem to make much…
-
12
votes6
answers8998
viewsA: Sum of multiples of 3 or 5
Solution using IntStream From Java 8 you can use the class IntStream to do the loop loop work: IntStream stream = IntStream.range(1, 1000); The above code will generate a Stream representing all…
-
2
votes1
answer104
viewsA: Taking value from one input and passing to another dynamically
The way that would solve this problem is to change the call from the event to: onchange="showValue(this)" because then you will pass the element reference select, not only its value; and in function…
-
29
votes3
answers10675
viewsQ: What are Path Parameters in a URI?
What are the path Parameters of a URI and its function? A URI that defines the parameters represents a resource other than the URI that does not have the parameters? This is, /foo;v=1.0 is a…
-
16
votes1
answer13251
viewsA: What is it and what is Karnaugh’s map for?
It is difficult to summarize much because there are many concepts that need to be mastered to properly understand Karnaugh’s map. Below I will try to simplify to the maximum without leaving…
-
4
votes1
answer102
viewsA: Subtleties between Python and C
What you describe is what we call idiomatic code. What is "idiomatic expression" in programming? Obviously there will be various ways of creating a function that returns the desired result, but not…
-
2
votes2
answers2587
viewsA: Delete a particular line from a . csv using Python
To avoid the need to work with temporary files, you should store the entire contents of the file in memory and write it as needed. To do this, we read the entire file: # Abre o arquivo para a…
-
29
votes3
answers1205
viewsQ: What are Proxy, Gateway and Tunnel in the HTTP protocol?
In the HTTP protocol specification, more precisely at RFC 7230, provision is made for the possibility of intermediaries between the user agent (UA), the entity that makes the HTTP request, and…
-
6
votes3
answers115
viewsA: The logic behind how PHP interprets string and number concatenation?
The question checks your knowledge of two aspects of language: how PHP treats strings within a mathematical operation - that is, how the cast of string for a number - and the precedence of…
-
0
votes2
answers459
viewsA: What is the number of the line clicked
What you can do simply is to enter a form field of the type radio in the table, along with a label, thus, when the table row is pressed, the field will be selected, containing the id of the record…
-
1
votes1
answer32
viewsA: How best to update inputs alternately
First, let’s consider that when your form is submitted, the following values come to PHP: $_POST = [ "ambiente" => "Novo ambiente", "logotipo" => "", "certificado" => "", "senha" =>…
-
3
votes2
answers2065
viewsA: Password_verify does not return the correct one
The hash used by the function password_verify not just the MD5 password. Actually, the function is compatible with the function crypt, i.e., the hash to be used should be this: define("SALT",…
-
1
votes1
answer250
viewsA: How to print a given list from a string of a . csv using python
The simplest solution I see for you is to use the else of for (Yes, that exists in Python). The else of for is executed whenever the whole loop is traversed, ie if the critic is not found in the…
-
1
votes2
answers516
viewsA: [Solved]Assign label value when selecting product in combobox
Surely you will need to implement the solution with Javascript, but the use of AJAX is unnecessary. You do not need to make a request to the server anymore to get only a value you already know…
-
8
votes4
answers7265
viewsA: How to get customer operating system information?
First, there is no way to obtain this information with absolute certainty, as any and all client information passed to the server will be via HTTP request and therefore can be modified manually.…
-
14
votes2
answers2933
viewsA: What is the difference between global and superglobal variables?
Super Global Variables Super global variables are native variables of PHP and are named because they will be present in any scope of the program. They were introduced in PHP 4.1.0 and are: $GLOBALS:…
-
18
votes6
answers630
viewsA: Is there a problem compressing CSS?
There’s some risk in doing that? I can’t imagine any direct risk in compressing the CSS file, because it is exactly the same code, without all the unnecessary characters maintaining the correct…
-
12
votes3
answers189
viewsA: What happens in the expression "$a+++(+$a)"?
The expression PHP perceives will be: $a++ + (++$a) As any expression is parsed from the left, it will occur: The operation shall be analysed $a++, producing the present value of $a as a result and…
-
5
votes2
answers2391
viewsA: In PHP, is there a difference between Double and Float?
To complete the francis' answer, it is valid to put the C source code of the PHP implementation. For example, when using the function settype, the documentation recommends: Possible values for type…
-
2
votes1
answer708
viewsA: Why does it declare a class or id in the script and link tags?
The exact function of the attributes could only be given when analyzing the code of the application in question, however, below I cite some possible applications of these attributes in these…
-
2
votes3
answers5589
viewsA: Grab child element in css
From the title of the question, I believe the solution would be: div > p > img { padding: 10px; } The operator > will fetch any direct child element among the related elements. This is, div…
-
4
votes2
answers5347
viewsA: Know how many years, months, days, hours, etc have passed since a certain date
In a very simplified way you can do: import datetime d1 = datetime.datetime(2014,7,16,23) d2 = datetime.datetime.now() diff = d2 - d1 days = diff.days years, days = days // 365, days % 365 months,…
-
2
votes2
answers1475
viewsA: Find the largest palindrome made from the product of two 3-digit numbers - Python
Another possible solution: from itertools import product palindromes = (i*j for i, j in product(range(100, 1000), repeat=2) if str(i*j) == str(i*j)[::-1]) print("O maior palíndromo encontrado foi",…
-
2
votes2
answers3654
viewsA: How to resolve "Function name must be a string" error?
The wrong line clearly is: $sql_query = $mysqli($sql_code) or die ($mysqli->error); The error message has also been corrected, from $mysqli->erro for $mysqli->error. Let’s consider that…
-
2
votes1
answer61
viewsA: Use of the set and for function in the same structure
Considering the line: world_trends_set = set([trend['name'] for trend in world_trends[0]['trends']]) The equivalent code would be: temp = [] for trend in world_trends[0]['trends']:…
-
1
votes1
answer367
views -
3
votes1
answer89
viewsA: PHP While generating more loop
The problem is using the structure do ... while to iterate on the record. Considering the code below: do { <block> } while (<condition>); The code block defined in <block> will be…
-
37
votes5
answers19389
viewsA: Differences and advantages between Github and Gitlab
A basic comparison can be found in this page and has been freely translated here: Release date: Gitlab: September of 2011 Github: April of 2008 Both are in the market for quite considerable time and…
-
2
votes1
answer123
viewsA: Mysql syntax error
The error is in what seems to have made a PHP concatenation inside a string: $query = "insert into uniformes (nome, descricao, tamanho , quantidade) values ('.$nome.', '.$descricao.', '.$tamanho.',…
-
17
votes6
answers751
views -
21
votes6
answers751
viewsA: Numbers and your friends
Python (115 bytes) N,d=1500,lambda n:sum(i for i in range(1,n) if n%i==0) print({i:d(i) for i in range(N+1) if i==d(d(i)) and i>d(i)}) Exit: {284: 220, 1210: 1184} Explanation: In the first line…
-
5
votes3
answers881
viewsA: How to redeem all data of the current month grouped by date?
The idea would be the same as the current week, just use the function MONTH Mysql to check the month and compare to the current date, CURRENT_DATE. SELECT COUNT(*) as `qtd`, `datetime_start` as…
-
1
votes1
answer315
viewsA: How to rename files dynamically in upload?
You can use the function md5 along with the [microtime][2] to generate unique names for each image. <?php $currentName = $_FILES['userfile']['name']; $parts = explode(".", $currentName);…
-
2
votes1
answer640
viewsA: Validate and capture sequence of numbers
You can use: /([0-9\-]+)\-[0-9]+/ Basically: ([0-9\-]+) creates a group with numbers and the hyphen; \- will always marry the last hyphen of the expression; [0-9]+ will always match the last number…
-
1
votes1
answer282
viewsA: Do I need to include classes when I inherit?
Let’s assume that we have three files: two with the definitions of the classes and another that will be the code to be executed. Person.php <?php class Person { public $firstname; public…
-
3
votes1
answer95
viewsA: Parameters functions for click event do not work
From what you described, just use the function toggleClass jQuery to add/remove a CSS class from the pressed element. When an element is pressed, jQuery will check if it has the CSS class; if it…
-
1
votes1
answer524
viewsA: How to hide and display a form using a link
A very simple solution is to assign a function to the event click of the desired element and control the value of the attribute display of the form. To do this, you can use a control variable that…
-
7
votes3
answers318
viewsA: Difference between properties syntax in C#
According to the documentation, the excerpts are (practically) equivalent. In the second, you define a class field as private and create a property to manage it. public class Person { // Define o…
-
5
votes2
answers1534
viewsA: Get value other than null javascript
Considering this condition: if (obj.value != "" || obj.value != null || obj.value != undefined) { console.log("Condição foi satisfeita"); } The condition will be true when: obj.value is different…
javascriptanswered Woss 73,416 -
5
votes2
answers7633
viewsA: How to format a full date?
It is possible to do in a manual way, creating the list of names of the days of the week, accessing the position data.getDay(), and creating the list of names of months, accessing the position…
javascriptanswered Woss 73,416 -
1
votes1
answer325
viewsA: Accessing different objects within an array
Just filter your object on the condition you wish. If in this case you need all the objects you own cor: azul, just do: let list = cabelo.propriedade.filter(item => { return (item.cor == "azul");…
javascriptanswered Woss 73,416 -
9
votes1
answer1269
viewsA: How the Python 'in' operator works
The problem is not with the operator in, but on the logical operator or and and that you used. Do: >>> (2 or 10) in range(1,6) Do not check if the numbers 2 and 10 are in the range(1, 6).…
-
2
votes2
answers223
viewsA: Dynamically creating array elements
Supposing we have the table browsers in the database: id | name ---+------------------ 1 + Google Chrome ---+------------------ 2 + Firefox ---+------------------ 3 + Opera ---+------------------ 4…
-
3
votes2
answers348
viewsA: Parse error: syntax error, Unexpected '' (T_ENCAPSED_AND_WHITESPACE)
The problem is basically using a PHP code within a text in PHP. You set the text in double quotes and this tells PHP to interpret your content. What does that mean? That if there is a PHP variable…
-
5
votes3
answers280
viewsA: How do I block access to setting parameters in a class?
What you want to do is clearly function of __slots__, vine documentation: Without a __dict__ variable, instances cannot be Assigned new variables not Listed in the __slots__ Definition. Attempts to…
-
13
votes5
answers21141
viewsA: What is the functionality of n?
Python uses the character \n for line breaking. Note that even if it is composed of two characters, it represents only one in the ASCII table: character 10. It is also known as ASCII LF, where LF…
-
0
votes1
answer240
viewsA: If within PHP Field
The simplest is to concatenate the values within the desired conditions: $email = "[email protected]"; $whatsapp = ""; $html = "<h1>Aqui começa seu HTML</h1>"; if ($email != "") { $html .=…
-
6
votes1
answer7278
viewsA: Check if a key exists in a dictionary
To check if a certain key exists in a dictionary in Python, just do: if "chave" in dicionario: print("O dicionário possui a chave") That is, if we consider the dictionary: d = {'a': "Valor de A",…