Posts by hugomg • 8,772 points
146 posts
-
4
votes2
answers883
viewsA: When to convert a bitmap to string Base64?
Base64 is a way to write an array of any bytes using only letters and numbers (plus a couple or three symbols). Note that Base64 is not a universal standard but rather a family of similar encodings:…
-
4
votes5
answers7954
viewsA: Removing the " n" from a string read using fgets()
One thing you can do is read the string with the '\n' and delete it later by typing a ' 0' instead of the \n. Another thing you can do is read the string letter by letter, via Getcha. So you have…
-
3
votes3
answers176
viewsA: How to get the line separation of the system
You can do something very close to what you want without using Javascript. The HTTP header User-Agent includes information about your client’s browser and operating system and your server can look…
javascriptanswered hugomg 8,772 -
9
votes2
answers280
viewsA: Pass two parameters to a function that accepts only one parameter
What you found is a bitfield and is a common way of representing boolean parameter sets in a compact way. The way it works is that each bit (i.e., power of two) of the value represents a different…
-
2
votes1
answer198
viewsA: Global Differences in Userscripts in Chrome and Firefox
For security reasons1, greasemonkey Userscripts run in a sandbox separate from the normal scripts on your page. In particular, the greasemonkey script has a window difference of window of the rest…
-
2
votes3
answers226
viewsA: Picking Indentation with Regular Expression
If you really want to use a regular expression, I think the following regex does what you want: ^(\s*)style\(data-above-the-fold="true"\)\.\n(\1\s+.*\n)* http://regex101.com/r/mZ2xS4/3 The ^(\s*)…
-
0
votes3
answers226
viewsA: Picking Indentation with Regular Expression
Maybe you can solve your problem with Regex but I believe that the restriction of making the sequin lines have more indentation than the first would make the regex very complicated. I would solve…
-
5
votes1
answer850
viewsA: How to "call" a function from a Lua table in C++
Its function actually has 4 arguments. The code function vec:func(x, y, z) print("vec:func:", x, y, z) return "return: OK" end is syntactic sugar for vec.func = function(self, x, y, z)…
-
7
votes1
answer498
viewsA: Check values in txt
For starters, io open. returns a Handle to the file (you are currently throwing it away) local fil, err = io.open("arquivo.txt", "a+") if not fil then error(err) end After that, you can use the…
-
13
votes4
answers317
viewsA: Why are maps "faster" than arrays?
To search for an element in an arbitrary vector it is necessary to traverse the elements of the vector one by one. In an array of N elements, this means that on average you will have to do N/2 tests…
-
1
votes3
answers4201
viewsA: Fire an event using pure Javascript
An alternative that can be simpler is to build a layered architecture, which allows you to call your code directly without being through the event system. function huehue(){ alert('HUE HUE HUE BR')…
-
4
votes1
answer261
viewsA: Regex in a switch case
switch in Javascript only works with constants. To test against patterns you would have to use ifs even more because you need to be explicit about the order in which the tests will be done.. var…
-
5
votes2
answers148
viewsA: Detect when a form is sent
$('#form').submit(cb) is a shortcut to $('#form').on("submit", cb). If you want to avoid jquery you can make this event bind using onsubmit or addeventlistener. To unsubscribe from the form you can…
javascriptanswered hugomg 8,772 -
12
votes1
answer886
viewsA: What is the difference between automata and grammars?
Formal Languages In the study of formal languages, one language is a set of strings on an alphabet. A string is a sequence of letters obtained from a given alphabet1. note: String is usually…
-
2
votes2
answers428
viewsA: Problem with IF Shell Script Syntax
Shell is a weird programming language. Technically, the [[ is not a de-taxe element, but is actually a command that needs to be separated from its arguments using spaces. Try rewriting your ifs in…
-
3
votes1
answer503
viewsA: What simulate, NFA or DFA?
I think the most important question to answer is the usefulness of Nfas. The rest comes easy later. 1) Why use nondeterminism? The main reason is that it is easier to encode some things if we can…
-
1
votes2
answers651
viewsA: How to use onload on DIV elements?
One way to know if an element exists with jQuery is to use the length property. $('.elem').length tells you how many elements there are on the page that match the selector .elem. if(…
-
7
votes1
answer1441
viewsA: Execution flow of a Try/catch/Finally block
How the execution flow works in a Try/catch/Finally block in the example below? You will enter the Try and play an exception. As predicted, the println after makeException() will not run. After…
-
4
votes3
answers2648
viewsA: Automatic calculation in text box
The answer from Sérgio using Eval is a simple solution but it has some problems: Security: Eval will execute any Javascript code, not just arithmetic expressions. You have to take care that only…
-
4
votes1
answer1101
viewsA: Cookies or Session by Javascript
You will not be able to do your authentication using only Javascript. Some part of the authentication process will have to be done on the server, since you cannot trust that the client will execute…
-
1
votes2
answers344
viewsA: link factoring
My tips: What is the factor of 0? This would be a better value to boot fat, since then you print the correct answer if the loop does not run at all. Note as the final result of fat depends only on…
-
1
votes3
answers2402
viewsA: To assign the chosen value in a select (HTML) to a php variable
On the HTML page you co-install, place the select within an HTML form. <form name="meuFormulario" action="umapagina.php" method="POST"> When the user subends the form, the browser will make an…
-
2
votes1
answer377
viewsA: Is it only possible to write code with bugs or vulnerabilities in C?
The reason you hear a lot about errors using C is because it’s a language extremely popular, used in many important systems and libraries where some easy errors of cometor can be converted into…
-
3
votes2
answers3105
viewsA: What is the question mark in a query?
Code injection problems can occur whenever you mix two separate languages. For example, SQL injection bugs occur when we treat user data as SQL code and pass to the database run and XSS defects…
-
7
votes4
answers1443
viewsA: Should an enumeration be constant in the lifetime of the solution?
Modern languages often have an enumeration type that is usually a range of related constants. Translation: Programming languages derived from C often have a type of enumeration that is usually a…
-
1
votes3
answers318
viewsA: Is referring to an element via its id considered bad?
One of the disadvantages of using dynamically created global variables via Ids is that it becomes more difficult to use a static analysis tool like Jshint to detect typos in accidentally created…
-
19
votes4
answers4078
viewsA: Pros and cons of the functional paradigm and Haskell
To tell the truth, I think the term "functional programming" is not very precise, and I would prefer to separate Lisps from ML-style typed languages (Haskell, Ocaml, F#, etc). That said, to answer…
-
5
votes2
answers358
viewsA: Reference in Flyweight design pattern
I don’t know if these terms "intrinsic" and "extrinsic" have a t or if they are only part of the explanation of the chapter but there is nothing magical about it. At the end of the day, if you want…
-
3
votes4
answers15597
viewsA: Can foreign key become primary key?
There is no problem the key of a table also being a foreign key. These concepts are independent of each other. The concept of key and primary key serves to restrict the values between rows of a…
-
1
votes1
answer120
viewsA: How to import Lua packages to Love?
When you give a require("iup"), interpreter will search for the iup file in a number of directories, depending on the configuration of your module system. In your case, the places where LOVE…
-
3
votes3
answers2755
viewsA: How to assign the results of a function that returns a list of objects?
Not all programming languages offer a succinct way to assign values to more than one variable at a time - in a way, Python is an exception. That question in Stackoverflow in English documents some…
-
1
votes4
answers1082
viewsA: How to verify that the properties of the window object are native?
One possibility is to "backup" the window before running your Scan. After that you can compare the values of the functions with the old value of the backup to see if there was a change. //Coloque…
-
1
votes4
answers2192
viewsA: How to insert a string containing the *character in the mysql database
If you use a parameterized query the bank will be able to insert special characters without any problem. You only need to escape the values if you are creating the query at hand, with fixed…
-
0
votes4
answers152
viewsA: Is a compiler allowed to omit a reference member in a class?
A subclass of Type can overwrite constructor and initialize ref differently. This would invalidate this optimization.
-
6
votes3
answers568
viewsA: Is there an advantage to an explicit "self" instead of the implicit "this"?
One of the advantages of using explicit self is that you simplify the language: With explicit self the scope of self will be a lexical scope equal to that of all other variables. No need to create a…
-
3
votes3
answers1400
viewsA: What are the ways to apply Eval in Javascript
Two other ways to retrieve Javascript code from a string are the Function constructor var f = new Function('alert("oi")'); f(); and create a tag <script>, as suggested here: var scrEl =…
-
3
votes2
answers205
viewsA: What is the difference between Scheme sequels and other languages?
The callback functions of the nodejs are not a particular case of continuations. "Continuation" is a more general term than that. Translating from wikipedia: A continuation is a representation…
functional-programminganswered hugomg 8,772 -
18
votes8
answers5453
viewsA: Why in some if’s situations are considered bad?
Conditionals are one of the largest sources of complexity for code. A 1 conditional code has two paths that the execution stream can take; a 2 conditional code in sequence has 4 possibilities and so…
-
2
votes3
answers9448
viewsA: Javascript use of Eval(): what are the pros and cons?
In the example you gave, the alternative to Eval would be to use a vector instead of a bunch of separate variables: var vals = []; var tdVals = []; var tdAtual =…
-
7
votes4
answers1141
viewsA: How to simulate "tail recursion" in C#?
As others have mentioned, C# doesn’t give you a surety that a tail recursion will be optimized. I’m a huge fan of tail recursion but I think you’re focusing a little bit on the wrong direction - I…
-
1
votes4
answers574
viewsA: Is it okay to store the password in a public class variable?
The public and private object orientation has to do with the organization and modularization of your code and nay are an important factor in security. A public variable will not be visible outside…
-
3
votes3
answers8488
viewsA: What happens in a conversion from a char to an int?
C characters are encoded in integers according to ASCII 1 standard. As Victor pointed out in responsible for him, the ascii codes of the numeric characters are consecutive, starting with 48 to zero.…
-
8
votes2
answers483
viewsA: How to show the files that need to be commited?
The command git status provides various information about the current status of the repository. This includes which changes are in the staging area (and will be included in the next commit), which…
-
25
votes3
answers12047
viewsA: Why doesn’t C# allow multiple inheritances?
Inheriting many concrete classes is a major source of problems from the point of view of the design of a programming language: what to do if the two superclasses have a method of the same name? What…
-
9
votes4
answers556
viewsA: What is the fastest, most memory-saving type?
First of all, be careful not to make premature optimizations because it is very easy to write a complex and "optimized" program that is actually slower than a simpler and more intuitive program.…
-
13
votes7
answers20675
viewsA: What are lambda Expressions? And what’s the point of using them?
A lambda expression is a concise way of declaring a function or subroutine. In an object-oriented world, it’s very similar to an object that has one method. There are two main advantages of using a…