Posts by Miguel • 29,306 points
758 posts
-
2
votes2
answers2422
viewsA: How to get a list of processes running windows in python?
I found out here a possible solution: import wmi c = wmi.WMI () for process in c.Win32_Process(): print(process.ProcessId, process.Name) Reference I did not test because I do not have windows, but…
-
5
votes3
answers52
viewsA: Character manipulation in PHP
You can do it like this, assuming there’s always gonna be a point between the names: $username = 'joao.silvestre'; $names = explode('.', $username); $final = $names[0][0].substr($names[1], 0, 7); //…
-
3
votes1
answer1154
viewsA: Add columns of a table to a total field and repeat the sum to each new row
The trick here not to add up with those of the previous line is on this line $(this).parents('tr').find('input.calcular') in which we will "ask the parent element, tr (line), what are the values of…
-
0
votes1
answer678
viewsA: How to convert a string to an integer in a socket program?
As long as you need Port be a whole, then do: Host = int(self.Txt1.get()) int() So you have to be sure that the input will be numerical, otherwise it will generate error ValueError: invalid literal…
-
4
votes1
answer330
viewsA: put variable in jquery selector
You are wrong to concatenate, you must use "" or '', but then you were using both, ie the pelicas (' ) were considered part of the selector: posicao = 2; $("tbody").find('tr:nth-child(' + posicao +…
-
2
votes4
answers10528
viewsA: Contact form with AJAX without refresh
You can do it, I took the name that you had in the form and put id: HTML: <form id="contactform" method="post" action="sendemail.php"> Nome: <input type="text" name="nome" /> </br>…
-
3
votes2
answers45
viewsA: Problem in solving javascript
With this code what I think you want is to store the elements that have these id’s of the ui array, but it will have to be a slight modification because ui is not object var ui = ['input', 'prompt',…
javascriptanswered Miguel 29,306 -
1
votes1
answer98
viewsA: Format value in Pyhton
You can do it like this: valorRaw = 'R$ 450,000.00' valor = float(valor.split('$')[1].replace(',', '')) # 450000.0 Assuming you’re sure the values always come in that format OR: valorRaw = 'R$…
-
5
votes2
answers609
viewsA: Randomly position div when loading page
You can do it like this, in order to ensure that it never leaves the Document (body): $(document).ready(function(){ const m_top = Math.floor((Math.random() * $('body').height()) + 1); const m_left =…
-
1
votes1
answer160
viewsA: What’s wrong with Twitter messaging?
You have to send the POST data in bytes: ... params = urllib.parse.urlencode( {'status':msg} ).encode("utf-8") ... .encode("utf-8")serves to make the Encode of a string 'utf-8' for bytes More…
-
1
votes1
answer235
viewsQ: Get authenticated user in constructor
After a lot of research and taking a look at documentation, I fully understand that and why can not do the "old fashioned", but wanted a solution/ workaround to do the following: I have a base…
laravel-5.3asked Miguel 29,306 -
0
votes1
answer38
viewsA: This program on Tkinter does not display its widgets. Can anyone explain why?
You were setting/configuring your widgets in your class Autenticar but you weren’t instating it anywhere, I’ve improved the structure of your code a little bit, do it like this: from tkinter import…
-
1
votes2
answers1142
viewsA: Alternatives for storing and analyzing data
For this example I put (stored) exactly the data you put in a file and went through it and removed the data, this file being (tests.txt) is in the same folder as the file with the code, you can also…
-
4
votes3
answers1464
viewsA: How to change the text of a link after clicked?
Solution with javascript, you can do so: const link = document.getElementById('my_link'); var less = false; link.addEventListener('click', function(){ this.innerHTML = (less = !less) ? 'Mostrar…
-
2
votes3
answers2432
viewsA: How to speed up a script to full speed in python?
I was able to optimize, running with python 3.5, the running time in +- 1.2 secs. What I did to measure the running time was: from math import sqrt from random import random import time start_t =…
-
4
votes4
answers843
viewsA: How to limit the generation of pseudo-random numbers to non-zero and non-repeating numbers?
Here’s another alternative, using a set, this by default implemented in the python language itself already avoids duplicates. In the example below n is the number of entries you want on your new…
-
1
votes1
answer250
viewsA: Upload . txt to Mysql database
Try this: $file = fopen('../files/docs/libs/newUsers.txt', 'r'); while(!feof($file)){ $data = explode(';', fgets($file)); // separar valores pelos ; que estão no ficheiro $query = mysqli_query($con,…
-
3
votes1
answer73
viewsA: Problem consuming Json with javascript
The problem is that the server/page you are trying to consume the data from does not have any authorization, Access-Control-Allow-Origin, to send the data to the server that is requesting it with…
-
3
votes1
answer979
viewsA: Wrong login and password with php
This gives that "the password is wrong" because you in the BD have 1234 in "Plain-text" and then you will compare with a hash (md5(md5($_POST['senha']))) , that is, the password you have stored in…
-
0
votes1
answer146
viewsA: Get all the data from INNER JOIN
Try this, SELECT suporte.*, login.*, radius_acct.* FROM suporte INNER JOIN login ON login.cliente_id = suporte.cliente_id INNER JOIN radius_acct ON radius_acct.USERNAME = login.user WHERE…
-
8
votes2
answers1126
viewsA: Password encryption on MD5?
MD5 is no longer reliable, it is a hash function that is already obsolete. If by chance an attacker has access to your BD and extract the hashes just use this,…
-
8
votes2
answers4843
viewsA: How do I add hours to an hour
To guess an hour you can do like this: $timestamp = strtotime('10:15') + 60*60; $dataHora = strftime('%d - %m - %Y, %H:%M', $timestamp); // 24 - 12 - 2016, 11:15 To add 30 mins: $timestamp =…
-
3
votes2
answers126
viewsA: How do I know the time and date of a location with PHP?
You can do it like this: date_default_timezone_set('Europe/Lisbon'); $dia = date('Y-m-d'); // 2016-12-24 $hora = date('G:i'); // 16:29 DEMONSTRATION Note that in the demonstration, the time is not…
-
2
votes2
answers939
viewsA: Generate a random profession for Online Players
What you have to do is to save on the server side the professions that have already left, in this case I choose at random one of the 3 principles and then delete the chosen one, when some socket…
-
0
votes1
answer78
viewsA: Insert data into database
From what I understand your connection is not on the same page, nor does it matter, where you try to enter the data, try the following, and see if there is an error: ... <?php…
-
5
votes1
answer115
viewsA: Error in the database
By the action of your form, the php part must be inside the file cadastrando.php. Errors later, if I’m thinking about it, you can solve with a simple check of the http method that was used to make…
-
0
votes2
answers1025
viewsA: Sum with SUM()
It could also be the following: in config/database.php: Change to this: ... 'strict'=>false ... So that you do not default to GROUP in the query…
-
7
votes2
answers3252
viewsA: How to use sys.Arg for data entry
It actually depends on what you want. If it’s the best way or you wouldn’t have to put more code. Imagine you run the code like this $ python tests.py arg1 arg2 To use argv can: import sys if…
-
5
votes1
answer116
viewsA: How to create parent element?
You can do it like this: $('p').wrapAll('<a href="#" />'); <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <p>texto</p>…
-
0
votes1
answer165
viewsA: Create a modal on the site
You can activate the modal "manually": $('#myModal').modal('show'); <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"…
-
2
votes2
answers230
viewsA: Is there a way to clear the field formatting before going through validation?
Here’s what you can do: use Validator; ... public function rules() { Validator::extend('cnpj_unique', function ($attribute, $value, $parameters, $validator) { $value = str_replace(['-', '/', '.'],…
-
4
votes1
answer26
viewsA: Database data comes incomplete
So you’re rewriting the value and you end up with only the last returns in the last loop, do this: ... $return = array(); while ($linhaCateAdmin=$pegaCategoria->fetch(PDO::FETCH_ASSOC)) {…
-
1
votes1
answer863
viewsA: Lower() and strip() methods
All right, for the whole sentence in uppercase it would be: frase.upper() For the sentence without spaces: frase.replace(' ', '') Explanation: As for the letters you wanted to capitalize you were…
python-3.xanswered Miguel 29,306 -
2
votes1
answer490
viewsA: Regex in python Find() function
With the function find() I can’t, but here’s what you can do: import re var1 = "abc" var2 = "def" var = 'abc1dois3quatro5def' # aqui e o conteudo do teu ficheiro, arq.readline() match =…
-
5
votes2
answers117
viewsA: How to call different modals, without using database
You can take advantage of the HTML 5 date attributes: $('.list-group-item').on('click', function(e) { const to_append = '<ul><li><i class="fa2 fa-calendar"></i><span…
-
1
votes2
answers3430
viewsA: Check if input file is filled
You can do it like this: if ($_FILES['Arquivo']['error'] == 4): $retorno = array('codigo' => 0, 'mensagem' => ' Informe o arquivo para Upload'); echo json_encode($retorno); exit(); endif; The…
-
3
votes1
answer356
viewsA: How can I change file attributes in windows with python?
In windows you can do so: import ctypes FILE_ATTRIBUTE_HIDDEN = 0x02 ret = ctypes.windll.kernel32.SetFileAttributesW('CAMINHO/PARA/FICHEIRO.txt', FILE_ATTRIBUTE_HIDDEN) if ret: print 'Ficheiro…
-
1
votes1
answer906
viewsA: How to add an array within an array?
You are missing something, which is "[]" at the end of the variable name where you want to insert the new array: We have: $regras = array( array( 'field' => 'cpf', 'label' => 'CPF', 'rules'…
-
0
votes1
answer21
viewsA: How to save form data only if it comes from a particular website?
You can check the sender domain like this: $_SERVER["HTTP_REFERER"]; // http://www.exemplo.... But I have to warn you that this is an editable parameter in the request, one can 'fake':…
-
5
votes3
answers2214
viewsA: Add html with jquery
What you’re looking for is append, adds inside element after all: $("body").append('ddd'); Or prepend which adds inside the element but first of all: $("body").prepend('ddd'); Example:…
-
4
votes2
answers58
viewsA: Syntax error on another machine
The problem is in context manager (with ...) which does not exist before python 2.5, try the following: saida = open('file.txt', 'r') lines = saida.readlines() for line in lines: if "]L" in saida:…
-
2
votes2
answers439
viewsA: Json path to get api value
You can do it like this: $json_file = file_get_contents("https://economia.awesomeapi.com.br/json/USD-BRL/1"); $dados = json_decode($json_file); echo $dados[0]->low; // 3.367 DEMONSTRATION You can…
-
1
votes3
answers150
viewsA: Value loses content as soon as it exits ajax
Yeah, that’s because alert(nomeResponsavel); is executed before the return of the ajax request, anything you wanted to do with that value must be within the success or completed of the obj that you…
-
8
votes3
answers156
viewsQ: Difference in behavior between for and for.. in
I have the following code that works exactly as expected (which is to go through the array, showing ONLY each element, in this case "Miguel" and "Celeste"): var runners = ['Miguel', 'Celeste'];…
-
1
votes2
answers1121
viewsA: Why in the textarea with height defined the text is not centered vertically?
Adds vertical-align: middle and inserts a line-height equal in both elements, so that they are aligned vertically input, textarea{ height: 60px; vertical-align:middle; line-height: 60px; } <input…
-
4
votes3
answers9438
viewsA: Delete confirmation with bootstrap
Look here, you can do that, you just have to adjust the button link to wherever you want: <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"…
-
3
votes2
answers136
viewsA: "Robo-Human" Intelligent
You can do it like this: $frase = 'Olá, qual seu nome?'; $ola = stripos($frase, 'olá') !== false; // cada uma destas vai ser true ou false $nome = stripos($frase, 'nome') !== false; $adeus =…
-
1
votes1
answer133
viewsA: Random ads with view counter
You can store that information in a database, this solution won’t cover that, this I’m going to focus on storing that information in a file, which is one of the ways to do that: <?php $imagens =…
-
5
votes1
answer5730
viewsA: Please provide a Valid cache path
As stated in this answer, tries to create directories, in Storage/framework: Sessions views cache Maybe they are missing. This, still feels that you can execute the command: composer install…
-
5
votes1
answer918
viewsA: Dictionary reordering, exchanging values for keys
Then we have: tests_dict = {'test 1': ['Manuel', 'Mariana', 'Filipa'], 'test 2': ['Manuel', 'Filipa', 'Mariana'], 'test 3': ['Mariana', 'Manuel', 'Filipa']} You can do it like this: 1. This first…