Posts by mgibsonbr • 80,631 points
861 posts
-
18
votes5
answers3496
viewsA: What are the main advantages and disadvantages of using an LL parser or an LR?
First you need to determine whether a formal grammar is even the best way to represent your language. If it is, if this grammar is implementable by one or another algorithm (because as pointed out…
-
25
votes1
answer16031
viewsA: Desktop notifications in Chrome with Javascript
There is a feature being planned for HTML5 called Notification (at the moment only supported [desktop] by Firefox, Chrome and Safari): Notification.requestPermission(/* opcional: callback */); ...…
-
15
votes2
answers1705
viewsA: Hide widget if empty
You can use the pseudo-selector :empty in your CSS to handle childless elements (text or sub-elements) #page-alerts { margin:25px 0; } #page-alerts:empty { margin: 0; } Example in jsFiddle. This…
-
17
votes5
answers14927
viewsA: How to not allow a character to be typed in the textbox, with Javascript/jQuery?
If your goal is to stop not only him being typed, but that it is used as value anyway (eg: copy and paste) I suggest listening to the property input and adjust the value according to its rule (in…
-
13
votes4
answers2188
viewsA: Time spent developing tests
I believe that this will depend on how important its application is, and what the consequences of incorrect behavior are. A more or less innocuous application (such as a video game) will have less…
-
4
votes2
answers280
viewsA: Trigger an action when a hash is found in the URL
If the problem is "what to do when the page already opens with the hash present", I suggest making more generic the method that would handle the click, and invoking it right after the page is…
-
7
votes2
answers1581
viewsA: Difference between method ". attr()" and ". date()"
The main reason for this behavior was explained in the @bfavaretto answer (difference between the arbitrary data held by jQuery and the attributes data-*), but even though jQuery didn’t do anything…
-
20
votes8
answers5920
viewsA: Is it always guaranteed that a multi-threaded application runs faster than using a single thread?
There are obstacles that can make an application multi-threaded less efficient than one with a single thread, such as shared memory (or not). If two threads share the same memory region, concurrent…
-
12
votes4
answers3196
viewsA: What is good practice when casting an exception within if?
From the performance point of view, there is no reason to choose between one and the other, the difference should be negligible. Although the representation of the two forms in the bytecode be…
-
14
votes5
answers10782
viewsA: What is a Mysql Transaction for?
Transactions guarantee atomicity to a set of operations, that is, or all of them will succeed, or all of them will fail. A classic example is a bank transfer, where two changes are required in your…
-
9
votes4
answers3090
viewsA: Regex for Cifras site as Cifraclub
Regex is not the right tool for this problem. By inspecting the page’s source code, I see that the ciphers are each in one element b, with class _i0, _i1, _i2 and so on (irrelevant in this…
-
10
votes4
answers2589
viewsA: Is it possible to create an 'abstract class' in Javascript?
It is possible to create a immutable object in Javascript through the method Object.freeze, and a immutable reference through the method Object.defineProperty: // Atribui a classe ao escopo global…
-
3
votes3
answers471
viewsA: Add custom timezones in PHP?
I don’t know any way to create timezones customized, but I can suggest an alternative using timestamps. Convert your date to a timestamp (int), via strtotime (if your date is in format string) or…
-
4
votes2
answers1221
viewsA: Where should I declare an instance variable in Javascript?
The difference is that the variable declared in prototype is shared between all instances of the class. If it has a simple value, it does not matter, but if it is a complex variable (a list, or an…
-
83
votes5
answers9611
viewsA: How do Closures work in Javascript?
Closure ("enclosure" in English, but this term is rarely used), refers to how functions defined within a "lexical context" (i.e. the body of a function, a block, a source file) access variables…
-
7
votes2
answers245
viewsA: Infinite loop when walking recursively through DOM nodes
You forgot to declare the variable i using var, which made her a global. The recursive call overrides its value, so that when it returns it iterates again over existing elements (entering the…
-
44
votes11
answers8299
viewsA: Should I write my program in English or Portuguese?
To answer this question, you must determine at least 4 factors (listed here in descending order of importance, in my opinion): Is it an internal project [of your company, for example], or something…
-
11
votes6
answers36799
viewsA: How to read a text file in Java?
One way to do this is by using the standard NIO2 library (New Input/Output 2), available from Java 7: static String readFile(String path, Charset encoding) throws IOException { byte[] encoded =…
-
4
votes1
answer370
viewsA: Responsive Nav-bar at the Foundation?
Your problem is that in Foundation CSS there are specific instructions for dealing with small-width screens (note: enhanced code layout for readability): /* Mobile Styles */ @media only screen and…
-
2
votes2
answers377
viewsA: Override the Python mock Decorator
That is correct, yes. In order for the class to be passed on to the decorator, it must already be built - which meant that its fields and methods already have to be ready and assigned. Thus, the…
-
8
votes3
answers3083
viewsA: How to do a search ignoring Python accent?
Based on the comment and reference from @bfavaretto, I was able to put together a proof-of-concept. The solution is to remove the diacritics from both the search list and the search term. To do…
-
17
votes3
answers3083
viewsQ: How to do a search ignoring Python accent?
Suppose I have a list of words, in Python (if necessary, already ordered according to the rules of collation): palavras = [ u"acentuacao", u"divagacão", u"programaçao", u"taxação", ] Notice I didn’t…
-
7
votes2
answers3697
viewsA: How to schedule releases on continuous integration with Jenkins?
Apparently Jeninks is using the cron format, common on Linux systems. So what your instruction is saying is: "perform the task once every minute (*) of the hour 3, every day (*), every month (*),…
-
3
votes6
answers18042
viewsA: How to make a Custom Scrollbar?
I suggest the pluigin jScrollPane for jQuery, it offers a variety of ways to customize the scroll bar consistently between the different browsers. Example of use: $(suaDiv).jScrollPane();…
-
9
votes3
answers4043
viewsA: How to add a CSS class to images that didn’t load?
The most "natural" way would be to use the onerror (jQuery: error), but be careful as this event will only be captured if it occurs afterward that the Handler has already been added. Therefore, a…
-
7
votes4
answers6715
viewsA: How to call an external function without sending the 'self'?
Note: this response indicates an alternative way of doing unbinding in a method bounded, which may be useful in some situations, but there are better ways to solve the original question. See the…
-
18
votes5
answers8633
viewsA: What is the most complete way to install python on Windows?
One of the biggest difficulties in installing Python packages on Windows is that not always the resources needed to compile them from sources are present. This causes problems when installing…
-
5
votes3
answers2326
viewsA: Problem accessing an accented file (matching character)
Based in response by @Luiz Vieira, and in that question in the English OS, I was able to find a solution. The problem was not in accessing the file itself, but only by printing its name on the…
-
13
votes3
answers2326
viewsQ: Problem accessing an accented file (matching character)
I’m trying to list a folder (files, subfolders) in Python [2.7 on Windows XP], and I’m having problems with sharp files. I know the method os.listdir behaves differently if the argument is a single…
-
8
votes4
answers2247
viewsA: What is the iterative (non-recursive) version of the LCA (Lower Common Ancestor) algorithm
If each node in your tree has information about the "depth" (i.e. the number of nodes between it and the root) then you can replace each node with your parent until both are the same node: entradas…
-
12
votes3
answers5488
viewsA: How to use the current value of a variable in a more internal function?
The name of the concept that’s causing you trouble is closure ("enclosure" in Portuguese, but this term is rarely used), and refers to how functions defined within a "lexical context" (i.e. the body…
-
111
votes4
answers48488
viewsA: Where should I put a Javascript code in an HTML document?
It depends on what the script does, and how much it misses. All Javascript inserted in a page (wherever) runs in a way synchronous by default*. This means that when the tag <script> is found…
-
3
votes3
answers1778
viewsA: How to select rows from table A that are referenced in a column of table B?
As far as I know, the operator IN works only for lists, i.e. if your select internal return more than one line it would seek the A.id on each of these lines - in contrast to the case where the SQL…
-
5
votes3
answers1404
viewsA: How to compare HTML elements by real z-index?
In the absence of simpler solutions that "reinvent the wheel", follows my attempt to write a function consistent with the stacking algorithm used by browsers: function naFrente(a, b) { // Salta…
-
2
votes1
answer394
viewsA: Efficient data structure for high color concurrent problem
I don’t have much experience with concurrent programming - particularly involving Java - so I can’t suggest you an efficient data structure, but I can give you some parameters to help you decide: Do…
-
16
votes3
answers1404
viewsQ: How to compare HTML elements by real z-index?
Given two arbitrary HTML elements A and B on the same page, how can I find out which one is "closest" to the user (i.e. if they overlapped, which one would obscure the other)? To css specification…
-
7
votes8
answers14487
viewsA: How to create a copy of an object in Javascript?
The most "secure" (i.e. less error prone) way to clone an object is by using an existing library/framework that supports this function, since cloning in theory is simple (see @Sergio’s reply, for…
-
25
votes3
answers30199
viewsA: How do I round numbers to the nearest integer?
For a simple rounding use the method Math.Round which receives a double (or decimal) and rounded to the nearest integer: Math.Round(0.4); // 0 Math.Round(0.6); // 1 However, this method has one…
-
9
votes2
answers340
viewsA: ASP.NET pages continue to run after page changes?
That one blog post (in English) explains in detail the situation of the endResponse. In short, the behaviour of close the thread after a redirect was considered a design error, something that is…
-
6
votes3
answers7789
viewsA: Built-in form action parameter is not passed via GET
If I understand correctly, your problem is that the parameter spv is not being passed, right? I suggest putting it in a hidden entrance (Hidden input): <form method="get" action="painel.php>…
-
7
votes7
answers25439
viewsA: How to convert a JSON response to a C#object?
To do this without using any external library, you can take advantage of the fact that JSON is a subset of Javascript, and use the JavaScriptSerializer from the System.Web.Extensions.dll (.NET 3.5…
-
4
votes6
answers5183
viewsA: How to reverse the position of a div(and its content and attributes) with another div?
I see many different approaches, but none using the classic algorithm of exchanging two value variables: swap = a a = b b = swap In case Uery would be like this: function trocar(a, b) { var swap =…
-
22
votes3
answers4056
viewsA: How to get the value of the current percentage of an upload?
In HTML5 it is possible to do this by adding a listener progress to the property upload of a XMLHttpRequest (used to upload the file via Ajax): xhr.upload.addEventListener("progress", function(e) {…
-
11
votes6
answers3652
viewsA: How to detect page encoding with PHP?
Assuming your server is serving coded pages as UTF-8, the default behavior of most user agents (browsers etc) will be using this same encoding when sending data back to the server (through…
-
37
votes4
answers13910
viewsQ: What is the best way to represent an Address?
When modeling addresses in an application, naively followed the standard form when representing in the BD (i.e. separate tables for country, state, city, neighborhood etc. - joins everywhere), and…
-
17
votes2
answers3325
viewsA: What would be real cases of use of functional programming in the world . NET (F#)?
Although the programming paradigm Imperative be the most popular among programmers [professionals], it is only one among several means of "giving orders" to a computer. Besides it and the…
-
13
votes4
answers8320
viewsA: What is the difference between client-side and server-side code in web development?
The difference is simply where the code will run: on the server where ASP.NET is installed (server-side) or in the browser from which the system will be accessed (client-side). Although it is…
-
14
votes3
answers1094
viewsA: Assign value to a dictionary variable that is optional
No, I believe that the form you have presented is minimal. I cannot talk about Python 3, because I have no experience. (Negative responses are complicated, but I have no supporting evidence, except…
-
4
votes2
answers830
viewsA: What is the most efficient way to calculate the Hashcode of an object in Javascript?
The main requirements of a hashCode sane: If A == B, then hashCode(A) == hashCode(B); (The reciprocal is not true: two objects can have the same hashCode and yet be different. This is called…
-
5
votes2
answers228
viewsA: What is the most efficient way to implement Groupby in Javascript?
Many libraries that implement GroupBy add that the entry is already keyed. A sorting by key is O(N*log(N)), but once performed it is possible to group lists of any size quickly, in O(N), because…