Posts by Miguel • 29,306 points
758 posts
-
2
votes2
answers397
viewsA: Calculate how many Nan in each Python time
I’m not sure what the format is really like in hd5 (I researched but I couldn’t figure it out), if it’s like what you put instead of doing ...split(',') as I do in the examples below ....split(' ')…
-
1
votes1
answer189
viewsA: How can I margin-top a div?
The best thing would be to get the internal Ivs into position absolute: #container { position: relative; /* importante */ } div.inner { width: 100px; height: 50px; position: absolute; }…
-
3
votes1
answer1416
viewsA: Calculate a Python string
Assuming you will be careful with the inputs you receive the simplest way is: var = '1+2' print(eval(var)) # 3 var = '5*3' print(eval(var)) # 15 As @jsbueno said well, you can use Ast.literal_eval,…
-
4
votes1
answer300
viewsA: Apache logs: checking a slowloris attack
There are two relevant logs you might want to check: error.log, all errors that may have occurred in the service, usually in /var/log/apache2/error.log access.log, access logs (hours, source ip,…
-
2
votes1
answer4477
viewsA: How do I put the div at the top of the page by tapping right at the top
What you just have to do is put your body with margin: 0;, this one for default has a margin of 8px (if I am not mistaken): body{ background-image: url("imagens/fundo.png"); background-repeat:…
-
2
votes1
answer44
views -
4
votes3
answers879
viewsA: Store in the database or in sessions
There is a problem with using only session, is that this default lasts very little time (in general the lifetime of a session is 24mins), I can put it in the cart now, I will talk/ask my…
-
0
votes2
answers71
viewsA: Javascript updates several inputs
I added the class evento to checkboxes for easy selection (but also gives $('input[type="checkbox"]'), if you’re sure it’s just those), and data-val inputs to store the original values var val_p,…
javascriptanswered Miguel 29,306 -
2
votes1
answer997
viewsA: Blade in Laravel 5.4 - How to work with class="active" in the menu links of a page in this scenario?
I usually send this as a variable from the controller: public function pg2() { ... return view()->with(['active' => 'pg2']); } In view: <a href="#" class="@if($active == 'pg1') active…
-
6
votes2
answers9138
viewsA: How to make a request with Curl
I must tell you that the error will remain when using the same beliefs (apparently the beliefs are invalid), to make a Curl with php you can: $url =…
-
1
votes1
answer1139
viewsA: Error: An operation has been attempted on an item that is not a socket!
You must redo/create another socket for a different connection, I also set the code a bit based on what you put: import socket host = 'google.com' rg = range(70, 100) open_ports = [] def…
-
1
votes1
answer71
viewsA: Reading Json with PHP
Do it like this: $json = '{"message":"Oi Gente","report":[{"0":[{"port":"gsm-2.3","phonenumber":"00000000000","time":"1970-01-08 10:00:26","result":"fail"}]}]}'; $json_dec = json_decode($json,…
-
2
votes1
answer262
viewsA: REGEX to Select a line that contains an unmounted string
With python it’s relatively easy, you don’t even need to use regex: str_desejada = 'LED AZUL deve acender' for linha in linhas: if str_desejada in linha: print('existe') Regex: import re linha = 'Ao…
-
2
votes1
answer212
viewsA: How to place a GET order on each line with jQuery
I think that this work, given that it is to divide the found from the found and send as an answer, should stay on the server side: check.php: if(isset($_GET['nomes'])) { $arrNomes = explode("\n",…
-
0
votes1
answer18
viewsA: Display a certain vector in a 2D list
I may have misunderstood, but if you only want to access the first vector go to the index of that vector on the shortlist: lista_1 = [[250, 27.65863337187866, 93.38094023943002, 27.65863337187866],…
-
3
votes1
answer880
viewsA: Create a Python list copy so that they are independent
DOCS The Difference between Shallow and deep copying is only Relevant for compound Objects (Objects that contain other Objects, like lists or class instances): The difference between shallow and…
-
3
votes2
answers265
viewsA: Redirect to browser language based subdomain
You can do the following (put this only on the site in English, which is the default, to not go into infinite loop): const sites = { 'pt-br': 'http://br.site.com', 'it': 'http://it.site.com', 'es':…
-
0
votes1
answer132
viewsA: Input('type=number'). each(Function()) )}; does not recognize value only returns Nan
You should check if it’s number before incrementing: validar = function() { var soma = 0; $('input[type=number]').each(function() { //number devido ao código gerado pelo jquery mobile. var val =…
-
0
votes3
answers314
viewsA: How to count the number of candidates on this page ? Python 3.6
If only to find out how many candidates there are: import requests from bs4 import BeautifulSoup as bs req =…
-
4
votes1
answer31
viewsA: Instructions that depend on variables coming from "for" loop, need to be executed in callback?
Yes, you can trust, for the case that you presented the browser (browser) does not "skip" the for and if will only be executed when it is finished, simply does not enter your condition because the…
javascriptanswered Miguel 29,306 -
4
votes3
answers331
viewsA: Avoiding code duplication without the use of switch/case in the Python language
I think you’re doing things unnecessarily: Can you narrow it down: data_hoje[1:2] + data_hoje[2::] # 1 Mar 2017 for: data_hoje[1:] # 1 Mar 2017 It seems to me here that you are just checking if the…
-
1
votes1
answer385
viewsA: Python: problem with list
The problem is on this line: ... lista.remove(lista[-1]) ... It’s because of the fact that remove() remove the first occurrence of the element, i.e., for inputs, "2,2,5,2", obtained: 2 2 2 5 On the…
-
3
votes3
answers691
viewsA: Python 3.6 regular expression for inteitra phrase extraction
I’ve been waiting for someone who actually knows about regex to respond but I’m gonna give you a different solution (and in many cases best, best): from bs4 import BeautifulSoup as bs string =…
-
4
votes1
answer529
viewsA: How to pass a parameter/variable on the initialization of a PHP class?
Uses a builder: class User { protected $id; public $dados; public function __construct($id) { $this->id = $id; // aqui já tens o teu id // echo $this->id; // vai imprimir 4 e podes fazer o que…
-
1
votes1
answer979
viewsA: Sending POST with Python via Curl
"I want to turn the form into a URL to run in backend"?! You have some concepts to work out, and we’re here to help you get that. What you’re doing is not using Curl, it’s using a library (urllib)…
-
14
votes3
answers14315
viewsA: Pythonic way of defining setters and getters
Exists exactly that question in so en. If you really need setters and getters, you should use them through Property, ex: class Pessoa(object): def __init__(self, nome, idade, salario): self._nome =…
-
2
votes2
answers202
viewsA: Displaying certain vectors in a 2D Python list
You can do it like this: def funcao_fitness(): fitness = [] vetor_distancias = [[10,20,30,40],[50,60,70,80],[5,6,7,8],[100,200,300,400],[9,15,25,30]] for subl in vetor_distancias: if sum(subl) <=…
-
3
votes1
answer53
viewsA: Displaying certain values in Python
The best way is to use a dictionary, in which each key can be the position of the corresponding value less than 100: from random import randint pos = {} for idx, val in enumerate(range(400)):…
-
2
votes1
answer693
viewsA: How to allow only a range of numbers?
You can do it like this: while True: nota_1 = input("Digite a primeira nota de " + str(aluno_1) + ": ") try: nota_1 = float(nota_1) except Exception as err: print("Valor deve ser númerico") else: if…
-
8
votes1
answer168
viewsA: How to organize an array of a list
From the beginning we know the ante-hand keys: $original = array( 'nome_e_sobrenome' => array( 'Luiz Felipe Machado', 'Maria Rita de Cássia' ), 'usuario' => array( 'luizf', 'mariar' ), 'senha'…
-
3
votes2
answers418
viewsA: Browse 2D list in Python
Cycle is inside the other (nested): for sublista in lista: for item in sublista: print item Or if you don’t need to do anything to the sublists you can just make the list flat: print…
-
4
votes3
answers2089
viewsA: Get the site name in the javascript url
Do the following from the domain name (window.location.hostname): var url = window.location.hostname; // obter o dominio var url_splt = url.split('.') var url_name = url_splt[url_splt.length - 2];…
-
0
votes1
answer1559
viewsA: How to print a. txt file in Python
Try this, it’s another approach to writing in the file: #Salvando em txt text = '' text += "DADOS DE " + str(nome1).upper() dados1 = registro() text += "\nMatrícula : " + dados1[0] + "\nTelefone: "…
-
1
votes2
answers985
viewsA: Add parameter at end of link with jQuery
Links is an object that contains all the elements, you must go through the a[href*="google.com"] and change one at a time. var param = 'SoUmParametro'; var src; var links =…
-
3
votes1
answer438
viewsA: How to sort by two parameters with Laravel 5.4?
Try it this way: $this->where('avaliacao_id', $id_avaliacao) ->orderBy('nota', 'desc') ->orderBy('data_admissao', 'asc') ->get(); You can invoke orderBy as often as you want…
-
1
votes1
answer449
viewsA: How to select and print a value within a list created by a "def"
What function returns is not a list, it is a tuple (think of it as an immutable list). Your variable aluni, may cease to exist, on that piece of code is serving no purpose. As for your doubt, why…
-
2
votes1
answer264
viewsA: Extract data from a calendar with Python and Beautifulsoup (under Linux Ubuntu-like)
Try this: import requests, time from bs4 import BeautifulSoup as bs url_post = 'http://www.purebhakti.com/component/panjika' headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)'}…
-
2
votes2
answers564
viewsA: How to put texts in Progress
With only css/html I don’t know how it would be, but here’s a solution with javascript: var elem = document.getElementById("progbar"); var width = 1 var timer = setInterval(function() { if (width…
-
2
votes3
answers9296
viewsA: How to make a countdown timer with Html5+css+javascript, which at the end of the selected time tap(or run) a *.mp3
For this just javascript, in this case starts past 3 secs: const audio = new Audio('http://homes.dcc.ufba.br/~leotavo/index.html/mp3/Coldplay%20-%20Clocks.mp3'); var timer = setTimeout(function() {…
-
0
votes1
answer901
views -
1
votes1
answer50
viewsA: Recognize loop for from other python scripts
In my opinion it is not good to declare a function inside an open file, (works but I think it is not good practice). You can do it like this: import re def recherche_boucle(): boucle =…
python-3.xanswered Miguel 29,306 -
6
votes1
answer1969
viewsA: How to receive multiple socket requests on one server?
The answer to your first point is "yes", the server can accept and process more than one connection we have is to prepare it for that. In this example the server can handle a single connection, but…
-
3
votes1
answer47
viewsA: Create arrays according to "exploded" strings
Is this: $arrayCategorias = array( '1-6', '1-7', '2-9', '3-2', '3-5' ); $newArr = array(); foreach($arrayCategorias as $key => $val) { $num = explode('-', $val)[0]; $newArr[$num][] = $val; } echo…
-
3
votes1
answer1787
viewsA: View and hide images with Javascript
I think you’re complicating a bit, there’s no need for so many operations (starting from the beginning that this is what you want), try it like this: const imgs =…
-
4
votes2
answers280
viewsA: I need help on a python Crawler
If the problem is just the fact that in the end there’s duplicate information inside your items you can check if it already exists before making the append: ... item["title"] =…
-
3
votes1
answer496
viewsA: Python - Problem printing inside a loop
You were going through the list of possible choices, and comparing each value ('rock', 'paper', Scissor) with what the user put, now he would always stop at something that the user had not put.…
-
1
votes2
answers764
viewsA: use variable cmd command with python
You can do it like this: import os with open('nome.txt', 'r') as f: nome = f.readlines()[0].strip() cmd = os.system('netsh wlan export profile name="{}" folder="G:\WLess" key=clear'.format(nome))…
-
1
votes4
answers6292
viewsA: Recover matrix dimensions in Python
Here’s what you can do: tam_matriz = (len(minha_matriz), len(minha_matriz[0])) This is gonna be a tuple, in this case: (2, 3) You can print like this: print('{} x {}'.format(tam_matriz[0],…
-
4
votes3
answers2989
viewsA: Make field mandatory depending on response
You can do it like this: const camp1 = document.getElementById('campo1'); const camp2 = document.getElementById('campo2'); const btn_sub = document.getElementById('btn-submit');…
-
2
votes1
answer647
viewsA: update Combox after closing the modal bootstrap
I guess this is it, if I understand correctly. $("#myModal").on("hidden.bs.modal", function () { var new_val = $('#novovalor').val(); $('#materia').append('<option selected>' +new_val+…