Posts by Thiago Krempser • 1,878 points
66 posts
-
0
votes0
answers21
viewsQ: Date creation from a string
I’m trying to create a Date object from a string of type yyyy-mm-dd. Testing on a javascript console, for example: new Date("2021-06-20") The exit is: Sat Jun 19 2021 21:00:00 GMT-0300 (Brasilia…
-
8
votes2
answers196
viewsQ: Why do I need to use an application server with Django?
Why it is necessary and what is the advantage of using an application server, such as Gunicorn, in a production environment? It would be possible to use only Django talking directly to the server,…
-
0
votes1
answer50
viewsQ: Should I upload to my Git repository the static files generated by Django’s collectstatic?
After generating the static files from my web app using: python manage.py collectstatic I am in doubt if I should send or not the content generated in the directory static/ to my repository. It’s…
-
-1
votes1
answer38
viewsQ: Does the INTERNAL_IPS variable control the Django DEBUG variable?
My Django application should run two environments: one for development and one for production. When running in the development environment, access to application by 127.0.0.1 and when production…
djangoasked Thiago Krempser 1,878 -
0
votes1
answer628
viewsQ: Doubt about the use of "Row" and "col" classes in Bootstrap
I’m using Bootstrap 4 for my frontend and I was wondering if I should always put all my HTML content inside a div with class col that in turn should come within a div with class row. For example, it…
-
9
votes2
answers1359
viewsA: Should I commit my virtualenv to Github?
I don’t recommend that you upload your virtual environment to your Git repository. Instead, use the command pip freeze to get a list of all packages used in your virtual environment and save the…
-
10
votes1
answer1138
viewsQ: Why does Bootstrap 4 use "rem" and "em" instead of pixels?
As you can see here and here, Bootstrap 4 uses the drives rem and em instead of using in px. Code snippet using the unit rem: $display1-size: 6rem !default; $display2-size: 5.5rem !default;…
-
0
votes2
answers61
viewsQ: Doubt about class assignment and ids
Is there any good practice that guides the order I should define the id and the class of an HTML element? I know it doesn’t matter what order the browser renders, but there is some code style guide…
htmlasked Thiago Krempser 1,878 -
-1
votes1
answer591
viewsQ: How to convert . svg icons to a font?
There is a recommended way to convert and combine various icons in the format .svg in a single source file (ttf, woff, etc.)? I want to define a @font-face and assign my font, so that I can use your…
-
2
votes2
answers83
viewsA: Remove an attribute from the <a> element when there is a specific attribute - jQuery
You can pass the element that was clicked as parameter to its function, try so: <script> function funcao(numero, el) { $(el).removeAttr('onClick'); $.ajax({ type: 'POST', url:…
-
1
votes3
answers500
viewsQ: What’s $(this.hash) in jQuery for?
In the code below I came across the syntax $(this.hash): $('a').on('click', function(e) { e.preventDefault(); $(this.hash).show(); }); I got a little confused thinking it might be something related…
-
-1
votes3
answers500
viewsA: What’s $(this.hash) in jQuery for?
Be for example the HTML code below: <a href="//exemplo.com#teste"> The $(this.hash) will read the property href of the element <a>, returning the # together with the text that follows…
-
2
votes1
answer96
viewsA: How to import fonts locally in css?
Use the @font-face CSS is a good alternative. Assuming your project has the following structure: site/ ├── css/ │ └── styles.css ├─── fonts/ │ ├── Oxygen-Regular.eot │ ├── Oxygen-Regular.svg │ ├──…
-
2
votes2
answers476
viewsQ: Centering dropdown menu in Bootstrap 4
By default, the dropdown component menu of Bootstrap 4 is left-aligned with the button that opens it: I need to align the dropdown menu with the center of the button so it looks like this: I found…
-
3
votes3
answers2125
viewsA: Format Time in a Python data frame
Assuming you have the time on string, you can convert to an object datetime, making: from datetime import datetime hora_string = '18:34:23.123' # Valor da primeira linha objeto_datetime =…
-
0
votes2
answers594
viewsA: How to remove all text within a parenthesis?
You can do it like this: texto.replace(texto[texto.find("("):texto.find(")")+1], '').strip() Who will return: 'bla bla bla'
-
5
votes1
answer138
viewsQ: The spread of Ecmascript ... arr is an operator?
I’ve seen articles referring to spread as "spread syntax" and as "spread operator" (for example here). I understand that an "operator" is "a function that takes arguments and returns a single…
-
2
votes4
answers2928
viewsA: Uppercase HTML vs CSS
By directly using uppercase letters in HTML, you would certainly save on the browser’s task of having to render the CSS rule. But I think this difference in render time is very irrelevant. Another…
-
2
votes2
answers740
viewsA: Shell Script - insert variable in a command
You can use parameters for this, for example when running: ./script_teste parametro_1 parametro_2 Being script_teste the bash script below: #!/bin/bash echo 'Parametros passados:' echo '$1 =' $1…
-
0
votes2
answers72
viewsA: Execute request when changing value in a select
I recommend you use the method done() to use the die from your endpoint and also use the method fail() to treat any possible error that may occur, such as a connection error. Also, change the…
-
2
votes1
answer108
viewsQ: Multiple "form-Controls" within the same "form-group"
In this section of the Bootstrap 4 documentation, says: "We do not support Multiple form-Controls in a single input group" But on the same page, in the section Multiple inputs, a little further…
-
0
votes0
answers21
viewsQ: Does the <button> tag default to type="Submit"?
If I use: <button>Enviar</button> is the same as using the form below? <button type=“submit”>Enviar</button> In other words, if I use a tag <button> without defining…
htmlasked Thiago Krempser 1,878 -
1
votes1
answer87
viewsQ: How to make Bootstrap 4 look like Bootstrap 3?
Assuming I’m using Bootstrap 3 in a project and want to upgrade it to version 4, but keeping the look of Bootstrap 3 (buttons with gradients, shadows, etc). Is there any way to do this the easy way?…
-
0
votes3
answers454
viewsA: Select button with jQuery and enable input from a form
You need to remove the type="submit" of your buttons to avoid sending the form. In addition, it should be false the value for the attribute disabled in your script.…
-
0
votes1
answer457
viewsQ: Select all elements of a CSS class except $(this) with jQuery
Be the HTML below as an example: <div> <a class="link">Link 1</a> <a class="link">Link 2</a> <a class="link">Link 3</a> <div> How can I select all…
jqueryasked Thiago Krempser 1,878 -
6
votes2
answers2537
viewsQ: When should I use a Property instead of a Python attribute?
If I set the class Person down below: class Person: def __init__(self, name): self.__name = name In this other way: class Person: def __init__(self, name): self.name = name self.kind = kind…
-
4
votes3
answers4406
viewsA: How to comment on python3
To write a comment in Python, just put a # before the text that will be the comment: # Isto é um comentário The Python interpreter will ignore everything after the # until the end of the line. You…
-
2
votes2
answers180
viewsQ: Doubt about Python derived class initialization
Imagine I have a base class Food and create a second class Rice that will inherit the class functionalities Food. If at the time of initializing, what difference does it make if I do: class…
-
0
votes1
answer271
viewsQ: How to close a select by clicking outside it?
I am building a custom select with autocomplete and for this I am using some <div>'s, one <input> and jQuery. I wish it had the same default behavior as a select HTML when you click…
-
5
votes2
answers1430
viewsA: .get in Python 3
The get() is a method used to take the value of a given key in a dictionary if the key is in the dictionary, if it does not exist, the method returns None or the default value passed by parameter.…
-
0
votes1
answer89
viewsQ: Difference between versions of the uuid Python package
I need to create unique Ids and for this I will use the package uuid. However, when it came time to import I was wondering which version to use: Is there a reasonable reason to have so many…
-
1
votes2
answers179
viewsA: Should I put "Event listeners" inside the "Document ready" function?
When you do it the first way, putting inside the $(document).ready(function(){ ... }), you will be instructing the browser to only run its script after the DOM is fully processed. How an HTML file…
-
1
votes0
answers25
viewsQ: What is the difference between using . on() and . click()?
What’s the difference between declaring an Event Listener with jQuery to pick up the click on an element this way: $("#elemento").on("click", function() { ... }); And in this other way:…
-
1
votes2
answers179
viewsQ: Should I put "Event listeners" inside the "Document ready" function?
I am using an Event Listener to catch the click on an element with jQuery: $('#elemento').on('click', function () { ... }); My question is whether I should put this "Event Listener" inside the…
-
1
votes1
answer51
viewsQ: How to change the opacity of an element excluding its edge?
I am styling a link that has a border and I would like that when the mouse cursor was on top of it, only the text would be clearer, keeping the border in the same original color. Using opacity, I’m…
cssasked Thiago Krempser 1,878 -
2
votes1
answer71
viewsQ: What is the default speed value in Bootstrap 4 animations?
I want to scroll the screen to the element with ID main-title, for this I am using jQuery animation function with 1000 ms as below: $("html, body").animate({scrollTop: $("#main-title").scrollTop()},…
-
0
votes0
answers29
viewsQ: time() function is returning the same value every time
I have the following code snippet: from time import time class Transaction: def __init__(self, value, timestamp=time()): self.value = value self.created_at = timestamp Creating an instance and…
pythonasked Thiago Krempser 1,878 -
3
votes1
answer92
viewsQ: Doubt about Python classes and attributes
I have a question about classes, attributes and objects in Python. For example using the class below: class Car: drivers = ['João', 'José'] def allowed_drivers(self): print('The list of allowed…
-
1
votes2
answers607
viewsA: Switch Button with Vuejs
Use the Vue Binding for classes together with a boolean variable to toggle between the classes you want. See in the example below the use of Binding :class to toggle the class of the button between…
-
6
votes2
answers1136
viewsQ: What is the purpose of using "Else" together with Try/except in Python?
In Python, what’s the advantage of using else in a block try/catch? If in this example below: try: f = open('texto.txt', 'r') except IOError: print('O arquivo não existe!') else: print(f.read())…
pythonasked Thiago Krempser 1,878 -
7
votes1
answer2734
viewsQ: What is the difference between r+ and w+ modes in Python?
I need to open a file to read and write at the same time, I was in doubt to choose between access modes. If I open the file like this: open('output.txt', mode='r+') Or open like this:…
pythonasked Thiago Krempser 1,878 -
1
votes1
answer994
viewsA: Consume a JSON with Javascript!
Place an ID on each of the HTML elements that will receive the information, for example using a Bootstrap 4 card: <div class="card shadow" style="width: 18rem;"> <img id="avatar"…
-
2
votes2
answers2470
viewsQ: How to use Python Random.Seed()?
I need to generate a random number using the Python language, in the documentation saw that there is a function random.seed() to increase the randomness of the generated number, but I found very…
-
0
votes1
answer320
viewsQ: How do I get the name with the file extension in a Python URL?
I want to extract the name of an image with its given extension uses full URL, for example: image_url = 'http://dominio.com.br/caminho/da/imagem/imagem.png' I want to have only: image = 'imagem.png'…
pythonasked Thiago Krempser 1,878 -
1
votes1
answer638
viewsQ: Difference between task and shared_task in Celery?
I am implementing a time-consuming process in my Django application that needs to be run asynchronously to avoid timeout in the browser. For this, I chose to use the Celery to perform the…
-
0
votes0
answers80
viewsQ: Running an asynchronous mode Python function with Celery
I have the function test() that takes a long time and I want to execute it asynchronously. I put the decorator of the Celery in the same as below: from celery import task @task def test(): (...)…
-
5
votes1
answer280
viewsQ: What is the difference between "==" and "is" in Python?
Using the two lists below as an example: x = [1, 2] y = [1, 2] And testing: x == y x is y The first test gives True and the second gives False. Why the result is different in both cases?…
pythonasked Thiago Krempser 1,878 -
-1
votes1
answer406
viewsQ: Return the first 5 items from a Python list
Given the list below: list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] Is there a quick way to get the top 5 items on this list? Something like list.get_first(5)?…
pythonasked Thiago Krempser 1,878 -
1
votes1
answer406
viewsA: Return the first 5 items from a Python list
According to this tutorial from the Python documentation, you can use the "slicing" functionality of the lists, making: first_5 = array[:5] That will return to the following list: [1, 2, 3, 4, 5]…
pythonanswered Thiago Krempser 1,878 -
3
votes1
answer106
viewsQ: What happens if I don’t use the Slim version of jQuery with Bootstrap?
In the Documentation of Bootstrap 4, it guides you to use jQuery’s Slim build. Is there a problem using the normal and full version of jQuery in my project? Is there any incompatibility?…