Posts by mgibsonbr • 80,631 points
861 posts
-
6
votes2
answers9026
viewsA: The difference between Software Service and Standalone
Note: if the two terms are presented as options in installing a system, then they probably refer to the way in which the dependencies this system will be managed - and not the way the life cycle the…
-
2
votes2
answers4328
viewsA: Use of multiple classes in a single CSS declaration
Your CSS has no content, so this rule does nothing. But suppose any content is added: .header .menu .style-fonte { background-color: blue; } The first part of the rule - the selectors - say where…
-
8
votes2
answers1234
viewsA: Store shopping cart on customer or server?
In session or in a cookie. If you saved in Javascript, first it won’t work if the user has disabled Javascript, second if the browser or the computer "crashes" it loses its entire cart (you can…
-
111
votes7
answers13788
viewsQ: How to represent money in Javascript?
What is the best way to represent monetary units (i.e. money) in Javascript? I know it is not good to use floating point, given the rounding problem, but I do not know what would be the best…
-
2
votes2
answers730
viewsA: Multiply select by radiobutton
There are some problems with your code: document.getElementByName does not exist. As your own code demonstrates, there may be more than one element with the same name. Replace the test with…
javascriptanswered mgibsonbr 80,631 -
10
votes3
answers337
viewsA: Doubt about the responsibility of a get()
I don’t know if this can be considered subjective or not, but there is evidence that the number of bugs in a program is proportional to the amount of lines of code in that program. Regardless of…
-
3
votes2
answers306
viewsA: How to do data Mining in a txt file with re.finditer
In this case, you need a regular expression that matches the entire sentence, not just the desired word. What is a phrase? Something you don’t own ., ? nor ! and: Something that ends with ., ? or !.…
-
6
votes1
answer2281
viewsA: Modeling for user permissions
There are two options for you here: the without referential integrity and the with. A without for sure is simpler, if you do not care about the lack of foreign keys, but if you find it indispensable…
-
3
votes2
answers375
viewsA: Doubt with inheritance in Java method
The problem is that Java discards generic types after compilation (such as Erasure that the error is mentioning), so that two functions with the same signature varying only the generic types are…
-
4
votes1
answer1875
viewsA: Convert encoding CP850 to UTF8
Its code has no effect on the returned string, as it is starting from an abstract representation and arriving at another abstract representation. I don’t know if I can explain, I’ll try to give a…
-
59
votes3
answers15467
viewsA: What is Boilerplate code?
"Boilerplate" is a term often used to refer to excerpts of documents (for example, legal documents) that are always the same, from document to document, so that they do not add much but still cannot…
-
12
votes1
answer135
viewsA: Why Math.round(-0.2) returns "-0" and not "0"
This is not just a Javascript feature, but the way floating point works. In this representation, there are two values for zero: +0 and -0. Implementations are required to treat them as equal (in…
javascriptanswered mgibsonbr 80,631 -
3
votes4
answers616
viewsA: Trouble finding prime numbers
Your problem, as the other answers pointed out, is that you’re subtracting 1 of i and afterward doing an operation involving i - 1. The most direct way to solve is by moving the decrease of i…
-
2
votes1
answer517
viewsA: z-index of an element without a closed position
My only suggestion is to momentarily change the position of your element to relative, observe the z-index, and then back to the way it was before: var pos = e1.style.position; e1.style.position =…
-
52
votes6
answers5796
viewsA: How is computer randomization generated?
Randomness is related to the concept of unpredictability: given a number (or sequence of numbers) you are unable to predict what the next number will be. In addition, other requirements may be…
-
2
votes1
answer66
viewsA: Fluent is safe, right?
It depends on how it is used. Looking at the examples on the linked page, we have: syntax description $table->where("field", "x") Translated to field = 'x' $table->where("field > ?", "x")…
-
2
votes2
answers222
viewsA: Problem of cursor positioning
Complementing Philip’s answer: your problem is that the method getCursor - when you find an exception - just log and move on, returning null. When the method listContacts tries to use the cursor,…
-
1
votes1
answer159
viewsA: Problem with internal database
Is your database empty? Your field código is auto-increment, so if you have a single record that is then the code 1 will already be "busy". The ideal when dealing with fields of this type is to let…
-
1
votes1
answer79
viewsA: Problem with Portuguese in ADT
Without more information you can’t tell what’s going on, but I can tell you two things: The language of Eclipse has nothing to do - but the encoding of the source files - may have. The Java compiler…
-
0
votes4
answers3125
viewsA: Dealing with collisions in Dictionary C#
There are some misconceptions here, we need to solve them before thinking about the most appropriate solution: Is there even a "collision", or your problem is "duplicate keys"? If your data mass has…
-
1
votes1
answer1533
viewsA: How do I enter into a ternary relationship?
Your relationship does seem right. You register suppliers, products, and when you want to associate a supplier with a product (in a many-to-many ratio) you use your Ids in the intersection table…
-
3
votes2
answers635
viewsA: Jdialog does not design components in Java
Whether the window is modal or not, if you have a lengthy process to do you have to put it out of of Event Dispatcher thread. It was the click of a button or something like that that started the…
-
8
votes7
answers6999
viewsA: Split() integer with Javascript
The split applies only to strings, not to numeric types. If you have a number with 2 decimal places (or only interested in the first 2 decimal places) you can turn it into a Sting using toFixed.…
-
37
votes4
answers1166
viewsQ: What are the differences between Generic Types in C# and Java?
I have studied Java for quite some time and am well acquainted with the functioning of generic types in that language: I know that only exist at compile time, that suffer type Erasure at the end of…
-
11
votes2
answers713
viewsA: How to simplify the following IF in PHP?
There is a "hierarchy" between "online," "common," and "new," so this way you wrote it is also how I would write it... But in your particular case, I see that the behavior repeats itself inside is…
-
4
votes5
answers844
viewsA: What is the shortest and most performative way to write Fibonnaci in Javascript?
Short I don’t know, but performative for sure is something like that: function fib(n) { var a = 1; var b = 1; var temp; while ( n > 2 ) { temp = b; b = a + b; a = temp; n--; } return b; } Example…
-
13
votes5
answers22471
viewsA: How do anonymous functions work?
In Javascript, functions are called "first class members". This means you can instantiate them, assign them to variables, or even create them dynamically at runtime (note: 99% of the time I don’t…
-
1
votes1
answer182
viewsA: How to change running route?
You are using relative Urls on your links. If you are on /Home/PaginaBase/6/3 (i.e. this is your path) and you click a link to Home/PaginaBase/8/3 your new path will be…
asp.net-mvc-5answered mgibsonbr 80,631 -
2
votes3
answers3426
viewsA: Disable zoom google maps does not work
According to that answer and that comment in SOEN, it is not possible to customize the behavior of the maps used in the embed. Your problem seems to be that you are trying to do both at the same…
-
15
votes2
answers2939
viewsA: Is there a problem with not putting "/" (bar) in auto-closing tags?
The idea of closing the tags without children comes from XML, in a proposal to unify the two languages by creating XHTML. However, as far as I know this has not gone forward - nor has this…
-
3
votes2
answers114
viewsA: Good practice with css selectors
The first option seems to me to be best practice, for the following reason: .menu li Here you have a specific element (or type of elements) in which you want to assign a style to all its…
-
2
votes2
answers538
viewsA: Remove Select2 parameters
The Select2 uses the ajax jQuery under the covers. When you use data it puts the result in query string [in a GET; in the POST he would go to the requisition body], such as the original method. If…
-
5
votes5
answers2024
viewsA: Replace If/Else with Case javascript
You’re making a switch in a list, I believe it only applies to a primitive value. Also, Javascript uses true and false for boolean values, no 0 and 1. However, there is a way to put your conditions…
-
2
votes1
answer207
viewsA: Calls Many to Many in template
Both in many-to-many relationships and in many-to-one relationships, one can use them in one for through the suffix .all (the same way you would in Python code proj.professor_participante.all(),…
-
17
votes2
answers677
viewsA: What is the difference between typeof(T) vs. Object.Gettype()
typeof(T) should be used in guys, not in variables. Your goal is to obtain an object Type from a known compile-time type. Already the object.GetType returns the real type of an object (i.e. its…
-
4
votes2
answers178
viewsA: Absolute ordering by data returned from DB
Assuming nome is an open textual field, what seems to be bothering your client is that lexicographic ordering does not take into account the interpretation a human would give for the string. While…
-
2
votes1
answer5979
viewsA: Take client ip on request
According to the documentation of getRemoteAddr, if the client is under a proxy this method will return the proxy address, not the actual client. How do clients connect to your server? Is Spring-MVC…
-
4
votes1
answer313
viewsA: Error - You must Supply a Resource ID for a Textview
Unfortunately the part of the log that could actually reveal where the error is got truncated: Caused by: java.lang.ClassCastException: android.widget.LinearLayout cannot be cast to…
-
4
votes2
answers666
viewsA: View in Django does not return Httpresponse object
If your code is only shown, then what seems to be missing is a else to handle requisitions and not a post. In fact, the render_to_response returns a HttpResponse and, if the problem were an…
-
1
votes2
answers157
viewsA: Initializing the Redmine
The archive secret_token.rb is initially absent. While installing, you should generate it using: rake generate_secret_token It should be possible to create it by hand as well, but I don’t know the…
-
2
votes1
answer1136
viewsA: compare two java objects
It’s unclear what you’re getting at, but I’ll try to answer with what I’ve understood so far: If you cannot have repeated elements, a Set (set) is the most appropriate data structure. It remains to…
-
11
votes1
answer1271
viewsA: Because the practice of "constant parameter" exists only in C
First, the codes you posted are not equivalent: in the first case, the pointer str may be reallocated at will, but the contents of the pointed string no (more details in that question in the SOEN).…
-
13
votes2
answers536
viewsA: Why invert the array index in a for, to popular the array, makes the process faster?
In modern processors the bottleneck is not in the CPU, but in the cache. This means that the fastest program is not [necessarily] the one that performs the least instructions, but rather the one…
-
6
votes1
answer8997
viewsA: How to make a simple text editor with jQuery, PHP and Bbcode?
I suggest looking for an editor already ready, because it is a common feature is easier than reinventing the wheel. A quick search led me to Sceditor, which seems to have everything you need. Open…
-
27
votes1
answer3182
viewsA: What is and how does context (this) work in Javascript?
In Javascript, the execution context of a code snippet - which defines its lexical scope, among other things - has a property called ThisBinding, which can be accessed at any time through the…
-
1
votes2
answers160
viewsA: How to get the IP address from the nmap XML output with a specific "vendor" using Elementtree? in Python
There’s no direct way to find ancestors through ElementTree, but this question in the SOEN shows ways to get around this, for example: parent_map = {c:p for p in tree.iter() for c in p} or (for…
-
5
votes2
answers4021
viewsA: Cryptography in Javascript
Access credentials (passwords, keys, tokens) should never be stored in the source code (hardcoded) but to be part of a configuration file (i.e. data). I don’t know Jekyll, but a quick look at…
-
6
votes1
answer136
viewsA: Vestige of mouse click
You can create an element with absolute positioning, and use pageX and pageY to get the mouse click position. Then just put this element in that position: $(document).click(function(e) {…
-
6
votes2
answers251
viewsA: Generating thumbnails through Filereader
You must not use for .. in to iterate over arrays (or array-Likes). It is used to iterate over the properties of an object. As its FileList has three properties ("0", "length" and "item") the code…
-
4
votes1
answer877
viewsA: Input in Sublime Text
I suggest you try the tool Sublimerepl. With it you can create a tab to be used as interactive input for your program. Source: that answer in the SOEN Note: I see you’re using input and then trying…