Posts by mgibsonbr • 80,631 points
861 posts
-
1
votes2
answers3436
viewsA: How to mount a JSON return?
The most direct way is to create an array of arrays, then convert to JSON in the same way as in the second code: $return = array(); while ($r =…
-
3
votes1
answer271
viewsA: Licensing of a Software
You can license in any way you want, because: Laravel is under the mit license, which allows the use of the code in proprietary systems; Apache HTTPD is under the apache license which - although…
-
4
votes1
answer533
viewsA: Setting matrix table in Django
I would recommend treating your data on view before sending to template: paises = list(Paises.objects.all()) # Filtre e ordene como achar melhor energias = list(Energia.objects.all()) # idem #…
-
4
votes1
answer135
viewsA: Error in programme C (determinant calculation)
Your problem is how you are creating the array aux: int i, j, k, x, y, soma=0, aux[10][10]; You are creating it with size 10x10, which means that internally a sequence of 100 elements is created. So…
-
5
votes2
answers2664
viewsA: Manipulate and model Json object
First of all you need the names of Milestones, as already pointed out in comment. I will assume that you have a type object: var milestones = { "6":"Infraestrutura" } When you receive JSON, the…
-
2
votes1
answer73
viewsA: Declaration of char in memory
You are confusing addressing with alignment (which is reasonable, myself 10 minutes ago was also confused). One thing is to determine the size of each address, i.e. if you have a variable, register,…
architecture-computersanswered mgibsonbr 80,631 -
3
votes2
answers94
viewsA: Refactoring generation of random datetime (Python)
As I do not know the purpose of your code, in principle it seems ok to me except for the fact that it never draws days 29, 30 and 31. If that date (which I see as "naive", or naive) represents a…
-
3
votes1
answer524
viewsA: How to create expression to allow just a few characters?
The problem of validating while the user type is that it is necessary not that the whole field is valid but that a prefix do the same (because otherwise the user would never be able to finish typing…
-
5
votes1
answer52
viewsA: Javascript help
The function setTimeout can be used to invoke a function after X milliseconds: var timeoutID = setTimeout(simulateClick, 10000, 1176, 435); The first parameter is the function that will be called,…
-
3
votes2
answers55
viewsA: Generate one array according to another without bottlenecks
Since category Ids are simple numbers, an object mapping ID to structure should be sufficient: function converter(produtos) { var map = {}; produtos.forEach(function(produto) {…
javascriptanswered mgibsonbr 80,631 -
6
votes3
answers20769
viewsA: javascript check if the attribute of an object exists
There are 3 situations you need to pay attention to: The attribute does not exist or its value is undefined; The attribute exists and its value is null; The attribute exists and its value is "falsy"…
javascriptanswered mgibsonbr 80,631 -
3
votes2
answers126
viewsA: How to remove the "date" we set in jQuery?
The $.data, when called with a single argument of the object type, it does not assign a single value - assign several. There is a match between individual attributes set by jQuery and attributes…
-
5
votes1
answer2622
viewsA: How to group similar objects
Create a Map to relate an object to the list of objects similar to it. Then move on to your collection, checking if the object is already there and adding to the list, or if you are not creating a…
-
11
votes3
answers4953
viewsA: How is the module math calculation (%) done in Javascript?
The concept of "module" is similar to that of "rest of the division [entire]": Dividendo ou numerador: 23 Divisor ou denominador: 10 Quociente: 2 Resto: 3 It’s not exactly the same concept…
-
18
votes1
answer4077
viewsQ: What is the difference between the elements <img>, <picture> and <figure>?
In HTML we have the elements <img> (image), <picture> and <figure>, which I believe to be a "figure" or "image". The img is well known, the others have been introduced recently. I…
-
1
votes1
answer380
viewsA: Ckeditor: How to make images responsive?
This plugin seems to be using the new attributes srcset and sizes of the element img. Here it is the specification, and the set of browsers who already support them. On what to put in the fields,…
-
6
votes1
answer666
viewsA: Generate random number between -99 and 99
Your problem is that the interval [0,200[ has 200 elements, but the range [-99,99] has only 199 elements. I suggest generating the range [0,199[ and then shift it negatively to [-99,100[: x =…
-
4
votes1
answer1247
viewsA: C program for solving mathematical expressions using binary tree
Your problem is that you seem to be assuming that a variable within a function retains its value when that same function is called recursively (i.e. all calls to cria share the same variables j and…
-
5
votes2
answers878
viewsA: When to use list comprehension and not filter+lambda?
I would not say that one is "better" or "worse" than the other, in reality both in performance and in concision the two forms are quite similar. The only thing that changes is the style programming.…
-
14
votes1
answer1271
viewsA: Webgl, Canvas and 3D Graphics
Is there a difference between Webgl and Canvas or is it just a branch of the same? The canvas is an element responsible for drawing on the page. Like this drawing is made depends on the context…
-
6
votes2
answers496
viewsA: What exactly is hypertext?
Hypertext is common text with other aggregated information. According to Wikipedia: Hypertext is the term that refers to a text to which other sets of information are added in the form of blocks of…
-
10
votes2
answers509
viewsA: How to get the instance of the top/parent object in a javascript Function?
Unfortunately what you want is not possible. The object you created is a member of the prototype of String, then the most you could (although I believe even that is not possible) would be to get a…
javascriptanswered mgibsonbr 80,631 -
2
votes1
answer1581
viewsA: Java text "encryptor" program problem
Your problem is that you are using the Scanner to read the file, not a simple BufferedReader or similar. The Scanner breaks the input into words, so that: There will never be a blank space, because…
-
7
votes2
answers1700
viewsA: Separating integer by character
First you need, for each integer, to know how many decimal digits it occupies. If you have at hand a logarithm function, better, else go multiplying a variable by 10 until she’s bigger than the…
-
5
votes1
answer71
viewsA: Copying an attribute from a list in java
In Java 8 it is possible to do this by using streams: List<MyObject> listaDeObjetos = new ArrayList<>(); List<String> nomes = listaDeObjetos.stream().map(MyObject::getNome)…
-
23
votes4
answers1065
viewsA: Is there any way to extend an object in javascript?
The problem with doing this in Javascript is that - at least until Ecmascript 5 (the version currently most supported by browsers) - This language has no classes! While in PHP, or Java, C#, etc…
-
16
votes3
answers2999
viewsA: What is the difference between for...of and for.. in?
The for..of is a new construction in Ecmascript 6, and therefore should only be used when the browsers provide appropriate support for this version, and enable it by default. Otherwise, your code…
-
2
votes1
answer149
viewsA: Increase the reliability of random numbers
You need a hash function. If I understand correctly, your final list is Li and its seed s, and the final list Lf is given by Lf = f(s, Li). Lf and s are public, and you don’t want Li only from both…
-
1
votes4
answers3096
viewsA: recursive superfatorial problem
This may not have as much relevance in this case (because the factor value - and consequently the superfatorial - grows so fast that it is impracticable to calculate it for large numbers), but the…
-
4
votes3
answers1818
viewsA: How to convert datetime/date to milliseconds in Python?
Build a timedelta from the difference between your date and the reference date, then use total_seconds to get the total of seconds contained in the interval. As this result comes expressed in…
-
2
votes1
answer848
viewsA: Row with circular chained list with head
First of all, for the list to have a head and to be circular it is necessary to create this head and make it point to itself. Dynamically, it would be this: Celula *cabeca = (Celula*)…
-
5
votes1
answer391
viewsA: Display of Latin characters in a String
If your page encoding is correct, for example by sending the HTTP header: Content-Type: text/html; charset=utf-8 Or by specifying it in HTML itself: <meta charset="utf-8" /> or <meta…
-
16
votes2
answers5548
viewsA: In OOP, can an interface have attributes?
An interface is a "purely abstract class", which only specifies a guy but not the concretization. When we speak of "attribute" in OOP we are usually referring to a concrete field - a memory position…
-
1
votes1
answer198
viewsQ: How to convert an integer to a binary string in Python 3?
If I want to convert between integers and characters, use chr and ord: >>> chr(10) '\n' >>> ord('$') 36 However I need to do a string test binary, something new in Python 3, and I…
-
3
votes1
answer694
viewsA: Double-hand encryption with fixed LENGTH
What you seek is not encryption (technique to hide data) but compression (technique to store data using a smaller amount of bits than in its "raw" format). Base64 is neither one nor the other (it is…
-
5
votes1
answer6989
viewsA: Double chained list in C
To delete a node you first need to get to it (by the way, this is something you would also need to do in a "search" function). Assuming that its function deletar also receive a Pessoa as a…
-
15
votes4
answers107040
viewsA: What is the difference between public, default, protected and private modifiers?
These modifiers are responsible for access control members of the class (fields and methods), also known as encapsulation. The idea is to assist in the creation of a stable API, but at the same time…
-
2
votes1
answer386
viewsA: How to Encrypt Images with Java RC5 Algorithm
According to that answer in Soen the JCE provides support for RC5, but no concrete implementation of it. I cannot confirm the veracity of this information, but by your exception this seems to be the…
-
6
votes2
answers1190
viewsA: How to perform an algebraic expression on a string in C
The usual ways to solve this problem is by either writing a parser (as suggested by Maniero; a simple example - in Javascript - here) that generates an abstract representation of the data, or…
-
3
votes1
answer348
viewsA: How to clone values of an object
There are two options, basically (actually three, the third being "implement all yourself"): Implement the interface Cloneable Every Java object has a method clone, capable of making shallow copies…
-
2
votes1
answer149
viewsA: How to transform a String "Caiaaaque" to another String "Kayak"?
The method replaceFirst is meant to be used with regular expressions, not strings, much less characters. For example, if you do: String s = "a.."; s.replaceFirst("" + s.charAt(1), ""); The result…
-
10
votes4
answers3187
viewsA: Should one use break in going?
Break a loop in the middle (any loop, not only the for) brings a downside which is to make it harder for the programmer to understand what state the program is in. Regardless of the construction…
-
4
votes4
answers14598
viewsA: Print only the column of a matrix
That’s not what that expression does. lista[inicio:fim] creates a sublist started (including) in inicio and terminated (exclusively) in fim: >>> [0,1,2,3,4,5][1:4] [1, 2, 3] >>>…
-
6
votes2
answers103
viewsA: Is there any risk of not validating the name of a function used in JSONP?
Absolutely! Although those who are at greatest risk are the page that uses your service (after all you could inject malicious code into it), there are attacks that take advantage of the fact that…
-
26
votes1
answer616
viewsA: Designing the Top Gear
These 2D racing games as far as I know render each line of the screen regardless of the others. If you observe a screenshot of the game (I’m assuming you refer to the first game in the series) you…
-
2
votes1
answer406
viewsA: place name in columns from an object array
First, make sure your table has autoCreateColumnsFromModel set as true. Otherwise she will ignore the functions getColumnCount and getColumnName that you created. Second, its function getColumnName…
-
8
votes1
answer9671
viewsA: Problem declaring variables for average calculation in Python 3
In Python 2, input returns a Python object interpreted according to the syntax of that language (i.e. if you type "2", it returns the number 2). In Python 3, it simply returns a string (the same as…
-
2
votes2
answers228
viewsA: Data compression. Issue for Criminal Period 2012, CESPE/Unb
The problem of the statement was not specifying whether it dealt with the best case, medium case or worst case. If we use common sense, however, we can see that this issue only makes sense when we…
-
3
votes2
answers1871
viewsA: Append methods in a list - Python
If what you want is fix some arguments of a method (as its list calls methodList, I imagine you want to keep in it methods, not values) you can use functools.partial. In it you set a fixed number of…
-
3
votes1
answer1418
viewsA: What is the correct way to use Bcrypt?
Your code seems correct to me. I don’t know this specific library (I was surprised that the workFactor was used as a parameter of GenerateSalt, and not of HashPassword, but apparently so), I don’t…