Posts by hugomg • 8,772 points
146 posts
-
5
votes1
answer169
viewsA: Special treatment for string, why?
The quick answer is yes, C has special treatment for strings, "because yes". The long answer is that you are assuming that C vectors and pointers are totally interchangeable in C, which is not true!…
-
3
votes1
answer62
viewsA: How does strtoull work?
The first parameter of strtoull is the string to be converted. The third parameter is the numerical basis. For numbers written in decimal is 10, for hexadecimal is 16, etc. The second parameter has…
-
2
votes1
answer138
viewsA: What is the difference between the streql() and strcmp() functions of the header string. h?
strcmp(s1,s2) returns a negative number if S1 < s2, returns zero if S1 = s2 and returns a positive number if S1 > s2. The streql function is not part of the C standard and is an extension…
-
2
votes1
answer82
viewsA: Error reading binary file
Without having the complete code to run, it’s hard to guess exactly what’s going wrong. That being said, one thing that is strange about your code is that you are reading the value of the field…
-
1
votes1
answer3712
viewsA: How to scroll through a 2-dimensional matrix in C and display?
Compile your program with warnings (option -Wall) that the compiler will give you a hint of what’s wrong. The problem you have is that a two-dimensional matrix must be accessed using matriz[i][j],…
-
5
votes3
answers4208
viewsA: Is it possible to create an object dynamically in JS without using Eval?
Your Eval code is already using the trick you need to no longer use Eval: Access properties via string: //Em Javascript esses dois são equivalentes: obj.foo = 17 obj['foo'] = 17 Already to make your…
-
2
votes1
answer76
viewsA: I can’t run code after the cycle is
Syntax error means that the Python interpreter cannot recognize your program as valid Python code. Usually this means that you have some keyword or keyword missing (or left over) in your program or…
-
0
votes2
answers4158
viewsA: How to create a dynamic chained list within another dynamic list in C?
Assuming that each song can only be on a single album and that each album can only belong to a single band, the notmal would be to make each album node contain a pointer to the first song on its…
-
1
votes1
answer79
viewsA: Help to save a table
There are a myriad of ways to solve this table serialization problem and the moon-users.org wiki has a good list of alternatives: http://lua-users.org/wiki/TableSerialization…
-
10
votes1
answer31551
viewsA: Pass matrix as function parameter?
In C, you need to specify the size of all dimensions of a matrix that is function argument, except the size of the leftmost dimension. For example, if you set that your matrices will always be…
-
2
votes1
answer56
viewsA: Detect ":" and show suggestions with jQuery
There are some libraries out there to make autocomplete inside a textarea. Have you ever thought about using one? For example: https://github.com/yuku-t/jquery-textcomplete If I’m not mistaken, most…
-
12
votes3
answers1996
viewsA: What do I need to do to measure password strength?
As mgibsonbr says in his answer, the strength of a password is associated with the difficulty an opponent has to guess it. Therefore, we measure the strength of a password rule based on how many…
-
2
votes2
answers798
viewsA: How to determine the value of X using Javascript
To solve a second-degree equation like this one you can use to baskara formula. If the factors multiplying the X and the X2 always be that of the question, don’t need to use Javascript. You can make…
javascriptanswered hugomg 8,772 -
4
votes1
answer273
viewsA: Simple error in code in Haskell
There are a lot of errors in your code but the good news is that most of them are just syntax error, which is easy to solve :) Type declaration syntax The guy statement says eq2grau receives a…
-
1
votes3
answers146
viewsA: Modification of Javascript on websites
The user will always be able to use a proxy to intercept communications with the server and modify them before the data reaches the browser. There’s nothing to do.
-
11
votes2
answers1444
viewsA: How to organize code without losing performance?
Using functions instead of putting code directly influences a program’s performance ? No! Function calls, especially in C, are quite fast. There are many other things that will make your program…
-
3
votes2
answers279
viewsA: Algorithm for (A+Bi) n
Rafael’s answer solves the problem in the smartest way (by converting the complex to a trigonometric representation), but I think it would be interesting to show that it is not difficult to solve…
-
2
votes1
answer753
viewsA: Regular expressions with grep
Firstly, grep is a shell command and its arguments are simple strings like any other. Instead of delimiting regex with / you should use single quotes (or double quotes if you are careful with…
-
7
votes2
answers280
viewsA: How to implement a library that has features similar to jQuery?
The Jquery code is public, why not go take a look at how they do it to take inspiration? : ) If you want a hint, these files here contain the part that defines the "Builder" of jQuery.…
javascriptanswered hugomg 8,772 -
6
votes3
answers5066
viewsA: What is parallel programming?
What is parallel programming? Briefly, this is when you divide a computation between various machines or processors that run at the same time. Don’t confuse parallelism with competition. For…
-
2
votes2
answers728
viewsA: ASCII encryption in C
One mistake you have in your code is that sizeof(password) does not contain the number of letters of the password. It will be the size of the pointer, which will probably always be 4. In C you must…
-
2
votes1
answer140
viewsA: Problems to delete a "circle" object that is on google-maps
You are creating a single object elemento and overwriting your fields in each loop iteration. var elemento = { idade:{}, genero:{}, circulo:{} }; $.each(mJsonData, function(id,data){…
-
2
votes5
answers2736
viewsA: Test whether all characters of the first string also appear in the second
A more efficient solution to this problem involves sorting the strings before starting to compare them. In pseudo code; ss = sort(s) // "acb" vira "abc" sv = sort(v) // "cdeabf" vira "abcdef"…
-
5
votes1
answer87
viewsA: Compile Archive . ly
Haskell source files notmalmente have the extension .hs (for normal Haskell files) or .lhs (for "literate" files, where the default for each line is to be a comment and lines of code are marked with…
-
3
votes1
answer101
viewsA: How to get the name of the parent object of the Javascript property
There is no special syntax to do what you want. Javascript objects have no pointer pro "father" (after all, if there was a difference if an object is stored in a table, list or variable - it would…
-
3
votes1
answer124
viewsA: Is it recommended to use prototype on native objects?
Like all programming style questions, there is no 100% right answer in this case but I’m not a big fan of adding methods to native objects. The native methods prototype has a global scope. If two…
-
3
votes3
answers1207
viewsA: What’s the difference when calling a function with parentheses and without in.py urls with Django 1.7?
What’s happening there inside the url function code is something like this: def url(regex, view): request = make_request() view(request) The view parameter is a function that receives a request. The…
-
11
votes7
answers2649
viewsA: Should people’s names be stored in two or just one column?
Different cultures has different concepts of what a name is and how to write the names. In some cultures, there’s no last name! Unless there is some important requirement to store the separate…
-
5
votes2
answers589
viewsA: Is it possible to name a parameter at the time of the function call?
The usual way to make named or optional Javascript parameters is to pass an object (dictionary) as parameter. A famous example is the function ajax from the jQuery library. In your case it would…
-
2
votes1
answer1004
viewsA: Capture value of an asynchronous function in Nodejs
There are several problems with your code but the basic problem is that you are assuming that the line after the asynchronous function call only runs after the server has responded. In fact the…
-
3
votes1
answer222
viewsA: Have all the machine code programmers who complained about Assembly changed their mind about Assembly?
The fun of programming in Assembly rather than directly in machine language is precisely that you can name things rather than refer to everything directly from the address of memory. For example, in…
-
5
votes2
answers2699
viewsA: Revert a string and add method to native objects in Python
The reverse of Python lists reverts to the list in place, changing the list values instead of creating a new list written inside out. Since Python strings are immutable, it doesn’t make much sense…
-
7
votes3
answers10342
viewsA: What are Unions? Why use them within structs?
The difference between Union and struct is that a struct is an "E" and stores all fields while a Union is an "OR" and all fields are in the same memory position. If you update a Union field all…
-
-1
votes4
answers2080
viewsA: How to capture elements in a json structure using javascript
If I understand correctly, your problem is in the "CREDIT_CARD", "MASTERCARD" and "SMALL", right? If so, what you need is to use the "for-in" loop to traverse an object’s keys // Esse código imprime…
-
2
votes1
answer667
viewsA: Hours calculation
You can use division to know how many full days you used and how many hours left. To avoid confusion in this example (due to two different values worth 8), I changed the deadline to 7 hours. Also,…
-
1
votes2
answers651
viewsA: Licensing of Mysql
To community version of Mysql is under the free code license Gplv2. You can use mysql for free. The only thing you can’t do and make modifications to Mysql without republishing them as open source.…
-
1
votes4
answers1177
viewsA: How not to repeat terms on printf
An alternative way to solve this problem, more efficiently, is to first sort the two vectors and then do a "merge", similar to what you would do in mergesort.
-
2
votes1
answer372
viewsA: How to avoid an XSS vulnerability in an HTML FORM?
XSS is not about the particular form tag. Fundamentally, the problem is when you include some user-controllable text somewhere that will be interpreted as HTML instead of text. The solution to this…
-
6
votes3
answers561
viewsA: Nth value of a binary search tree
A super simple way to get around the difficulties of this problem is to use global variables for the search parameters and return value pro, which allows you to keep the recursive function focused…
-
1
votes1
answer246
viewsA: Regular Expression that checks the presence of a repeating Pattern
You can use {n} for something that repeats a fixed number of times. For example, the regular expression a{8} recognizes a sequence of 8 characters a. In addition, it also has {n,m} for "of n a m…
-
2
votes1
answer784
viewsA: Dismember full numerical expression in C
I don’t know if it’s worth trying to adapt your code to make it work. It will not work very well to have a big loop on the outside being that in each iteration you want to do something different (in…
-
4
votes2
answers348
viewsA: Singleton in Javascript
If what you want with a Singleton is to have a single instance, it doesn’t really need to complicate much. But without seeing an entire example, you can’t tell if your sample code is correct. For…
-
5
votes1
answer704
viewsA: Scatter table (Hash Tables)
One very important thing to keep in mind when using hash tables, especially with open addressing, is the load factor: the ratio of the number of distinct keys in the table to the maximum capacity of…
-
4
votes3
answers476
viewsA: How to see the implementation of a function?
What’s the difference between getchar(), gets() and scanf()? getchar reads one character at a time, gets reads an entire line at a time and scanf is a generic function that does different things…
-
31
votes2
answers2760
viewsA: What is a memoization?
Memoization is to use a cache table to avoid having to recalculate the value of a function more than once. A classic example is a naive implementation of the Fibonacci function: function fib(n){…
-
4
votes2
answers1258
viewsA: Is it possible to open an IDLE file from the terminal?
The Python interpreter only runs Python programs, it does not come with a built-in editing interface. What you can do is use a text editor to write your program (anyone but Word serves: Notepad++,…
-
68
votes2
answers35446
viewsA: What is the complexity of an algorithm?
The complexity of an algorithm has to do with how much time and memory this algorithm takes according to the size of its input. For example, we want to answer questions like "if my algorithm takes 1…
-
2
votes5
answers573
viewsA: Why are you wearing shorts?
As far as I understand (and correct me if I’m wrong), it’s faster to work with an entire processor architecture size in most cases due to CPU optimizations. Actually, defining variables of the short…
-
11
votes1
answer16087
viewsA: How to return vector size with sizeof()?
In C, as soon as you pass an array to a function the array "decays" to a pointer to its first element. The length of the vector is forgotten and the only way to pass it to the function is by using a…
-
33
votes3
answers2698
viewsA: What are covariance and countervariance?
In object-oriented languages, if a function or variable expects to receive an object of a type you do not need to pass it an object of exactly this type: according to the the principle of Liskov’s…