Posts by mgibsonbr • 80,631 points
861 posts
-
4
votes2
answers927
viewsA: Objectoutputstream only saves the first object
In accordance with this question in the SOEN, the problem is that the ObjectOutputStream writes a header (header) in the file after writing the first object, which should not be written more than…
-
4
votes1
answer1385
viewsA: How to change the value of a string in XML?
According to that answer in the SOEN, what you want is not possible - the string.xml in fact it is read-only. The recommended alternative is to use SharedPreferences: a way to create and persist…
-
2
votes2
answers200
viewsA: For loop does not start with Array
You seem to be not standing firm as to how the loop for works. Recapitulating: for ( iniciação ; condição de permanência ; passo ao final ) { corpo } initialization: code to be executed before to…
-
5
votes4
answers2213
viewsA: Randomize the position of the images
Assuming that when you say, "I have a list of 10 images," you refer to something like,: <ul id="minhaLista"> <li><img src=... /></li> <li><img src=...…
-
1
votes1
answer164
viewsA: Facebookoperationcanceledexception error in Facebook SDK Friend Smash example game
Two questions: Are you running a recent version of the tutorial? I searched Github for the code posted, and found it nowhere (nor on friendsmash_complete nor in the friendsmash_incomplete). If your…
-
9
votes7
answers8546
viewsA: How to implement a linear regression algorithm?
To Reply by @Marcos Banik can be translated for example to Python with minimal effort: >>> x = [1,2,3,4] >>> y = [10,20,30,40] >>> m = sum(a*b for (a,b) in zip(x,y)) -…
-
7
votes2
answers326
viewsQ: How does the jQuery stack (stack) work?
When I learned to use the method .end jQuery, I realized that it was a powerful tool that ensures a lot of expressiveness to the code (and I’ve already seen how to integrate it to my plugins).…
-
6
votes4
answers7395
viewsA: What’s different from jQuery’s find and filter?
The function of find is to seek elements descendants of that selected(s), while the function of the filter is to create a subset of the elements themselves. Example: <div id="div1" class="a…
-
6
votes5
answers10429
viewsA: How to exchange the value of two variables in Java?
If your variables are integer, you can use the XOR trick: int a = 8, b = 3; if(a > b) { a = a ^ b; b = a ^ b; a = a ^ b; } // agora a deve valer 3 e b deve valer 8…
-
6
votes5
answers12033
viewsA: How to change the value of a "date" attribute in Jquery?
Other answers are assuming that you intend to use exclusively the method .data jQuery, and they seem to be correct, but it’s good to make a distinction: the attributes data-* HTML5 are not the same…
-
2
votes2
answers984
viewsA: How to make jQuery Chosen disregard accentuation at the time of the search?
This library offers no easy option to customize the search no... I tried to read the sources first on Github (they are in Coffeescript, language I do not understand) then in the downloaded file…
-
51
votes6
answers15594
viewsQ: How to do a search ignoring Javascript accent?
Suppose I have a list of words, in Javascript (if necessary, already ordered according to the rules of collation): var palavras = [ "acentuacao", "divagacão", "programaçao", "taxação" ]; Notice I…
-
7
votes3
answers2418
viewsA: Force jQuery event execution order
If you cannot modify the code in any way, my only suggestion is to make a "Monkey patch" in function jQuery.fn.ready, to specify an execution order. Enter this code before of all others (but…
-
4
votes3
answers610
viewsA: Reload after update
There are two potential problems with your code: You seem to be dealing only with error conditions in callback (anonymous function you pass as pro parameter getJSON), but not conditions of success.…
-
4
votes5
answers1657
viewsA: How to add class to the next element when clicking the button?
Your solution proposal (use the next and the addClass) is correct. Here’s a simple example (no limit conditions check - like the first or last element): $(".selecionado") .removeClass("selecionado")…
javascriptanswered mgibsonbr 80,631 -
22
votes8
answers48548
viewsA: How to pass parameters in function calls by reference in Javascript?
It was thinking about this situation that was added between the parameters of .on the possibility to pass arbitrary data to the Handler. Any object passed as a parameter just before the Handler will…
-
4
votes7
answers44529
viewsA: How to get only the numbers of a string in Javascript?
One way is parseInt(str.split(/\D+/).join(""), 10). A regex \D+ takes everything that is not number; Making split around this expression, we divide the string into "pieces" using this regex as the…
-
9
votes3
answers16338
viewsA: How to create and read an XML with Python?
Python has two ways built-in to handle XML files: the xml.etree.ElementTree and the xml.dom.minidom. In addition, there are external libraries that can greatly simplify the work of handling XML,…
-
0
votes6
answers2251
viewsA: Upload files (always in different folders)
Reason: Always I send proposals in PDF that stay with 10MB, then I would like to send instead of sending to the client attachment, I send the link to him to download the proposal. However, one…
-
13
votes4
answers3950
viewsA: When to use ternary condition?
Your chain of if proposal is not the only way to represent the same code: var idElemento = $(this).attr("id"); var isDataInicial = idElemento.contains("Inicial"); var idEscolhido, opcaoDP, data; if…
-
6
votes2
answers4564
viewsA: Internal search form
You can use the attribute placeholder to put the text that will only appear when the field is empty: <input type="text" placeholder="Pesquisar..." name="q" id="s" onfocus="defaultInput(this)"…
-
2
votes2
answers334
viewsA: Loop to perform calculation in C Pagerank
I confess that I cannot, at first reading, understand how Pagerank works and express it by means of code. But looking at your attempted solution, I’ve identified three potential issues that may be…
-
2
votes1
answer117
viewsA: Is it possible to use Query String and Hash at the same time?
According to the Wikipedia (in English) when using a fragment (expressed via hash - #) and a query string (expressway ?) in the same URL, the fragment should be placed afterward of the query string.…
-
28
votes3
answers35092
viewsA: Ajax cross-Omain request with pure Javascript (no Apis)
The two main options are the CORS (cross-origin resource sharing) and the JSONP (JSON with padding). Both require some server support (in the form of request headers or supported response formats),…
-
53
votes5
answers24456
viewsA: AJAX request with pure Javascript (no Apis)
The site quirksmode.org has a complete example Ajax request designed to work on most browsers (current and old), without the use of external libraries: function sendRequest(url,callback,postData) {…
-
9
votes3
answers1569
viewsA: How to create multiple entries in an index based on columns in the same row?
I can’t talk about efficiency, but one way to query for a value using a single query would be to use the IN in an unconventional way - with the columns on the right. Example: select * from…
-
9
votes4
answers556
viewsA: What is the fastest, most memory-saving type?
If you are storing this data in a contiguous region of memory (e.g., an array), then using the type with the smallest size that still "fits" your data would have the best performance. In modern…
-
3
votes2
answers1204
viewsA: Fixed column of a Jtable in a Jscrollpane
What you’re looking for is a Row header (line header - compare with column header, used when you want a line fixed at the top). There is a similar question in Stackoverflow in English, but the…
-
11
votes2
answers9742
viewsA: Dynamically adding element with jQuery
I suggest you keep this label as a template (i.e. leave it in its initial, empty, and invisible state), and clone others from him: <label id="meuTemplate" for="criaAssoc" class="instAssoc"…
-
20
votes3
answers6498
viewsA: How to model a tree data structure using a relational database?
To determine the best structure to represent your tree, ask the following questions: The maximum depth is guaranteed very small? (i.e. a maximum of 3) If the answer is yes, a simpler solution may be…
-
12
votes2
answers454
viewsA: Self-referential global object: what is it for and why does it exist?
The necessity of property window.window comes from the way Javascript references its variables. Every time an expression is created involving a identifier (i.e. a name) to engine do JS searches on a…
javascriptanswered mgibsonbr 80,631 -
7
votes4
answers18382
viewsA: What is the difference between null and Undefined?
Theoretical aspects Semantically, undefined means "without reference" and null means "worthless". Or as placed by @Calebe Oliveira, "If any method returns undefined, indicates that a certain…
-
31
votes5
answers3608
viewsQ: Can the browser "remember" a password programmatically?
I am developing an application where from a password provided by the user a pair of keys (authentication and encryption) is derived. The password itself is never sent to the server, only the…
-
13
votes2
answers341
viewsA: First-class functions: Why should input types be counter-variants?
The justification for the type of entry being contravariant [and output, covariant] is to satisfy the Principle of Liskov’s replacement. This principle states that "subclasses should always be less…
-
42
votes4
answers18382
viewsQ: What is the difference between null and Undefined?
Most programming languages have a "null" type to represent the absence of a value. It can have multiple names (null, nil, None, etc), but its purpose is the same (with the exception of SQL, where…
-
103
votes9
answers31327
viewsA: How to hash passwords safely?
If I hash passwords before storing them in my database, it is enough to prevent them from being retrieved by someone? The purpose of the hashing is to make it difficult for an attacker who has…
-
7
votes4
answers7004
viewsA: Create a triangle with CSS
It is possible to do this for example through transparent edges (I’m not sure if they are available pre-CSS3): border-left: 40px solid transparent; border-right: 0px solid transparent;…
-
11
votes3
answers9326
viewsA: Is it possible to use Sqlite as client-server?
The tool SQL Relay - middleware between HTTP clients and the database server(s) - supports the Sqlite. Through it, it is possible: Execute a daemon accepting local and remote connections (specifying…
-
7
votes6
answers23686
viewsA: Difference between absolute and relative Urls in page contents
The difference should be negligible. Inspecting the way the browser sends requests (for example, in Chrome under "Tools" -> "Developer Tools" -> "Network") I noticed that both calls send…
-
14
votes6
answers7903
viewsA: When should we allow a column of a table from a database to accept NULL?
Theory It is necessary to be very careful when using NULL for he works according to ternary logic. That is, strictly speaking, to semantics of NULL is not "no value", but "value unknown". See some…
-
9
votes2
answers1434
viewsA: What are the best practices for working with Legacy Database in Django?
The "best practice" would be to let Django himself assign the names of the tables and fields, but that doesn’t apply to your case, right? If you have a legacy database, you can keep its structure as…
-
6
votes5
answers704
viewsA: Event is not tied to the element
You can use the method .live (in newer versions of jQuery, .on): $("#refresh_abertos").live("click", function() { ... }); Example in jsFiddle. Citing the documentation of live (my emphasis): Places…
-
12
votes3
answers2560
viewsQ: Database redundancies are always undesirable?
I am developing a system that keeps a record of all financial transactions occurring in a bank account (simple matches). There is a redundancy in my data model: a table saldo_conta keeps a list of…
-
13
votes2
answers1365
viewsA: Should I use a parser generator or should I develop my own code to do "parse" and "lex"?
Generally speaking, a domain-specific tool will be easier to use, and potentially more efficient, than a general-purpose tool. That’s the logic behind the "domain-specific languages" (DSL), and is…
-
11
votes3
answers12452
viewsQ: How to perform a function after two or more asynchronous events?
I have a jQuery script that starts two or more asynchronous operations at the same time, and would like to run a callback when all they have been completed. An example would be to start an animation…
-
6
votes3
answers12452
viewsA: How to perform a function after two or more asynchronous events?
The fact that the browsers used a single thread for the Javascript code of the page makes it much easier, as there is a guarantee that an invoked function runs from start to finish before another…
-
15
votes3
answers4295
viewsA: How to count amount of Likes from a page?
According to one comment in that reply in SOEN, it is possible to obtain the number of Likes in JSON format through the following request: https://graph.facebook.com/fql?q=select like_count from…
-
5
votes1
answer247
viewsA: Virtualhost in separate file - Apache compiled
Just create this folder yourself! I was also using an Apache installation that didn’t use sites-enabled, then I saw in one that used how it was done and I did the same. It’s a simple matter of…
-
8
votes2
answers629
viewsA: Why does jQuery fadein not work if the element has zero opacity?
The objective of fadeIn is not "animate the opacity of the element", but make the transition from invisible to visible. By "invisible" I mean display: none. The animation of opacity is just a ruse…
-
6
votes2
answers3208
views