Posts by Miguel • 29,306 points
758 posts
-
2
votes2
answers278
viewsA: Change the website background daily automatically
It is possible, in the following example I do a background for each day of the week: var images = [ 'https://www.cleverfiles.com/howto/wp-content/uploads/2016/08/mini.jpg',…
-
0
votes1
answer1623
viewsA: Sending Server Data to Client (LOCAL)
In case it is option 2 your function was not returning anything, you must return or the error happens, besides being poorly positioned. You also weren’t sending as an answer to the customer at…
python-3.xanswered Miguel 29,306 -
3
votes1
answer179
viewsA: How to get the array number of the element I clicked JQUERY?
You can do with index(): $('div').on('click', function() { alert('O elemento encontra-se na posição ' +$(this).index()); }); <script…
-
1
votes1
answer95
viewsA: Reverse loop Selenium python
I really don’t understand the problem that’s happening to you, it would help if you added your code, but here’s an example: from selenium import webdriver driver = webdriver.PhantomJS()…
-
4
votes1
answer381
viewsA: Why aren’t my custom error pages being called?
I think that at the beginning the error is in the path to the errors folder, this must be in resources/views/errors. Test example: - Creates file 404.blade.php inside the folder I mentioned above -…
-
3
votes3
answers2297
viewsA: Python 3 make the program find out how much of a given digit is in a string or a number
Extending the answer of @Wéllingthon M. de Souza who answered and well to your question, here are two alternatives in case you want to count all characters: from collections import Counter frase =…
-
3
votes1
answer200
viewsA: Bar chart made in Python became "weird". Any suggestions how to improve it?
The problem is the gap you had for the axis of y, n-200 as a minimum value, and it would be negative since the spectrum of your values is in the range 0 <= y < 10. Thus it works well, tested…
-
2
votes1
answer115
viewsA: Graph of a Python denial of service attack
Here’s what you can do: import matplotlib.pyplot as plt import matplotlib.dates as dates from datetime import datetime, timedelta x = [] y = [] with…
-
1
votes2
answers2014
viewsA: How do I read two columns of a . dat file in Python?
You didn’t specify the final format that it should have, but I’m going to assume that it’s a list of several sub-lists, each of which has the second and third column data. You can do it this way:…
-
2
votes2
answers48
viewsA: Avoid error while recovering Json field
So you can avoid making a mistake as follows: <?php $json = '{ "Autenticacao": [{ "login": "123", "senha": "123" }] }'; $obj = json_decode($json); if(!isset($obj->Autenticacao->login)) { //…
-
1
votes1
answer172
viewsA: Random search
You must also place your ordination in this case ...('users_destaque', 'DESC'). Try the following, Laravel versions < 5.2: User::orderBy('users_destaque',…
-
4
votes2
answers623
viewsA: apt-get install -y <program> What is the -y option for?
-y is by convention to automatically answer yes (yes) questions that may arise during the installation/update. Whenever you see this flag in the delegating command a particular process is very…
-
2
votes1
answer3155
viewsA: How to clear Windows Python interpreter screen?
Based on these sources (fonte1, fonte2), being windows you can do: import os os.system('cls') If it were linux it would be: import os os.system('clear') I didn’t test it, but I believe it will work…
-
1
votes1
answer99
viewsA: how to give two splits on a txt
I don’t know how you’re opening the file, but here’s what I think is the best way: with open('FICHEIRO.txt') as f: for line in f: nome, apelido = line.split(':') # nome = Rafael, apelido.split() =…
-
3
votes1
answer697
viewsA: How do I get the final URL of a JS redirect?
Curious this strategy in this kind of services, is very well played to avoid precisely what you want to do. Here’s what’s going on. It seems, but it is not a redirection (code 301), that is, when…
-
4
votes2
answers6824
viewsA: Automatically create vector in Python
You can use the module Random to generate random values: If you do not want repeated values: import random x = 5 saida = [] for _ in range(x): saida.append(random.choice(range(100))) print saida #…
-
2
votes1
answer52
viewsA: How to put data in the session flash when redirecting to Silex?
According to this example, you must register SessionServiceProvider: $app->register(new Silex\Provider\SessionServiceProvider()); After registering the functionality you can already:…
-
3
votes1
answer4380
viewsA: How to limit the size of a div
You can add in css: .itemsatuais .item:nth-child(n+11) { display:none; } You’re basically saying you only want the first 10 .item visible .itemsatuais{ background-color:#263238; width:95%;…
-
1
votes2
answers53
viewsA: Find key and corresponding value in text file
The flag on $pos must be in false not to include what comes before, taking advantage of your example: <?php $text = file_get_contents('animals.txt'); $id = "2"; $id_str = strlen($id); $pos =…
-
3
votes3
answers447
viewsA: Prevent cookies from being viewed/obtained with javascript
With the help of a colleague from here who indicated a path where to start, I found out and even liked knowing that yes, it is possible to obfuscate and prevent a cookie from being read/obtained by…
-
9
votes3
answers447
viewsQ: Prevent cookies from being viewed/obtained with javascript
I was reading an article and I found curious a sentence of this, where the author makes a list (right in the first paragraphs of the article) of the main safety care that we developers should take…
-
1
votes2
answers136
viewsA: Error whenever using max python function 3.6.1
The error has nothing to do with the function max() but with the way you are doing the print, in python 3.x it is required that there is parentesis to execute the print: lst=[6,10, 2, 1, 9, 35]…
-
1
votes1
answer413
viewsA: Testing if a String is inside a File. txt
The method readline() returns only one line of the file, you could use the readlines() that returns a list of all, where each element is a line, or the way below (using a generator): nome = input…
-
3
votes1
answer2796
viewsA: Transfer of python files, client-server
I suggest to transfer data structures use json or pickle, although with json the serialization can be faster. That being said, this question unintentionally becomes a bit of a blatant/challenging.…
-
17
votes3
answers6745
viewsA: How to validate whether it is a vowel without writing all the letters of the alphabet
For this you are far from needing one while... or having all the letters of the alphabet. You’re also making the mistake that you don’t store the input in a variable, and you don’t need to turn it…
-
3
votes1
answer963
viewsA: How to check route parameters in Laravel and accepted only specific parameters?
There’s no way that’s the best solution in this case. For this you can put the check in the controller, or in a simple way on the route as mentioned in the question: Route::get('/fotos/{user_id}',…
-
19
votes4
answers18311
viewsA: How to flip (mirror/flip) an image
It is possible yes, with the property tansform: scaleX(..) you do that easily: img { width: 260px; } #esquerda { -moz-transform: scaleX(-1); -o-transform: scaleX(-1); -webkit-transform: scaleX(-1);…
-
7
votes4
answers392
viewsA: Program that returns the unusual numbers of two lists (python)
Here’s a way equivalent to @nano’s reply: nao_comuns = list(set(a) ^ set(b)) But in a didactic way and programming the functionality you can do without using two cycles (I commented in the code some…
-
1
votes1
answer5400
viewsA: pq the while True loop accesses if and Else in sequence to every complete loop in that code?
It does not enter the two (if and Else) in the same round of the cycle. The "problem" is that since while True... it will do several laps, entering if (if the condition is verified) and descending…
-
4
votes1
answer1800
viewsA: Relationship Many-to-Many Laravel 5
In the Commission.php model you should make your relationship : ... public function parlamentares() { return $this->belongsToMany('App\Parlamentar', 'composicao_comissao', 'cod_comissao',…
-
2
votes1
answer78
viewsA: Problem in understanding this structure in a python string
According to the DOCS (was also unaware of this possibility of print()) that argument in this case will write from inside a file, ex: print("import base64, bz2, os", file=open('tests.txt', 'w'))…
-
9
votes4
answers10562
viewsA: Performatively calculate the divisors of a Python number
Tip: Don’t use list comprehensions to perform functions such as the print(), append() etc... will create a temporary list full of values None, and has performance implications if this is too big,…
-
2
votes1
answer165
viewsA: How to copy everything from a website and save to a txt file
You can do with Curl like this: <?php $curl_handle=curl_init(); curl_setopt($curl_handle, CURLOPT_URL,'http://steamcommunity.com/profiles/76561198337627631/inventory/json/730/2/');…
-
2
votes1
answer850
viewsA: How to submit when pressing ENTER on a Qlineedit?
You can use the returnPressed to do this, to connect the event to the method: ... self.textChat = QtWidgets.QLineEdit() self.textChat.returnPressed.connect(self.onSubmitText) ... Or set to have a…
-
5
votes5
answers29639
viewsA: How to convert an int number to string in python?
To reverse the string that returns from input(), which already returns a string and not an integer, you can do so: num = input("introduza um num") # '123' revertido = num[::-1] print(revertido) #…
-
2
votes2
answers513
viewsA: How to open file by separating each line into an item from a list/tuple?
Do it like this: with open('file.txt', 'r') as f: list_lines = f.readlines() # [' 1 linha \n', ' 2 linha \n' ...] To remove line breaks and/or extra spaces, tabs from the end/start of the line do:…
-
11
votes2
answers1038
viewsA: How to remove tags in Python text?
There are several ways, but I don’t think there’s any better way to fulfill this role than Beautifulsoup: >>> from bs4 import BeautifulSoup as bs >>> bs('<p>hey<span>…
-
5
votes2
answers327
viewsA: Identify if the value being printed is float, string or int
To know the type/class we can do (type): print(type(3.4), type("hello"), type(45)) # <class 'float'> <class 'str'> <class 'int'> To filter only the part of the float, str, int can:…
-
1
votes1
answer812
viewsA: Check if there is a file inside a specific directory
Here’s what you can do, using os.pathexists.: import os file_path = "C:/imagex/jonsnow.png" if os.path.exists(file_path): # existe seja arquivo ou diretorio To check only files you can do: ... if…
-
1
votes1
answer634
viewsA: Call Counter Socket.io
You must issue an event with the same name (it can also be with another but in this context it is more indicated to be with the same), since your client side has no delegated event for when it…
-
2
votes1
answer316
viewsA: Problems with the time interval on a carousel
Deep down, what’s going on with the first lap is that she’s going to do the following: carouselBannerHolder.style.left = ("-000%"); because Count is still 0, that is this return apparently takes…
-
7
votes1
answer271
viewsA: Contrary to appendHTML - how to do?
You can do it alone: document.getElementById('grupoExt').innerHTML = ''; That with jQuery it would be: $('#grupoExt').html(''); With jQuery You also have the functions: remove(): $('#grupoExt…
-
5
votes2
answers3090
viewsA: Function that returns the smallest prime number in Python
In relation to function maior_primo, you can rewrite it to the following: def maior_primo(n): for num in reversed(range(1,n+1)): if all(num%i!=0 for i in range(2,num)): return num…
-
2
votes1
answer535
viewsA: Python - Tkinter Module
You have to create a menu (add_cascade) also for the menu Ambiente, and then just add the items: class Random: def __init__(self): janela = Tk() janela.geometry("1024x720") janela.title("Sorteio de…
-
3
votes1
answer40
viewsA: I always want to delete the first index every time I click a button. How do I do it?
Your code is a little fuzzy and it doesn’t match what you ask for in the title, here’s what you ask for in the question heading: var first_ele; var btn = document.getElementById('btn'); var nome =…
-
5
votes5
answers789
viewsA: List comprehension with conditional
To count the elements of a list that satisfy a certain condition, taking into account the question title ("list understanding") you can do: seq = [1,3,4,21,10,30,10,24] max = 10 cont = len([x for x…
-
2
votes1
answer380
viewsA: Interval calculation of 2 dates
I could do better with your code if you put it in the question as well. If it is this daterangepicker that you’re using can do so to calculate the days of difference: const milis_day = 1000 * 60 *…
-
7
votes2
answers79
viewsA: Separate the string value
Do it on the client side (no js), you can just do it: responseText = '24.95, <strong> Outro texto, </strong>'; // faz de conta valorFrete = parseFloat(responseText) alert(valorFrete);…
-
11
votes2
answers2648
viewsA: What is a shebang?
Yes, it has most Linux distributions. Indicates the interpreter that should be used to run a particular program/file. Important (Remembered by our colleague @Wtrmute): Because the "#" character is…
-
11
votes1
answer507
viewsA: Custom HTML attributes
It’s not good practice. To combat this HTML5 has brought us a means to achieve what you want (custom attributes) are called data-*, where you can do data-blahblah and save yourself any trouble that…