Posts by mgibsonbr • 80,631 points
861 posts
-
2
votes1
answer92
viewsA: Grouping function miscalculating
The problem with your code is that you are using an object mutable as default value of your dictionary. When you do: temp = dict.fromkeys(X, [0, 0]) You expect him to create a list [0, 0] different…
-
4
votes1
answer1176
viewsA: Search for nested list elements
If you have a fixed number of nests (e.g., lists of lists of elements) - not arbitrary (lists of lists of lists of lists of lists of lists...) - you can use a list comprehension to "flatten it"…
-
2
votes1
answer2088
viewsA: Infinite Loop. How to stop the Loop in a given situation?
Remove the condition: if (track_click >= total_pages - 1) of within of condition: if (track_click <= total_pages){ If this were a show synchronous, it would be all right, but as it is…
-
5
votes1
answer61
viewsA: Why can’t I access a field but the method can?
The problem is that your reference A, of the kind BaseClass, may keep a reference for any object of BaseClass, not only of DerivedClass. Thus, there is no way for the compiler to know beforehand…
-
3
votes1
answer231
viewsA: Delete letters before after a number
You need to understand how the capture groups: The first value returned is always the marriage whole (There’s no changing that); For each (...) in regex, an additional value is returned, in…
-
1
votes1
answer670
viewsA: Toggle action from a button
Literally answering the question, if you have two actions A and B (represented by interface implementations ActionListener) and you want to switch between one and the other, you can create a third…
-
4
votes2
answers116
viewsA: How to make readable the code that uses String properties?
You can do this through the method split: it breaks a string into pieces using a regular expression as the delimiter. Breaking around the bar, and grabbing the penultimate piece (the last one is…
-
5
votes1
answer3805
viewsA: Get table row values
First select your inputs: $('.quantidadeDigitada') Then pick up your lines: .closest("tr") Then mark each line at a value: .map(function() { Return the value of inputs formatted as you want: return…
-
2
votes2
answers378
viewsA: Execute JS command using string
Assuming that your data has a type structure: { // data "result":[ // data.result [ // data.result[0] { // data.result[0][0] "Pedidos":[...] // data.result[0][0].Pedidos }, ... ], ... ] } You can…
-
3
votes3
answers1864
viewsA: How to return key of object with higher value in Javascript?
The simplest way seems to me to be with a loop even, but if you seek a more functional alternative, it can be done as follows: Get all object keys by using Object.keys; Sort them in descending order…
-
3
votes1
answer186
viewsA: How to verify sender using RSA algorithm
There is no easy way to do this, which is why in practice it is used certificates and not simple pairs of keys. A certificate is: A public key... Associated with a identity (a name)... And both…
-
2
votes1
answer531
viewsQ: How to use Ellipsis with Bootstrap menu?
I created a horizontal menu with Bootstrap by following that example, but I have a problem when it is viewed on a device with very low resolution (most smartphones, except maybe the biggest ones):…
-
5
votes4
answers199
viewsA: Problem accessing array element
You have to continue going through the string until you find another space (or the end of the string) and - if you found a space - start all over again. Instead of making the loop of 0 to n, play 0…
-
4
votes6
answers8412
viewsA: Function that enumerates letters of the alphabet
You can take advantage of the fact that, in Unicode, the letters are usually already encoded in the same sequence as they appear in the day-to-day alphabets. This is not guaranteed, however, so I…
-
10
votes5
answers2736
viewsA: Test whether all characters of the first string also appear in the second
How to compare characters is easy (just use the equal operator - ==), my suggestion is to simply scroll through each character of one and the other string to see if they are equal: // No cabeçalho:…
-
3
votes2
answers152
viewsA: Permutations and files
First of all, you don’t need to call perm from within get_file_extn: just return to calling function! If you call perm from there, you’ll be starting from scratch, which is not what you want (but…
-
4
votes3
answers8025
viewsA: Difference between decimal and Numeric
According to the SQL2003 standard (§6.1 Data Types), whose relevant excerpt you can see transcribed in that reply in Soen (the standard in itself is not free to consult, needing to be purchased),…
-
3
votes1
answer907
viewsA: What is the best way to fragment a Django project into apps?
It is not possible to answer in a generic way, as it depends much more on the domain being modeled, as well as its objectives with the project. At first, it’s okay to have one app for the entire…
-
6
votes2
answers280
viewsA: Regular expression matching only 1-digit numbers, and nothing else
When using match, string looks for a chunk (substring) that matches the regular expression used, wherever it is. As its string contains a single digit isolated, it finds this digit and returns true.…
javascriptanswered mgibsonbr 80,631 -
7
votes2
answers269
viewsA: Program always returns the same result in C
There are three problems in your code: You are using the assignment operator (=), and not the comparison operator (==). The condition of while and the last if are ok, because you use different (!=)…
-
1
votes2
answers2457
viewsA: 301 redirect outside the domain with htaccess
First, do you want domain 2 to redirect to 1 or the other way around? What your code is trying to do is redirect from 1 to 2, so: http://dominio1.com.br/novo/ ====> http://dominio2.com.br (also…
-
15
votes2
answers1684
viewsA: What are Unit Tests for and what are the advantages?
Unit Testing, or Unit Testing, aims to ensure that certain processing units (in general methods and functions) do not only what is expected of them, but that carry on doing just that when the system…
-
2
votes1
answer62
viewsA: transform blob into text and do reverse function later
You can use FileReader.readAsDataURL, he codes the Blob in Base64. On your server, you can then decode from Base64 to binary again (you haven’t specified the language, but all of them often have…
-
5
votes3
answers527
viewsA: Protect secret configuration file
If these passwords are necessary for the functioning of the system, then they must be available in original format (or equivalent) to that system, either on disk or in memory. 100% protection…
-
4
votes1
answer167
viewsA: Problem with links in the ckeditor
According to this thread in Ckeditor support, it is necessary to change a configuration so that the & are not "escaped" when inside links: CKEDITOR.config.forceSimpleAmpersand = true; After…
-
4
votes4
answers784
viewsA: Break an integer into small parts in Java
This is a case where it is easier to get the digits in reverse order, and then flip the list. For to get the last digit of a positive integer just do the rest of the division by 10: int a = -123;…
-
1
votes2
answers4191
viewsA: When do I use Pathparam or Queryparam?
According to that answer in Soen, PathParam serves to access the path while QueryParam serves to access the query string. Clarifying, a full URL* has the following parts: http :// google.com : 80…
-
11
votes3
answers9801
viewsA: What’s the encoding for in Base64?
The US-ASCII character set has 95 "printable" characters, plus 33 other control characters (0 to 31 and 127, or 00-1F and 7F in hexadecimal), originally used to control devices such as printers,…
-
4
votes2
answers79
viewsA: Add a login field to an existing user table
From a user experience point of view, using emails as login is usually more convenient than using "usernames" (usernames). First of all because it’s one more thing for the user to remember ("which…
-
3
votes4
answers2540
viewsA: Checkbox that selects all
Select the checkbox desired, and assign it the function onclick: document.querySelector("input[name=all]").onclick = function() { Select the others checkboxes (in your example are all, but the ideal…
javascriptanswered mgibsonbr 80,631 -
4
votes3
answers8626
viewsA: Protect folder from direct access
It depends on what you want. Each file belongs to a single user, and would it be bad if one user accessed another user’s files? If one person with access to a file passed the link to another,…
-
12
votes2
answers3077
viewsA: Why in class statements in Python should we extend Object?
Not required, but recommended, and the behavior is different in Python 2 and 3. According to that documentation, up to version 2.1 the class concept (class) was different from the concept of type…
-
4
votes1
answer859
viewsA: Is this a good way to keep my API safe?
There is a problem in your method 2: suppose an attacker gets a copy of your BD. Normally this would not be a catastrophe, because the users' passwords are phased, but by method 2 the attacker could…
-
1
votes2
answers729
viewsA: Key Doubt in Symmetric Encryption
One password is something to be memorized by the user, and possibly also chosen by the user. In general, passwords have low entropy, that is, although the potential number of password candidates…
-
10
votes2
answers2516
viewsA: What are the differences between Inputstreamreader and Java Scanner
The class InputStream does the data reading binaries, does not matter the source (ex.: FileInputStream to read files, ByteArrayInputStream to read from an array of bytes, socket.getInputStram() to…
-
4
votes2
answers2071
viewsA: Javascript with Object Vectors
As you already own a class Carro, all you need to do is instantiate it and save the items in your vector: var car = []; car[0] = new Carro(); // Novo carro na posição 1 car[1] = new Carro(); // Novo…
javascriptanswered mgibsonbr 80,631 -
1
votes2
answers1044
viewsA: String corresponding to real number
I suggest adding a parameter to your function, indicating whether you have already found the comma or not: public static boolean Real(String s, int i, boolean virgula) { ... else if ( s.charAt(i) ==…
-
6
votes1
answer148
viewsA: How/why to chain variables with operator = (equality)?
This operator serves to assign more than one variable at the same time, no more and no less. It’s hard to think of such a practical use in the abstract, but I would say that if you need to…
-
6
votes3
answers10752
viewsQ: How to debug a website on mobile devices?
I’m developing a website that, although it looks good on the desktop, is getting deformed when accessed via mobile devices. Specifically, some problems occur when using the browser Android standard,…
-
5
votes2
answers208
viewsA: I cannot get return of floats through expressions
This is due to a change in the semantics of the division between the 2.X and 3.X versions of Python. In Python 2.X operations between integers always return an integer, so that 6/10 is interpreted…
-
5
votes1
answer165
viewsA: How to build a queryset that returns only the cars with the last approved revision?
First, select the biggest date using annotate: from django.db.models import Max, F Carro.objects.annotate(max_data=Max('revisao__data'))... Then select the revisions that both have date equal to…
-
10
votes3
answers828
viewsA: How do I generate a hash in the client-side?
You need something like Secure Remote Password Protocol (SRP). As pointed out by Earendul and André Ribeiro, simply moving the server hash pro client negates all security benefits - because an…
-
28
votes3
answers1826
viewsA: How to calculate PI with "n" decimal places in Javascript?
The first thing you need is a library of arbitrary precision decimal number manipulation. A double (numeric format used by Javascript for type Number) is accurate to a maximum of 15 decimal places…
-
8
votes1
answer1242
viewsA: Relationship between requirements list and use cases
When adopting a formal process of Software Engineering, it is important that the various artifacts (documents, models) are consistent among themselves. For if these artifacts exist, they are to be…
-
6
votes3
answers8700
viewsA: Typeerror: not all Arguments converted During string formatting (Python 3.4)
We’re missing a % in your string 'O preço da ligação foi de .2f reais.', therefore the .2f ends up being interpreted literally (i.e. will be part of the final string, without modifications) and - as…
-
0
votes1
answer42
viewsA: List of everything that implements such a class
Although the keyword is the same, extends in a generic statement works for both class and interface. That is, you can create a list of everything that implements an interface, in the same way that…
-
17
votes2
answers2077
viewsA: What Class Does in Python
The function of classes is to unite structure with demeanor in a logical way: Lists, dictionaries, tuples, etc describe a data structure. They may be more or less semantic, but they are sufficient…
-
17
votes1
answer786
viewsA: Build a "3D" building with HTML, CSS and JS
One can do what you want using only HTML and CSS3 transformations. That tool serves as a starting point, for you to experiment with the options available, but for greater control it is better to do…
-
3
votes3
answers6238
viewsA: How to change an item in a json
I don’t know Angularjs, but I believe filter can do what you want (just not understood by the documentation how to use it). To do in pure Javascript, can use Array.filter: var array = [{ id: 1,…
-
0
votes2
answers205
viewsA: Typeerror: 'float' Object has no attribute 'getitem'
What types of elements bullet_array? That line: bullets_array.append(math.atan2(mouse_position[0] - player_x, mouse_position[1] - player_y)) suggests they are simple numbers... The problem is that…