Posts by stderr • 30,356 points
651 posts
-
3
votes2
answers599
viewsA: List of square roots
The sum is not necessary, to return the list, simply do: import math def raiz(n): return [math.sqrt(x) for x in range(1, n + 1)] print (raiz(6)) # [1.0, 1.4142135623730951, 1.7320508075688772, 2.0,…
-
5
votes1
answer671
viewsA: Specify DNS server when resolving address
Natively there seems to be no way to do this. Alternatively, you can use the module dns.resolver of the tool set dnspython. To install on Ubuntu/Debian, via apt-get, do: sudo apt-get install…
-
4
votes1
answer6483
viewsA: What is the most appropriate way to batch test ERRORLEVEL?
Probably the last option because of the readability and enable dealing with negative returns. IF %ERRORLEVEL% EQU 0 ( echo OK ) ELSE ( echo ERRO ) Another alternative with conditional: IF…
-
9
votes1
answer3840
viewsA: 'Dict' Object has no attribute 'has_key' in Python3
The method dict.has_key was removed in Python 3.x, use the operator in. Removed. dict.has_key() - use the in Operator Instead. In your case, you can use it like this: if "code" in kwargs: self.code…
-
5
votes1
answer111
viewsA: Concatenate a new line
Use double quotes " instead of single quotes ', in such a way as to enable the interpolation of string, \n will be interpreted as line breaking and not literally. #!/usr/bin/perl print 'oi' . "\n" .…
-
1
votes2
answers660
viewsA: Return getInstallments Pagseguro
I put myself on the line var retorno_bandeira = response.installments + "." + bandeira, return of all data comes Undefined, but add the name of the flag directly on the line like this…
-
1
votes1
answer72
viewsA: Terminal: program not installed
According to the documentation, it is necessary to open the file .bashrc or .bash_profile (depends on configuration) and remove the line rbenv init, which is usually at the end of the file, and…
-
4
votes1
answer440
viewsA: How to convert special characters?
Use the function urlencode: $string = "União"; echo htmlentities(urlencode($string)); // Uni%C3%A3o…
-
2
votes2
answers274
viewsA: Playsound function
Instead of using the flag SND_ASYNC, use SND_NOSTOP. According to the documentation: SND_NOSTOP The specified sound Event will Yield to Another sound Event that is already playing in the same…
-
2
votes1
answer205
viewsA: I can’t capture JSON data!
Do the following: By default Curl will check that the server certificate is valid, if the check fails, the connection will fail, to disable change CURLOPT_SSL_VERIFYPEER for false: curl_setopt($ch,…
-
3
votes1
answer107
viewsA: Error Openwebmail when sending email to a person
... but they get the message, someone has seen and or imagines what can be? The problematic code snippet may be in this subroutine: sub pipe_mode { ... open(MAIL, "|-") or do { .... }; print MAIL…
-
1
votes2
answers836
viewsA: How to set a header with a JWT token in a request made by the Requests library?
You can use the package requests-jwt, which basically creates a mechanism customized authentication to be used with requests. To install, type in the terminal: pip install requests_jwt Note:…
-
9
votes3
answers2010
viewsA: How to optimize the sum of elements in an array
From ES6, you can use Array.reduce so with arrow functions: var numeros = [1, 3, 4, 2000]; var soma = numeros.reduce((a, b) => a + b); console.log(soma); Another alternative with while: var…
-
3
votes2
answers761
viewsA: Store paths containing directory with space in name
Another option is to reference the variable between double quotes: home="/home/douglas/Minha Pasta" cd "$home" According to the documentation, 5.1. Quoting Variables: (In free translation) When…
-
2
votes1
answer102
viewsA: Problem with handling txt files in C++
According to the function documentation sprintf: The size of the buffer should be large enough to contain the entire Resulting string (see snprintf for a Safer version). According to your comment…
-
38
votes6
answers40933
viewsA: Does ternary surgery exist in Python?
There is, in Python it is known as Conditional Expression. <expressao1> if <condicao> else <expressao2> First, the condition is assessed (rather than expressao1), if the condition…
-
1
votes3
answers9343
viewsA: Check if a date is valid
Assuming the date is always received in the format dd/mm/yyyy hh:mm, you can use the expression \d{2}\/\d{2}\/\d{4} \d{2}:\d{2} to validate, see an example: using System; using…
-
1
votes1
answer1096
viewsA: Function Returning None
In the method calcuate_areas, failed to return the result, areas: # ... for geom in geometries: area = geom.Area() areas.append(area / conversion_factor[unity]) return areas…
-
2
votes2
answers12233
viewsA: How to display/hide fields according to selection?
You can get the selected value from select through the attribute value: function exibir_ocultar(val) { if(val.value == 'pessoa_fisica') { document.getElementById('cnpj').style.display = 'none';…
-
4
votes1
answer392
viewsA: How to list all files in ". ts" format of folders and subfolders to be converted to ". avi"?
Perhaps it would be more appropriate to use the find for this task: find . -name "*.TS" | while read -r ARQUIVO; do ARQ_DESTINO="${ARQUIVO%%.TS}.avi" echo "Convertendo $ARQUIVO para $ARQ_DESTINO"…
-
1
votes1
answer390
viewsA: Capture date from Qdateedit
To return the date on string use the method qdate#toPyDate: data = self.dlg.data.date().toPyDate()…
-
3
votes1
answer84
viewsA: offline PHP test
See some alternatives: XAMPP: Available for Windows, Linux and OS X. Includes: PHP (5.6), Apache, Mariadb, PHP, Perl, phpMyAdmin, Filezilla, etc. LAMP: Available for Linux only. WAMP: Available for…
-
3
votes1
answer1532
viewsA: Foreach to head office
To walk the array, which is multidimensional, it is also necessary to cover the subarrays: $matriz = array(); $matriz[0][1] = '01'; $matriz[0][2] = '02'; $matriz[1][1] = '11'; $matriz[1][2] = '12';…
-
1
votes1
answer50
viewsA: Check php text theme
There are small errors in the code. $tema == "Cotidiano"; The operator == is used for comparison, use = for value assignment. for($n = 0; $n < $qtd; $n++){ $arra = array($textos[$n]); if($tema ==…
-
6
votes4
answers9085
viewsA: NOT operator in python
Python also has the operator not: def adiciona_perfis(): quantidade = 0 nome = raw_input("Digite seu nome ") nomes.append(nome) quantidade += 1 if not tem_vaga(quantidade): # Código...…
-
4
votes2
answers13268
viewsA: How to delete files in a directory with batch script?
It is possible yes. To delete files, use del. If you prefer to delete files using the absolute path, use the variable %~dp0 to obtain the folder of script and indicate the target subfolder. You can…
-
3
votes3
answers3735
viewsA: Generate random number between two numbers with Math.Random
The method Math#random returns a double equal to or greater than 0.0 and less than 1.0. int numeroAleatorio = (int) (1000 + Math.Random() * 10000); One problem with the code is that the minimum…
-
4
votes1
answer941
viewsA: How to transform Array into distinct variables?
You can go through $dados indicating the sub-array cliente: $dados = array('cliente' => array('0' => array('Code' => 1, 'Name' => 'a'), '1' => array('Code' => 2, 'Name' =>…
-
0
votes1
answer725
viewsA: Dynamic table in python
Maybe it’s because the variable c is stated within the for, at each iteration the initial value is zero, after the first iteration of the second for, add up 1, is a cycle that repeats itself with…
-
6
votes1
answer395
viewsA: Calendar.MONTH returns incorrect month
According to the documentation: Field number for get and set indicating the Month. This is a Calendar-specific value. The first Month of the year in the Gregorian and Julian calendars is JANUARY…
-
4
votes3
answers461
viewsA: How to run . sh file on button
Directly by HTML no, with PHP it is possible to do this in some ways, an option is the function shell_exec (not unlike system or exec): <form method="post"> <button type="submit"…
-
2
votes4
answers2433
viewsA: Count the number of times a character appears in a string
Another alternative is to remove the characters you don’t want by using //[^\/], after that just count the remaining characters: v_dir_relatorio="'/file/program-files/teste/dev/dev1/Central.pdf.gz"…
-
1
votes1
answer345
views -
2
votes2
answers46
viewsA: Take array data dynamically in PHP
I don’t understand why this function is returning error "mysql_fetch_array() expects Parameter 1 to be Resource, array Given in": The function DBRead returns a array with the data you want, it is…
-
1
votes1
answer116
viewsA: **kwargs optional with default
Another feature is also that the user can choose which parameters he wants to pass, and those he does not enter have values default. Assuming kwargs is a dictionary, you can use the method dict.get…
-
0
votes2
answers2039
viewsA: File extension in Base64
Use the function pathinfo: $string = "data:image/gif;base64, ...."; $baseImagem = base64_decode($string); $extensao = pathinfo($baseImagem, PATHINFO_EXTENSION); $arquivo = ''; switch ($extensao) {…
-
3
votes1
answer39
viewsA: Capture two parts of the same string?
You can use the function preg_match. Assuming the list of names is a array like this: $nomes = ['Diretoria: (aprovação 23, de 2014)', 'Diretoria: (aprovação 42, de 2015)', 'Diretoria: (aprovação 70,…
-
3
votes2
answers63
viewsA: Taking only 4 items from 1059 instead of all
items is a array of arrays, you must specify the index, I made some small changes to your code, see: function buscaUser($user) { $opts = [ 'http' => [ 'method' => 'GET', 'header' => […
-
2
votes2
answers1019
viewsA: Generate random number for an array
Another option is to use the functions mt_rand to generate a random value and count to return the total of elements of array: $dados2 = connection::select('SELECT * FROM tab1'); foreach ($dados2 as…
-
1
votes1
answer64
viewsA: Doubt about PHP array
One option is to use the function preg_match_all together with the expression |texto\d+(.+?)<\/body>|is to get the content that is between texto followed by a number and </body>, the…
-
1
votes1
answer28
viewsA: Does Mysql Arabic return?
It may be necessary to define the charset, use the function mysqli_set_charset. See an example (taken from the documentation): $mysqli = new mysqli("localhost", "my_user", "my_password", "test"); if…
-
1
votes3
answers807
viewsA: Remove row from an array
An alternative, besides the option posted by Virgilio, if you are dealing with a heavy file, is to read the file line by line, in this process you can skip lines that do not satisfy a certain…
-
1
votes2
answers3516
viewsA: How to generate random numbers at command prompt?
Another alternative is to create an alphabet with the characters you want to generate, in a loop for you use the random to randomly obtain an index and access the value of a array: @echo off…
-
1
votes1
answer212
viewsA: Use of bindingNavigator
On the estate BindingNavigator.BindingSource, inform a BindingSource: // ... DataTable dt = new DataTable(); BindingSource bs = new BindingSource(); dt.Load(dr); bs.DataSource = dt;…
-
1
votes2
answers530
viewsA: Recover return from callback
Beyond the alternative suggested by Sergio, since Distance Matrix is an asynchronous service, you can use an Promise for asynchronous processing. Take an example: function CalculaDistancia(origem,…
-
0
votes1
answer103
viewsA: Create Views in the database from function
It may be necessary to use the method MySQLConnection.commit to confirm the current transaction and save the changes. conexao = MySQLdb.connect(host = "localhost", user = "root", passwd = "pass", db…
-
4
votes1
answer1055
viewsA: Selecting All Rows from a Datagridview
Use the method DataGridView.SelectAll to select all lines: dataGridView1.SelectAll(); To select the rows of a specific column, do so, for example in click one-button: void Button1Click(object…
-
2
votes2
answers765
viewsA: Typeerror: split() Missing 1 required positional argument: 'string'
The function re.split must receive at least two arguments, regular expression and string where you will apply it. You are reporting only regular expression. Maybe that’s what you want to do: import…
-
0
votes2
answers63
viewsA: Problems with the switch
...has to do with the keyboard buffer that picks up the \n when do I enter the data? How to resolve this? Probably the cin.get must be returning beyond the typed character, the new line too. One way…
-
1
votes2
answers2984
viewsA: How to download multiple files using wget?
The syntax to do this with the wget the Marcos Célio already answered, how the question is marked with the tag php, the answer is based on that language, you can try the following: Download the…