Posts by hugomg • 8,772 points
146 posts
-
1
votes2
answers341
viewsA: What would be the correct way to verify if a value exists in the table in Lua?
If you want to avoid having to do a linear search for the value, you can use the names as table key if not Namez[name] then Namez[name] = true end You can iterate the table keys with the pairs…
-
0
votes1
answer47
viewsA: How to mount this effect with JS?
One way to do this would be to use setTimeout or setInterval. I think something like that might work: var elms = $('.elemento'); var i = 0; var interval = setInterval(function(){ if (i >=…
-
2
votes2
answers66
viewsA: Use multiple javascript loops
The problem with your code is that a is a global variable. If you switch to a local variable everything works fine. arraya = [] arrayb = [] function interval(array, length, count) { var a =…
javascriptanswered hugomg 8,772 -
20
votes2
answers5391
viewsA: What is the HMAC?
HMAC is an acronym for Hash-based Message Authentication Code What would be an HMAC? An HMAC is a type of MAC (message authentication code). A MAC is a code that you can add at the end of a message…
-
0
votes1
answer118
viewsA: Segmentation failure (recorded core image) in YACC/Bison
To begin, you need to understand the cause of the error. When you pass the inputESCREVER 10; TERMINAR; be parsed as follows;: Each of the nodes of this tree corresponds to a reduction rule that will…
-
1
votes2
answers37
viewsA: Problem deleting from recursion list
I don’t know how your function is running endlessly. The impression I get is that if this function gets stuck in an infinite loop it should stop at some point with a stackoverflow error. Anyway, you…
-
8
votes3
answers214
viewsA: Javascript Check if it is safe
You do not need to use Val in this case. You can access a field determined by a string using the operator [] for (var i=4;i<=6;i++){ obj1["but"+i] = { Label: "button"+i }; } But in my opinion the…
-
0
votes3
answers582
viewsA: How to dynamically increase struct size?
One thing you can do is store only pointers in your struct typedef struct{ char *nome; char *sobrenome; size_t num_telefones; char **telefones; size_t num_emails; char **emails; } TCONTATO; If you…
-
3
votes2
answers1216
viewsA: input() and raw_input()
Yes, the input of Python 3.x is the raw_input python 2.x. This change can be found in changelog of version 3.0: PEP 3111: raw_input() was renamed to input(). That is, the new input() Function reads…
-
4
votes1
answer1052
viewsA: Parameters of the scanf function
Before we start, I think you actually wanted to use "%19[^\n]" instead of "%19[^\n]s". The second version actually means "a string up to 19 characters \n, followed by the letter "s". The reason for…
-
5
votes1
answer193
viewsA: How to create a commercial game using ready-made models in Unity without violating copyright?
That will depend on which is the furlough where the free models have been made available. If this information is not available with the models, the only way to know is to ask the original authors…
-
20
votes1
answer3361
viewsA: What is the __future__module for?
The module __future__ really is a bit magical. It would be more necessary to see the from __future__ import as a statement for the Python compiler instead of a import typical. The raison d'être of…
-
3
votes4
answers1048
viewsA: Should every algorithm be finite?
It depends on the context you’re talking about. From your book’s point of view, requiring that algorithms always end will simplify a lot. For example, it is easier to discuss runtime and…
-
2
votes2
answers524
viewsA: How to know if the code is still written in HTML5 standards?
This one is linked on the official HTML5 standard website: https://html5.validator.nu/ https://whatwg.org/…
-
2
votes1
answer464
viewsA: Partial sum of elements of a vector in O(n) or O(log n)
As written, its algorithm is O(N3). There’s a third loop implicit in the part where you add the A[i]s. In the current form of the problem, there is no better algorithm than O(N2). You have N*(N-1)/2…
-
2
votes1
answer229
viewsA: Segmentation fault (core dumped)
There is an error in your loop. You are using OR instead of E: // versão atual (*str != '\0' || *str != '\n') // versão correta (*str != '\0' && *str != '\n') The result is that the…
-
4
votes1
answer115
viewsA: When should I use "xml:" in front of some attributes?
You do not need the prefix "xml" unless you want to treat your document simultaneously as XML and HTML decument. (I don’t recommend this - I think it’s best to just follow the HTML5 specifications)…
-
3
votes3
answers5527
viewsA: List in Python with non-repeated values without using set function?
You can do it in the most direct way: Using loops, you can test if a given element of the second is in the first list (and by it at the end if it is not) With another loop, you can repeat this…
-
4
votes1
answer1070
viewsA: What is Node.js and what does it replace?
It replaces nothing. It’s just one more option that’s available... The extremely simplified view of the operation of a webpage is that the client, through a webbrowser, requests the page from a…
-
3
votes1
answer209
viewsA: setInterval does not work after clearInterval
The call setInterval(interval,2000) will do nothing. The interval is an "identervalID" but the setInterval expects a callback as parameter.…
javascriptanswered hugomg 8,772 -
3
votes1
answer93
viewsA: Algorithm and complexities
Yes. But I would use a different notation to talk about the best case. When we write that the worst case is O(f) we mean that the time spent in the worst case is asymptotically less than or equal to…
answered hugomg 8,772 -
3
votes3
answers213
viewsA: Why don’t I need to pass parameters to that function?
In Javascript the expression value troca(banner2) is the return value of troca. When you call blah.addEventListener("mouseover", troca(banner2)); it’s like you’ve written var tmp = troca(banner2);…
-
1
votes2
answers525
viewsA: Error with sem_init() function on Linux
The error you got is an error of linkage. Your C code is correct and the functions you use are declared in the ". h" files you include. However, when generating the executable your compiler is not…
-
1
votes1
answer1467
viewsA: Using recursion to count the number of times a number appears in a list
In most programming languages, each function call needs a few bytes of the runstack and in general there is a maximum limit to the stack size. On a desktop computer today that limit is usually on…
-
5
votes2
answers2637
viewsA: What is the point and difference of using <![CDATA[]]> inside a <script> tag?
From the Javascript point of view, this CDATA does nothing because it is inside a comment. It is there as an HTML to become a valid XML document besides being simply an HTML document. For example…
-
0
votes2
answers258
viewsA: Is there any way to reverse javascript minification?
If you just want to reverse the minification for debugging purposes, the debuggers of Chrome and firefox are able to reindentify the minified code for you.
-
3
votes1
answer149
viewsA: Write list in binary file
pal is a pointer to char then *pal will be a memory position containing a char. When você faz*pal = cvocê está armazenando um char na posição de memória apontada pelo ponteiropal`. I think what you…
-
5
votes3
answers432
viewsA: Javascript - Thread, Asymchronism, Ticks
I think the best way to clarify this problem is to highlight the difference between competition and parallelism and the difference between cooperative and preemptive. In parallel computing you have…
-
9
votes1
answer1625
viewsA: How to include a C function in Python?
The first thing you will have to do is generate a dynamic library with your C code. On Linux this means a bilioteca ". so" and in windows would be a ". dll" Assuming you are on Linux and your C file…
-
0
votes3
answers320
viewsA: I can’t fix this bug in Python, I’m a beginner
In your program, trans1 and trans2 are of the tuple type (apparently, tuples of characters). To do against you need to be numbers trans1 = float(price) trans2 = float(usertap)…
-
4
votes1
answer426
viewsA: Document.write function does not write two messages
The Document.write function is full of quirks. For example, it does different things while the document is loading and after it has finished loading. If you want to print some things for debugging,…
javascriptanswered hugomg 8,772 -
3
votes2
answers2449
viewsA: Not a git Repository (or any of the Parent Directories): . git como resolver?
When you give clone git creates a nine directory for the repository. You have to run git checkout from within that directory. Try to make a cd teste-site If you do not want to specify the name of…
-
2
votes2
answers89
viewsA: Array.prototype.filter does not work as expected
The filter method returns a list and Javascript lists always count as "true" in a Boolean context (including the empty list). if( [] ){ console.log("Olá!"); }else{ connsole.log("Esse else nunca…
javascriptanswered hugomg 8,772 -
6
votes2
answers46
viewsA: Doubt with syntax
It’s the equivalent of doing it here: var db = require('../lib/dbconnect'); db(config); The require function returns the exported value in the dbconnect.js file. This module exported a single…
-
2
votes1
answer58
viewsA: Javascript - Settings Steps
You can write your state machine "in hand" using mutually recursive functions: function faz_coisas(onDone){ function passo1(){ umaCoisaAssincrona(function(result){ blah(); passo2(); }); } function…
javascriptanswered hugomg 8,772 -
1
votes2
answers241
viewsA: Extensive matrix makes the program stop working
A simple alternative to solve this problem is to allocate the matrix at compile time rather than at runtime on the stack. int main() { static int matriz[2000][2000]; return 0; } This is equivalent…
-
1
votes2
answers159
viewsA: Javascript and C language accessing the same database
In general it is not a good idea to allow the client to access the database directly, since a malicious client can send any message to the server. For example, a client could send an SQL command to…
-
1
votes3
answers146
viewsA: Perfect square, not so perfect
One possibility is to do a binary search. So you don’t need to use float. unsigned intSqrt(int N){ // invariante: lo*lo <= N < hi*hi unsigned lo = 0; unsigned hi = 1<<16; while(hi - lo…
-
5
votes3
answers161
viewsA: How can I make this code more functional in Javascript?
The suggestion I would make is to make a sieve of erastostenes instead of an algorithm of "trial Division" function PrimeMover(num) { var N = 10000; var isPrime = []; isPrime[0] = false; isPrime[1]…
-
0
votes1
answer3569
viewsA: Passing information from a file to an array
There are several problems with your code. I’ll tell you what I found but I can’t guarantee it’s an exhaustive list. First of all don’t just read 256 characters of input and play straight into the…
-
2
votes3
answers4312
viewsA: How the end of file loop is done
The feof function says if any file reading function has ever tried to read some input and failed due to the end of the file. It does not say if a reading function will be able to read the next…
-
6
votes8
answers794
viewsA: Mapping an array with possible subarrays as elements
The most common name for this function you want is "Flatten". For me, the easiest way to implement this function is with recursion. function flatten(inputArray){ var out = []; function go(x){…
-
9
votes4
answers10409
viewsA: How do you display "Press ENTER to continue" in Python 3.4?
Simply do not store the input output in a variable input("Pressione ENTER para continuar")
-
6
votes1
answer134
viewsA: Is there a difference beyond the syntax between Self-invoking-Functions?
All versions end up doing the same thing, which is calling the anonymous function, and it’s more a matter of taste. I prefer version 2 (function(){ ... }()) because I think it’s clearer with the…
-
4
votes1
answer90
viewsA: Why can’t I get value returned by function?
The problem is that the return within the function carregarCursos applies only to carregarCursos. It will not "jump out" and serve to return a pro value getCursos. In the way your code is written,…
javascriptanswered hugomg 8,772 -
4
votes2
answers664
viewsA: How to share functions between javascript files?
The simplest way is to include archive1 before archive2 in your HTML: <!doctype html> <html> <head> <script src="arquivo1.js"></script> <script…
-
2
votes1
answer589
viewsA: Object Object, how to not issue this alert
These alerts are not standard behavior of your javascript. You’ll have to sift through your code and find who is calling the function alert. "Object Object" occurs when someone passes a pro object…
-
3
votes1
answer207
viewsA: Is it correct to clean an internal malloc to a function with it?
But if dereferencing is done through the function itself? When you do free(foo()), you are not doing the free "through foo". You are simply giving free on the return value of foo(). It is as if you…
-
3
votes2
answers330
viewsA: Should I wear rebase?
The result will be the same. In both rebase and merge, if the same line is changed in both branches it creates a conflict for you to resolve manually. If any modification of the master went without…
-
12
votes3
answers1812
viewsA: Questions about Latex
1) Latex elements for example (summary) are editable ? for example, can I change the summary name and put Index ? or exchange the numeration for Roman numerals? Tex is extremely flexible. If you’re…