Posts by mgibsonbr • 80,631 points
861 posts
-
1
votes1
answer505
viewsA: Does jqgrid support line break formatting?
All you have to do is insert <br/> in the text you want to break into lines. Whether on the server, before sending, or on the client, before you populate the grid (I couldn’t find in your code…
-
7
votes1
answer117
viewsA: Why can’t I use || for pointer?
Seems to me your problem is that while no exit condition: it will continue forever! (or better, it will continue until you give a segfault) Suppose your string is simply: ;= Using while(*l->str…
-
3
votes3
answers2755
viewsA: How to assign the results of a function that returns a list of objects?
In that reply in the SOEN the author proposes a structure to allow such constructions. Here is the original post (also in English). The suggested code is: list <- structure(NA,class="result")…
-
2
votes1
answer982
viewsA: Organizing Javascript Files in the Solution
The two main factors in this decision are the download time and the use of the cache. Both are conflicting and it is necessary to make a trade-off. Not sending the code a page will not use reduces…
javascriptanswered mgibsonbr 80,631 -
5
votes2
answers1163
viewsA: When to use instance variables vs parameters?
In fact, none of the options are ideal. I will briefly discuss each of them and then propose an alternative. Option 1: save status to A This solution, although inelegant, may be feasible at least in…
-
2
votes1
answer491
viewsA: Find isolated components in graph
It is difficult to understand what is being asked, because both your question and some sources I have consulted use different names for the same concept, and vice versa. I will define some terms,…
-
37
votes6
answers18641
viewsA: What is the difference between declaring an array with "array()" and "[]" in Javascript?
Both forms produce the same result (unlike String, for example, where there is difference between the literal "foo" and the object new String("foo")). In Javascript, arrays are not "special" in any…
-
4
votes1
answer1518
viewsA: Call the Jquery function
Your problem seems to me to be that you’re adding the Handler to class remove_produto several times (once to each Ajax call). Also, when your code enters the first else you are replacing elements of…
-
4
votes1
answer2226
viewsA: Save multiple figures in a loop - Python
You haven’t shown your code, but assuming you’re using it matplotlib.pyplot as in the tutorial, I suggest each new figure and/or each new subplot is stored in a dict, so that you can access it again…
-
3
votes3
answers740
viewsA: Is sending data to the same form a good method?
I believe this can be circumvented through a redial. Make a POST for your form and, in case of failure, make a redirect (302) for himself - passing the query string rendering parameters (i.e. which…
-
3
votes3
answers949
viewsA: Scrypt, Bcrypt or anything else
In a hash algorithm, only what is being hashed is secret. Everything else is public (salt, work factor, other parameters). These algorithms are designed to maintain pre-image resistance (i.e. from…
-
5
votes1
answer186
viewsA: Performance in Javascript objects
The first option for sure. When you create a constructor function and create an object through new, you are creating a chain of prototypes. That is, every object of the type Objeto owns a property…
-
13
votes5
answers61683
viewsA: Using line break " n" in Java
The only problem is that if your file opens on Windows (or Mac), some text editors will not recognize the line break and show everything as if it were a single line. If you want to ensure that line…
-
8
votes4
answers552
viewsA: How to distribute words in a fixed size area?
The first thing to do is to find out the height and width on the screen of each word. That answer in the SOEN shows a possible path (create a div with the word and measure their clientWidth and…
-
5
votes6
answers2374
viewsA: How to select all "empty" elements
Apparently, when you use [value=""] he observes only the attribute value, not the property value. That is, the value that was in Markup, not the current value. Example: <input type="text" />…
-
164
votes7
answers20768
viewsA: How to protect source code?
It is neither possible nor necessary to take extreme measures to protect the source code. Focus your energies on what adds value to your business, instead of wasting it "treating customers like…
-
7
votes1
answer295
viewsA: Can CORS be configured for Websocket?
Information about Websockets and the same origin policy is scarce (and conflicting), but everything indicates that they nay are subject to that policy, and therefore can be used to communicate with…
-
10
votes3
answers711
viewsA: Extend classes with private constructor
If all methods are static, why inherit from the class? You can simply, in the class B, import all methods of A so that you can keep calling them without having to use A.metodo. B.java import static…
-
5
votes5
answers727
viewsA: Return all CSS classes with Regular Expression
My suggestion is to use a parser complete CSS, such as JSCSSP, and extract the classes from the individual selectors (instead of the entire CSS text). function extrairClasses(css) { var classes =…
-
7
votes4
answers3372
viewsA: Generate random numbers that result in a fixed sum
The algorithm proposed in my another answer is functional but it’s not righteous (i.e. does not distribute the value evenly between lines). If there are many lines, the latter tend to be all with 0.…
-
3
votes4
answers3372
viewsA: Generate random numbers that result in a fixed sum
I think you should approach the problem from another angle: you actually have 200 (I’ll call it alvo) and wants distribute that alvo for N lines, each line being subject to a maximum and perhaps a…
-
8
votes2
answers665
viewsA: How to determine the smallest number of small areas to render?
You have an estimate of R and P? This is a case that allows great flexibility in solutions, since its goal is to "render everything that has changed", but not necessarily "render nothing that hasn’t…
-
2
votes3
answers171
viewsA: Is it possible for two applications to communicate in an Ad-Hoc network?
Regardless of the topology of your network, the [direct] access from one PC to the other will depend on your ability to address it, whether via IP address, DNS or whatever (e.g.: on your ad hoc…
-
11
votes5
answers708
viewsQ: At what point in a project should the platform be chosen?
When a project is designed (i.e. a need is identified, and it is decided to develop a computerized solution for it) one of the first things the customer asks: on which platform should the software…
-
20
votes12
answers208289
viewsA: How to format date in Javascript?
If you are using jQuery UI, you can use an auxiliary function from datepicker: $.datepicker.formatDate('dd/mm/yy', new Date()) (Note: I added this answer because I saw in your example code the use…
-
3
votes1
answer291
viewsA: Obfuscate code in Actionscript 3.0 in SWF Flash?
There are several tools to outshine SWF, both free and paid, just choose one that suits you. Second that answer in the SOEN, a tool that obfuscates the SWF itself is preferable to one that…
-
2
votes2
answers772
viewsA: Error executing Cordova build command
C: Net templates Phonegap android-sdk tools ant build.xml:734: Unable to find a javac Compiler; com.sun.tools.javac.Main is not on the classpath. Perhaps JAVA_HOME does not point to the JDK. It is…
-
14
votes2
answers817
viewsQ: How to create an immutable object in Javascript?
I know it is possible to "freeze" a Javascript object through the method Object.freeze: var x = { foo:"bar", complexo:[1,2,3] }; Object.freeze(x); x.foo = "baz"; // Não tem efeito…
-
9
votes2
answers817
viewsA: How to create an immutable object in Javascript?
According to the documentation of Object.freeze, there is no ready method for this, it is necessary to create a special function to iterate on the fields of the object and apply freeze in each of…
-
3
votes2
answers226
viewsA: Error performing Insert on an Android application: "Empty bindArgs"
Although in your question you say you’re using mysql, it seems to me that the access is through the class SQLiteDatabase, or am I mistaken? If so, according to the documentation of execSQL: Executes…
-
15
votes4
answers9017
viewsA: How to declare a constant in Javascript?
It is not possible to create a constant directly, but you can declare a function that always returns the same value: function constante(valor) { return function() { return valor; } } var…
javascriptanswered mgibsonbr 80,631 -
13
votes5
answers2395
viewsA: Strategy to find out if your web application is being partially or fully censored by an ISP
From the server’s point of view a censored communication is indistinguishable from a communication that has never been initiated by the client. Similarly, from the customer’s point of view a…
-
1
votes4
answers1358
viewsA: Conceptual database and file backup strategy
It is difficult to give a conceptual answer because it varies a lot with the implementation. Examples: A strategy for backup databases without loss of availability would be replication of your BD in…
-
16
votes3
answers8084
viewsA: CORS on Nodejs without the use of Frameworks
Enabling CORS is a simple matter of adding the header Access-Control-Allow-Origin to your answer. In Node.js, this is done through the method response.setHeader:…
-
14
votes8
answers16873
viewsA: How to invert a string in Javascript?
Note: this answer assumes strings in BMP without matching characters (only pre-compounds) - which in many practical applications is good enough. For a more complete solution, see the response of…
-
9
votes1
answer253
viewsA: Is it wise to implement functions that only call for other functions?
Yes, this form of organization is normal. Its function run_game is not trying to "do more than one thing at the same time", it is simply operating in a higher level of abstraction. For example, a…
-
13
votes4
answers262
viewsQ: How to implement journaling in Python?
I need to do a series of operations involving binary files (you can’t use BD), and I need to ensure that they end successfully even in the event of failure in the middle of the operation. For this,…
-
12
votes2
answers1272
viewsQ: What does it take for a system to support a locale?
I’m developing a system that will require a locale specific for it to work properly. That is, it is not only a matter of user interface, the system as a whole can become unusable if the locale…
-
8
votes2
answers2746
viewsA: How to make the jQuery toggle function in pure javascript?
Just keep a circular counter, which picks up the next event from a list each time the element is clicked: function toggle() { var eventos = arguments; var contador = -1; return function() { contador…
-
5
votes4
answers4212
viewsA: How do I start the next ten?
In general, methods are used ceil (ceiling) and floor (floor) to round to the whole closer but as you want to round in the direction of a different greatness (in case a dozen) you need to make some…
-
17
votes5
answers32771
viewsA: How to calculate the age of a person with JS, from the date of birth?
I suggest comparing the month and the day of the month: if today’s date is greater than or equal to that of birth (i.e. the birthday has passed), then it is enough to make the difference between the…
javascriptanswered mgibsonbr 80,631 -
4
votes4
answers7550
viewsA: jQuery identifying jQuery’s own change
The method change just listen to the event onchange browser, it is not activated when the value changes programmatically. An alternative would be you invoke the change manually via the command…
-
16
votes6
answers53653
viewsA: How to change PATH in Windows
If you want to change the PATH from the command line/from inside your program calling the shell, the command is this: set PATH=%PATH%;C:\minha\nova\pasta The set serves to assign values to…
-
1
votes2
answers437
viewsA: When do I use Objectoutputstream the parent class attributes are also saved?
Yes, not only the attributes of the object itself are saved, but also those of the superclasses, and also all objects referenced. That is, a sufficient "graph" of objects is recorded to restore the…
-
0
votes2
answers848
viewsA: How to adjust the height of sidebar elements?
I couldn’t reproduce your problem exactly as your code is (height expressed in percentage - but height in pixels the problem arises), but it seems to me that your cause is the fact that you have…
-
0
votes2
answers654
viewsA: Pointer logic
I believe having an "array of pointers" makes sense, but an "array pointer" doesn’t. If you declare: int *variavel[10]; What you’re saying is, "allot memory in the stack to 10 pointers for integer,…
-
16
votes3
answers568
viewsQ: Is there an advantage to an explicit "self" instead of the implicit "this"?
Unlike most [most popular] object-oriented languages, which use a keyword to refer to the object that is "target" of a method call (commonly called this), the Python language requires every method…
-
10
votes5
answers1668
viewsQ: How to use a language other than Javascript in your browser?
Despite the enormous plurality of programming languages in various environments (desktop, server, mobile devices), browser continues to support one and only one language: Javascript. The reason for…
-
6
votes2
answers1144
viewsA: Change Arraylist nodes
No, because a, b and c are of the type int, which is a primitive type. In Java, everything that is passed as an argument to a function (including constructors) is passed by value (i.e. copied). Even…
-
3
votes2
answers268
viewsA: How to create "html canvas"? (I think it’s new in html)
That doesn’t sound "native" to HTML5, but rather an external library called Polymer (Edit: as pointed out by the OP in the comments, if trada polyfill). Note the first lines of the source code of…