Posts by mgibsonbr • 80,631 points
861 posts
-
3
votes1
answer97
viewsA: How to calculate the total seconds in a date range list by ignoring intersections of intervals in Python?
My suggestion is this:: Sort intervals by start date; For each interval, if its beginning is less than the end of the last, merge the two: Example (you passed your 3 tests): def…
-
2
votes1
answer69
viewsA: Syntax created dynamically
If your input matrix is sorted, this greatly facilitates the operation, as just save in a variable the last array created and check if the parent of the next line is the same. If it is, add column 2…
-
13
votes4
answers58476
viewsA: IF, ELSE IF, ELSE or IF IF IF. When to use, what’s the difference?
The other answers already explain very well, but I would like to complement with the following: often there are several ways to do the same thing, without there being clearly a "better" or "worse",…
-
5
votes2
answers391
viewsA: Why comparing a variable to None should be done using is or is not
The operator == forehead for equality, as long as the is forehead for identity. In other words, x is y will only return True if x and y are the same object (and not merely "equal"): >>> x =…
python-3.xanswered mgibsonbr 80,631 -
1
votes1
answer126
viewsA: What does this "people[last, first]" mean in Python?
Probably, people is a dictionary that maps tuples for other data: >>> people = {("Obama", "Barack"):"USA", ("Roussef", "Dilma"):"BRA"} >>> for last, first in people: ...…
-
2
votes1
answer307
viewsA: Use of equals and inheritance
This is a typical use case for the super: Compare instances using superclass criteria; If everything is ok, compare also using the criteria of the class itself. Code example (no error handling, such…
-
2
votes1
answer65
viewsA: Is it possible to assign loop repetition to a variable?
My suggestion is simply to adjust the limits of for to execute only once if the variable is set, or N times if it is not set: for( var i = (w_valor_1 === "" ? 0 : w_valor_1 ) ; i < (w_valor_1 ===…
-
2
votes2
answers773
viewsA: Program for Public IP Capture
The most direct way to get your public IP is - as you yourself suggested - to access a website that will return that information to you. If there are no drawbacks, why not your own…
-
52
votes1
answer1763
viewsQ: Can the IP address be forged?
When a client connects to my server, can I trust that the IP address I have access to (every/framework/etc language used in web applications exposes the client’s IP in some way) is really that…
-
1
votes1
answer812
viewsA: How to convert text into HTML entities in a way that is compatible with Ckeditor?
The "raw" Ckeditor makes only a basic conversion, the one responsible for converting the vast majority of entities is the plugin "Escape HTML Entities" - included by default in all distributions.…
-
4
votes1
answer812
viewsQ: How to convert text into HTML entities in a way that is compatible with Ckeditor?
I need to do a textual search on a set of data produced by Ckeditor. This editor converts text into HTML entities such as: Serviços oferecidos ---> Serviços oferecidos What I need,…
-
7
votes2
answers2365
viewsA: Are JS native objects associative arrays?
I don’t know what you mean by "associative array", but the fact is that in Javascript every "object" type can receive properties whose key is textual. Arrays are objects, but strings are not always…
-
12
votes2
answers348
viewsA: Singleton in Javascript
It’s impossible to create a Singleton in Javascript, given the prototypical nature of the language. The vast majority of object-oriented languages use what we call OO Classical, in which class…
-
20
votes3
answers5317
viewsA: Why use get and set in Java?
"Security" in this case refers only to a programmer accidentally accessing a variable in a way other than that intended by the class author (not necessarily a different programmer). Let me give you…
-
8
votes1
answer349
viewsA: In Python, how do you explain the expression 'x = not x'
The precedence of operators = and not is such that the instruction cited is to be interpreted as: =(b, not(a)) i.e. "evaluate not(a) and save the result in b". Already the expression not(x) returns…
-
5
votes1
answer268
viewsQ: How to automate a deploy in Apache?
I have some systems based in Django that often need to be deployed (Deployed) on different servers. This involves, among other things, installing all the dependencies, downloading the project files,…
-
3
votes2
answers5775
viewsA: Dynamic array in Javascript
If the question is to "associate the name X with the array Y", then the best way to do it is to use an array dictionary (i.e. a simple object whose keys are names and whose values are arrays): var…
-
5
votes2
answers1285
viewsA: Ckeditor html content is empty after using jQuery-ui Sortable in your parent div
In accordance with the answer from Zuul, the problem occurs when removing the iframe of the GIFT. For this reason, my suggestion is to destroy the editor before ordering (making it a simple…
-
4
votes2
answers6158
viewsA: Hover over one element that will effect another
That’s not how the dial , works: it makes two independent selections and applies the style to both. In this case, it will apply both to .tratoresList strong (overriding the previous rule) as to the…
-
13
votes1
answer1444
viewsA: What is an Array-Like?
In Javascript (and potentially other languages, but I don’t remember any) there is a type of data Array who owns a property length (indicating its size), the ability to have its individual elements…
-
3
votes1
answer673
viewsA: Why this function shows the list before returning but returns None
When a function - recursive or not - is called, what matters to the calling function is its return value. Not of the functions it calls. For example: def fatorial(n): if n == 1: return 1 return n *…
-
3
votes1
answer1071
viewsA: How to view if there are two identical items in Arraylist and remove them?
To store elements without repetition, the ideal is to use a data type "set" instead of "list". I suggest the HashSet, or maybe the LinkedHashSet if the order of tokens must be preserved: Set…
-
2
votes1
answer46
viewsA: Error in converting text file with nodes into AVL to be used in graphical interface
The error message cannot find symbol means that you tried to access a variable that was not defined anywhere. Or a parameter, or a type. In your case, there are 3 names that the program failed to…
-
0
votes1
answer47
viewsA: Display contents of a list recursively
Yes, it is a good algorithm. All relevant tests have been done (stop condition ok, limit of the indexes ok), incidentally the test by len(ls) == 0 is kind of redundant: if n >= 0 - necessary…
-
7
votes2
answers4994
viewsA: How to work with Regex on name validation?
Your general idea is ok (marry the first name, and zero or more times marry a space followed by another name), the problem is in the use of brackets ([]) in the second part of the expression -…
-
8
votes3
answers10734
viewsA: Recursion to return numbers from 0 to n
You speak in return the numbers from 0 to N, but its function calls imprimenumeros, So I’m assuming that’s enough for you print on screen the numbers of this function, am I right? (otherwise it…
-
12
votes2
answers1619
viewsQ: How do CSS rules take precedence?
I know that if two CSS rules apply to the same element, the more specific one will have priority: p { color:red; } /* Todos os "p"s serão vermelhos... */ .umaClasse { color:yellow; } /* ...exceto os…
-
3
votes1
answer77
viewsA: Media queries ignored from a certain resolution
Your problem is in order of its rules. In general, if two CSS rules "conflict" (i.e. both apply to the same element, with the same specificity, and each has a different value for a property) than…
-
5
votes2
answers59
viewsA: Additional field in a Database table for removal
In English, we simply say "mark as Deleted" (like, "mark as removed"), and in fact it’s a common practice. I don’t know any alternative terminology for this practice, but I could be mistaken. (a…
-
18
votes3
answers3927
viewsA: What is the difference between $(this) and $this and this?
Short answer Within a Event Handler (ex.: the function fn in $(...).click(fn)) the this refers to an element of the FOD. This means that the most direct - and most performative - way to act on this…
-
3
votes2
answers102
viewsA: Is it possible to loop with a variable jump?
The response of Bacchus seems to me to be the only correct way, although some details escape me. Its sequence is: { i, se n == 0; seq(n) = { seq(n-1)+2, se n % 2 == 1; { seq(n-1)+4, se n % 2 == 0.…
python-3.xanswered mgibsonbr 80,631 -
4
votes1
answer372
viewsA: Problems with RBAC permissions modeling
I think you’re mixing things up a little bit. RBAC was not made to manage permissions with this level of complexity, only to say whether such a user is allowed to perform the X action or not. Action…
-
5
votes1
answer110
viewsA: How this expression 'a' <= c <= 'z' is evaluated in Python
She’s rated left to right, like: 'a' <= c and c <= 'z' Moreover, if c was an expression with side effects, like a() <= c() <= z() The call to c() only occur once, still in left-to-right…
-
2
votes2
answers57
viewsA: What is the function of the ismount method
islink says if the specified path is a symbolic link (Symbolic link, soft link or symlink). Formerly this type of path only existed on *NIX systems, but recent versions of Windows also support them.…
python-3.xanswered mgibsonbr 80,631 -
10
votes2
answers5413
viewsA: Work with Session without cookies to prevent session theft
It seems to me that you are seeking something impossible. Before answering your question, let me ask another similar question: When you register on a website you create a username and password.…
-
1
votes1
answer248
viewsA: Choosing encryption in SSL
Disclaimer: I am not a security expert, nor do I have practical experience with Java TLS. This is a partial answer, intended to assist in the search for a definitive answer. First, it is worth…
-
4
votes1
answer340
viewsA: What’s the difference between serialized and non-sserialized objects?
Serialization means to take an object (or set of objects) and put it in an appropriate format to transmit it in network or save it in file. Objects that implement Serializable nay are serialized,…
-
0
votes2
answers52
viewsA: You’re not stopping file processing
According to that documentation, the fgets includes the line break read from stream (i.e. when you give Enter) on their way out - unlike gets, not included. Thus, the string read will never be equal…
-
3
votes2
answers1185
viewsA: How to add and search BD products with JSON in HTML dynamic fields?
Your code $("input[name='codProduto[1]']").blur(...) only assigns a Handler pro event blur of the elements that are already on the page from the beginning - that is, the first product. If you want…
-
4
votes3
answers517
viewsA: How is the life cycle of an application until a release with Subversion is released?
There are two main ways to use branch, which I will call "branching by Rule" (twigs created by default) and "branching by Exception" (branches grown under exceptional conditions). I will touch on…
-
4
votes2
answers1762
viewsA: How to return the position of an element in the Hashset?
Like pointed out by Renan in the comments, HashSets are not ordered, so it does not make much sense to speak in the "position" of an element within it. Changes in the set - or even the creation of…
-
1
votes1
answer926
viewsA: Save text from a Tkinter Text object in a variable
It would not simply be the case to declare textarea in the upper scope? (i.e. in the class or module) textarea = None def manipulateText(): # Lê o texto texto = textarea.get(1.0, END) # Insere mais…
-
5
votes1
answer1641
viewsA: width 100% bootstrap responsive
I noticed in the resolution xs the body gets a padding-left and padding-right of 20px. This is causing the "margin" to appear. Try setting them to zero, manually: body { padding-left: 0;…
-
2
votes2
answers2395
viewsA: Add <option> to <select> with jQuery via $.post’s callback
When the result of Ajax is a JSON, jQuery automatically converts it into a common Javascript object. That way, all you have to do is access its properties (or indexes, if it’s an array) normally.…
-
2
votes1
answer1859
viewsA: Read each existing Line in Stringbuffer or String
I have two suggestions, but to say which one will have the best performance just by testing... Note: before starting, I suggest using a StringBuilder instead of a StringBuffer - the first is not…
-
6
votes1
answer3473
viewsA: Text translation algorithm
Before answering your main question (which is related to DOM manipulation), I would like to give you some general ideas for refactoring your code, so that it is easier to manage. OK? First of all, I…
-
2
votes1
answer642
viewsA: Get snippet of a String with regular expression in JS
First of all, we’re missing one () after function, and that , "$1" on the line that create regex are not valid in Javascript. This corrects the syntax errors. Second, you need an object RegExp to…
-
4
votes2
answers5399
viewsA: Maximum number of characters in a String and Stringbuffer in Java
The theoretical limit is the maximum value of a int - 2^31-1 - since strings are represented internally by an array of char, and the way to index this array is through a int. However, what will…
-
5
votes1
answer198
viewsA: Case or lower case use in UUID
A UUID (or even a GUID - one of its implementations) is essentially a number, between 0 and 2^128 [-1]. Ideally, it should always be treated as a number, and mostly compared as a number. Convert a…
-
14
votes2
answers13934
viewsA: What is a complete NP problem?
An NP-complete problem is a problem belonging to problem class NP which may be reduced in polynomial time to boolean satisfiability problem (SAT): Given a Boolean expression expressed as a…