Posts by mgibsonbr • 80,631 points
861 posts
-
4
votes2
answers738
viewsA: Ckeditor does not recognize required attribute
The configuration extraAllowedContent allows you to enlarge the filters1 that determine what is or is not accepted in the Markup dealt with by the Ckeditor. To allow the attribute required in inputs…
-
3
votes5
answers338
viewsA: Move background of text
In the absence of a solution cross-browsers in CSS to apply a gradient to background of a text, I suggest the use of canvas to achieve its objective. This example in W3schools does exactly what you…
-
8
votes2
answers1032
viewsA: Attacks of data interception
Macro-categories Interception attacks can be classified into three large groups - Eavesdropping, Man-in-the-Middle and Denial of Service - depending on what the attacker does (or is able to do) with…
-
5
votes3
answers325
viewsA: Create select using "for" cycle
Note: this is an answer to a previous revision of the question, in which the language was not specified and I assumed (erroneously) it was Javascript. You can do this with DOM handling methods…
-
4
votes2
answers3236
viewsA: How to overcome Xmlhttprequest cannot load?
Firstly, it should be noted that the browser established the origin of the call as null. The source (the schema/domain/port trio that identifies where you are) usually refers to the site on which…
-
1
votes1
answer1552
viewsA: Error checking Digital Signature - "Unable to load Private Key"
When you specify the option inkey, the default is to treat it as a private key. If you want to verify the signature using a public key, you must also use the option -pubin: openssl rsautl -verify…
-
1
votes1
answer121
viewsA: File per folder limit - Django 1.7
As far as I know, there is no control of this type, however there is a very simple way to prevent folders from growing too much: separating files by the date of upload, through FileField.upload_to:…
-
2
votes1
answer606
viewsA: Single email field on Django User model
You are unlucky, from version 1.5 it is possible use your own template to represent a user, but in 1.4 or below there is (as far as I know) a "clean" way to modify the model User. Unless you’re…
-
6
votes3
answers1678
viewsA: How to run code just in the first click?
One way to do this is through $.one. It places an event handler in the set of selected elements, so that the handler will only be called once for each element of the set. Example:…
-
5
votes2
answers738
viewsQ: Ckeditor does not recognize required attribute
I’m using Ckeditor to create pages that may contain forms (in other words, forms can be inserted into the content being edited, because I’m using the full package). I wish I could use the attribute…
-
10
votes4
answers3093
viewsA: Function to check if number is prime in Javascript
If the number is relatively small, you can do this check simply by testing if it has dividers, like suggested by Maniero. Otherwise, this solution becomes increasingly expensive, to the point of…
-
5
votes1
answer699
viewsQ: How to implement Diffie-Hellman in Javascript?
I am developing a web system where users can communicate with each other privately, without even the server having access to the content of the communication (i.e. end-to-end). For this I intend to…
-
5
votes1
answer699
viewsA: How to implement Diffie-Hellman in Javascript?
To Webcryptoapi - in the process of standardization by W3C and already supported at least in part by most of the browsers modern - possesses methods for DH key generation. It is not necessary, nor…
-
17
votes1
answer5098
viewsA: Funcionamento @classmethod
By default every method created in a class belongs to the object. This means that an object instance is required to call a method, and this instance is normally associated with the first function…
-
11
votes3
answers13657
viewsA: How to make a column occupy the rest of the available space?
You can do this with Flexbox: Make the #container have flex layout: div#container { display: flex; The element on the left, whose size should occupy as much of the available space, you establish…
-
6
votes4
answers5471
viewsA: Count occurrences in a list according to prefixes
Assuming that there is no "hierarchy" between prefixes (e.g., every word that begins with ro also begins with r), a simple and direct way is using the itertools.product. It will combine each element…
-
5
votes1
answer241
viewsA: What are the implementation differences between the Browser.log console and Node.js?
The method console.log is not standardized, so that each browser can implement it as you see fit. And in fact, by executing your example in different browsers, I had different results: Firefox:…
-
6
votes2
answers403
viewsA: Computer buffer
More than "store temporary values", the function of a buffer is to group into data sets that would be too small to be treated individually. When a process (usually a communication) has a overhead…
-
0
votes1
answer221
viewsA: Minecraft make the player connect to the game
I see at least 3 [potential] problems with your code: When the linked documentation says to "send an 0x02", it probably means the byte 0x02, not the string "0x02". Change your code to:…
-
3
votes1
answer1555
viewsA: Wait for pending runs to finish to proceed, Javascript
The general idea of using a variable as "semaphore" is OK (but using it in a loop would be even gambiarra, and would not work), and the way your code is structured can be done with a minimum of…
-
4
votes2
answers2470
viewsA: Method with generic return
This can be done using Class.cast: public <E> E to(Class<E> e) { return e.cast(obj); } Call it that: String st = to(String.class); Integer it = to(Integer.class); Example. Always…
-
12
votes1
answer832
viewsQ: What is the baseline?
Studying Flexbox (layout type in HTML/CSS), I came across this concept of baseline, I’ve never seen before: align-items ... ... baseline: items are aligned so that their baselines line up Looking…
-
4
votes2
answers397
viewsA: Is support for users who do not use Javascript running out?
It all depends on the requirement of such users: if there is pressure for websites to work without Javascript, there will still be websites that work without Javascript. If there isn’t, there won’t…
-
3
votes1
answer787
viewsA: Execution order is not followed
As explained in that other answer, the problem is that this library is doing asynchronous operations, so that they have not yet finished executing by the time the later code is called. A simple and…
-
5
votes2
answers2350
viewsA: Run code only after setTimeout runs
If you have an extensive function - be on top-level or in another function - and whether an excerpt of it only runs after a second condition is satisfied (some time has passed, an ajax call has…
javascriptanswered mgibsonbr 80,631 -
3
votes2
answers2689
viewsA: Align text in the vertical center of a circle
If your text only has a single line, you can make the line-height is equal to the size of the div: .circle{ ... height: 37px; line-height: 37px; ... } Example. Otherwise, that answer in Soen shows…
-
7
votes4
answers7094
viewsA: Swap the first character of a string with the last python character
The method string.replace replaces all the occurrences of a substring, not just one. So, if your string is rar and you ask to replace the r for b, all the rwill be replaced, and the result will be…
-
6
votes1
answer70
viewsA: Sort decimal notes
Your problem seems to be that the notes are in string format, not numerical. String comparison is in lexicographic order, and how "1" < "5" then "10.0" < "5.5" (albeit numerically 10.0 >…
-
58
votes5
answers8000
viewsQ: What is the difference between pointer and reference?
One of the first things I learned about Java is that this language "has no pointers, only references", followed by some generic statements about how the first is complex and the second is simpler.…
-
0
votes1
answer182
viewsA: Depending on the seed I put the print of the capacities does not occur. How to tidy up?
By their logic, if all three values are drawn equally (ex.: 42, 42, 42) then you’ll never get out of the loop: cap_inicial_1 <= cap_inicial_2 ? Yes: 42 <= 42. Get in the loop; cap_inicial_1…
-
2
votes1
answer1203
viewsA: Padding-top does not work in the content below the bootstrap navbar, in firefox browser
The example below works correctly on Chrome and Firefox. A margin-top for elements with the class container except for those who are inside the nav. The reason to use margin and not padding is…
-
4
votes2
answers281
viewsA: Return to start if size is not reached
If you want to execute certain code, then repeat it if at the end certain condition is not satisfied, the most natural way is using a do...while (do X, if condition Y is true do X again, etc). But…
-
8
votes6
answers2106
viewsA: Smooth gradient color transition automatically
Although you say "random", the site in question seems to follow a predefined sequence - and nothing random. If you have two colors A and B and would like to make the smooth transition towards the…
-
3
votes1
answer289
viewsA: About the URL how it is encoded and POST parameters
When you submit a request, whether GET or POST, the parameters are first encoded using the URL encoding (by default; if you specify that you want a different encoding than…
-
9
votes3
answers5066
viewsA: What is parallel programming?
Parallel programming consists of dividing a computational task into two or more sufficiently independent instances to be executed in parallel - for example in two different processing cores, or even…
-
24
votes2
answers14623
viewsA: What is and what is "2>&1" for?
The command > is equivalent to 1>, and means you’re redirected to standard output (standard output - stdout) to the specified file. Already the 2> means that one is redirecting the standard…
-
3
votes2
answers728
viewsA: ASCII encryption in C
First of all, look the observation of hugomg how to calculate the password size. It should be strlen(password) and not sizeof(password). Your problem is in how you are treating the range limits (in…
-
3
votes1
answer58
viewsA: Problem with query Join with 5 tables
When you make a subquery within a type junction: INNER JOIN (SELECT COUNT(*) AS id FROM avaliacoes) ON avaliacoes.estabelecimento_id = estabelecimentos.id There are two problems with her: To…
-
23
votes4
answers4453
viewsA: What are the practical advantages of using object orientation in the day-to-day life of a development team?
Standardization Just as a child who is learning to read has difficulty joining the letters to form words, an earlier one already reads whole words but strives to join them in sentences, and a…
-
3
votes3
answers1630
viewsA: Problem with randint function
If you are referring to the site http://www.pythontutor.com/, The problem is that he’s probably using a fixed seed in his random number generator. My guess is that this is being done so that the…
-
3
votes3
answers512
viewsA: Create element only in the first mouseover
I suggest not creating it in the onmouseover, but already have it in HTML - only hidden. So, you can display it/hide it simply with CSS, without needing Javascript: #ex1 map { display:none; } #ex1…
javascriptanswered mgibsonbr 80,631 -
2
votes1
answer2475
viewsA: How to pass JSON array as parameter and access its objects in another function?
The method getJSON is asynchronous. Your code: JsonControl.prototype.getJsonData = function(dataLocation){ $.getJSON(dataLocation, function(mData) { return mData; // Esse retorno não está indo pra…
-
2
votes1
answer66
viewsA: How to assign a class to a field type in Django?
Use isinstance: for field_name, field in self.fields.items(): if isinstance(field, forms.DateField): field.widget.attrs['class'] = 'date'…
-
7
votes1
answer1130
viewsA: About Deferred and Promises Jquery
timer1 = $.Deferred(...) This creates a deferred ("deferred", "deferred"). This object starts in the "pending" state. Only when someone call the method resolve or resolveWith he had passed to the…
-
3
votes2
answers481
viewsA: Separate <script> tag by semicolon
If your script is embedded in the page (i.e. <script type="text/javascript"> código </script>), see the answer from Zuul for a possible solution (another would be to move your script to…
-
3
votes1
answer2935
viewsA: Sort Char vector in C using selection method
Along those lines: if (stricmp(v[j], v[j + 1]) > 0) { Are you comparing j with j + 1, and not with min. Even this can cause a segfault, for j + 1 may equal to max! (assuming that max is the…
-
14
votes3
answers3855
viewsQ: Differences between Git and Mercurial
What are the main differences, advantages and limitations of these two distributed version control systems? If anyone has practical experience in both (for example I only know the Mercurial more…
-
0
votes2
answers674
viewsA: How to use an iterator twice within an understanding?
I found two shapes, one using lambda (that only works for the key or value, but not for both): >>> { ... a:(lambda b: (min(x[1] for x in b), max(x[1] for x in b)))(list(b)) ... for a,b in…
-
7
votes2
answers4323
viewsA: Format number for only 2 digits
To round to the nearest number, the simplest is to use toFixed: var x = 4.499999999999999; var y = x.toFixed(1); document.querySelector("body").innerHTML += "<p>" + y + "</p>"; Already…
-
2
votes2
answers674
viewsQ: How to use an iterator twice within an understanding?
Let’s say I have a list: lista = [(1,1), (1,2), (1,3), (2,6), (2,4), (3,1), (3,2)] And I want to know the maximum and minimum values of the second element, grouped by the first. That is to say: {…