Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »

Welcome to Software Development on Codidact!

Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.

Activity for hkotsubo‭

Type On... Excerpt Status Date
Comment Post #281551 @#64628 It depends on what data the application considers "valid". If I want to be very strict and allow, let's say, only "valid text in a specific set of languages" (or anything closer to that), preventing zalgo text would be a good start, as it wouldn't allow lots of non-sense gibberish (it won't p...
(more)
4 months ago
Comment Post #289928 @#64628 You suggested an alternative that leads to the same problem, I just thought this was worth mentioning (not only for you, but for any future readers). Otherwise, one could read this and think that your solution would avoid the problems caused by a forced push (which is not the case).
(more)
7 months ago
Comment Post #289928 @#64628 This doesn't eliminate the problem. Let's suppose the remote has 3 commits: ``` A <-- B <-- C (main) ``` And suppose that lots of people already pulled it (so they all have the 3 commits in their local repos). If I reset main to commit A (either by force push or directly in the ser...
(more)
7 months ago
Comment Post #289928 If the previous commits (the ones that got lost after `reset`) were already pushed, you can't avoid a forced push. The only way to avoid it, AFAIK, is to not rewrite history that's already pushed (don't `rebase`/`reset` if it affects already-pushed commits). Instead, you could `revert` the commits...
(more)
7 months ago
Comment Post #289928 Actually, this solution is not restricted to `main`, as it works for any branch. Regarding `push --force`, just [be aware of the risks before you do it](https://www.gitkraken.com/learn/git/problems/git-push-force#the-risks-of-git-push-force).
(more)
7 months ago
Comment Post #289780 To shift the elements, you could also use `System.arrayCopy` as below: ```java int array[] = // some array int indexToRemove = // index to be removed int newSize = array.length - 1; System.arraycopy(array, indexToRemove + 1, array, indexToRemove, newSize - indexToRemove); // then you can do a...
(more)
7 months ago
Comment Post #289778 Complementing the answer from @#53034 below, if removing is a common operation that needs to be done lots of times, consider using a `List` instead of an array.
(more)
7 months ago
Comment Post #289491 @#64926 Actually, a commit is a snapshot (references: [1](https://git-scm.com/book/en/v2/Getting-Started-What-is-Git%3F), [2](https://github.blog/2020-12-17-commits-are-snapshots-not-diffs/)): it contains a pointer to a tree object, which represents the state of the whole working dir - BTW, a tree co...
(more)
8 months ago
Comment Post #289289 I didn't add this to [my answer](/posts/289289/289295#answer-289295), but one of the reasons *could be*: most commands manipulate the current branch you're working on (`add`, `commit`, `revert`, `status`, `log`, `rebase`, etc), and making `merge` work different would be confusing in that matter.
(more)
9 months ago
Comment Post #289229 In some languages, the assignment also yields a value. For example, in JavaScript `console.log(sum = a + b + c)` will assign the value of `a + b + c` to `sum` and yield its value, so `console.log` will print it. In this case, the whole thing `sum = a + b + c` would also be considered an expression?
(more)
9 months ago
Comment Post #287932 As a side note, the documentation calls it ["Old string formatting"](https://docs.python.org/3/tutorial/inputoutput.html#old-string-formatting). Nowadays, you can use `str.format` method (since Python 2.6) or [*f-strings*](https://docs.python.org/3/reference/lexical_analysis.html#f-strings) (since Py...
(more)
about 1 year ago
Comment Post #287682 Actually, hours and minutes are not being used, so you could also remove them: https://jsfiddle.net/86x0jtu7/1/
(more)
over 1 year ago
Comment Post #287682 `getSeconds`, `getMinutes` and `getHours` are functions (actually methods, but anyway), and they need to have parenthesis to be called - so change them to `getSeconds()`, `getMinutes()` and `getHours()`, and it'll work: https://jsfiddle.net/7tar9uvw/
(more)
over 1 year ago
Comment Post #286994 > "*The strikethrough on 'd'?*" Yes! One idea to make it easier to find: the line that was changed has a different highlighting, which means the system *already knows* that the difference is on that specific line. Maybe it could show only that line (or have an option to toggle between "show all...
(more)
over 1 year ago
Comment Post #286994 Regarding the second case, there's an example [here](https://software.codidact.com/posts/284597/history): in edit #6, only one character was removed, and there's a strikethrough showing that. It's still hard to find because it's only one single char in a long post, but I guess we can consider this is...
(more)
over 1 year ago
Comment Post #286948 IMO, enabling articles would be great. Sometimes you just want to write a post explaining "what is X and what it's used for". And for those cases, the question tends to be very silly ("*I've heard of X, but what is it?*). An article could simply skip this "made up a question" part and go straight ...
(more)
over 1 year ago
Comment Post #286307 As explained in [other answer](https://software.codidact.com/posts/286304/286334#answer-286334) and in [another comments thread](https://software.codidact.com/comments/thread/6166), this code can break the HTML structure and it's not recommended.
(more)
almost 2 years ago
Comment Post #286409 @#56529 I've made a quick test here and it seems that the argument is required. If you don't want any option to be passed, just use an empty object, and it'll use the defaults (as [described in the docs](https://davidjbradshaw.github.io/iframe-resizer/#options)): ~~~javascript iFrameResize({}, '#...
(more)
almost 2 years ago
Comment Post #286349 @#56529 > "*from my experience with elementary and basic JavaScript tutorials it's not common*" Well, from my experience (I'm not bragging about it, but it goes beyond basic), it's not uncommon. Regarding readability, well, that's very subjective, and setting an initial value is not always nece...
(more)
almost 2 years ago
Comment Post #286357 @#56529 Based on your last comments (here and in another posts), I guess the main issue is to understand recursion and how this relates to DOM tree traversal. I've edited the answer and added **lots** of stuff to explain what's going on with this code. I also suggest you to read Dirk's answers a...
(more)
almost 2 years ago
Comment Post #286351 @kalispero Sorry, I had too many unread notifications and probably missed this one
(more)
almost 2 years ago
Comment Post #286372 "*Operator precedence rules of JavaScript or of Math?*" Both: - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence - https://en.m.wikipedia.org/wiki/Order_of_operations
(more)
almost 2 years ago
Comment Post #286372 Zero multiplied by anything is zero, so `0 * 42` is zero. Thus, `-1 + 0 * 42` is `-1 + 0` (because of operator precedence rules, multiplication is made before the addition), which results in `-1`.
(more)
almost 2 years ago
Comment Post #286358 The code is traversing the DOM tree, just like I imagine a tree-walker would do. I would say it's an *actual* tree walker, then :-)
(more)
almost 2 years ago
Comment Post #286358 `e.childNodes.forEach(replaceIn(document.body))` is wrong, the correct is `e.childNodes.forEach(replaceIn)` - that's because the `forEach` method receives the function that will be called for each element. By doing `replaceIn(document.body)`, you're calling the function, and the result is being passe...
(more)
almost 2 years ago
Comment Post #286358 Consider the analogy of the labyrinth in [Dirk's answer](https://software.codidact.com/posts/286349/286352#answer-286352): to do the task in all rooms you need to visit all of them. There's no way to do that without actually visiting every single room. In a similar way, you can't replace all the n...
(more)
almost 2 years ago
Comment Post #286334 The non-dangerous solution is what's already suggested, anything else will be a workaround and won't properly work for all cases. The problem with `innerHTML` is that it's a single string with everything in it (tags, attributes, etc, all in a long, unique string). To break it into parts, you'll ne...
(more)
almost 2 years ago
Comment Post #286358 @#56529 You simply call the function with the element: `replaceIn(document.querySelector('whatever'))`. Or, as it was made in your other question: `replaceIn(document.body)`. There's no `replaceAll` because the elements in a page are organized in a DOM-tree - it's a hierarchical structure (as exp...
(more)
almost 2 years ago
Comment Post #286351 @#56529 Note that `(x == 42)` is a comparison (it's checking if `x` is equals to `42`), so the result is a boolean (it can be `true` or `false`). In this case, the result is `true`. But when you multiply a boolean and a number, the boolean is automatically converted to a number (JavaScript does a ...
(more)
almost 2 years ago
Comment Post #286357 @#56529 > "*I am starting to think that my problem with this code is not the if-else*" I agree. The logic behind `if`/`else` is always the same: if the condition is true, do this, otherwise do that. Perhaps your issue is actually understanding what the "_this_" and "_that_" are doing in this pa...
(more)
almost 2 years ago
Comment Post #286351 @#56529 You must assign a value to `x` before running that: ```javascript x = 42; x = (x == 42) * -1 + (x != 42) * x; ```
(more)
almost 2 years ago
Comment Post #286349 `let node;` **is** "regular JavaScript". It's just declaring a variable without assigning an initial value, which is not uncommon. I didn't assign a value because it wasn't needed, as this will be made in the loop. Of course you could do: ```javascript let node = 1; while ((node = walker.nextNod...
(more)
almost 2 years ago
Comment Post #286349 Perhaps you could rephrase the question to "how this recursive function works", because that seems to be the main issue (once you understand this, the `else` and `for` become just minor details, IMO)
(more)
almost 2 years ago
Comment Post #286349 Well, there is: https://software.codidact.com/posts/286304/286334#answer-286334 :-) If I understood correctly, the piece of code that uses `createTreeWalker` does that.
(more)
almost 2 years ago
Comment Post #286349 As explained [here](https://software.codidact.com/posts/286333), there are different types of nodes. And this code traverses through all document's nodes, but the replace only makes sense in text nodes ([here](https://software.codidact.com/posts/286304/286334#answer-286334) there's an explanation of ...
(more)
almost 2 years ago
Comment Post #286335 The purpose of `for..of` is not only to provide a different syntax. With this statement, you can loop through any iterable object (you can even create your own). Some objects, for instance, don't have the `length` property or don't support the `[ ]` syntax to get a specific element, so using `for..of...
(more)
almost 2 years ago
Comment Post #286335 There's no `=` after `const` in *any* variable declaration. You either declare it as `const variableName;` or `const variableName = someValue;` (the `=` is after the variable name, not after `const` - yes, that was pedantic from my part, sorry) Anyway, this `for..of` code is equivalent to: ```j...
(more)
almost 2 years ago
Comment Post #286317 @#56529 The "on the fly variable declaration" is simply the syntax of the [`for..of` statement](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...of): `for (const child of e.childNodes)` loops through `e.childNodes`, and in each iteration, the next element is set to t...
(more)
almost 2 years ago
Comment Post #286307 @#56529 "*it's harmful to use on an entire document*" - Actually, it's potentially harmful to use in **any** element, if its `innerHTML` contains tags/attributes with the character you're replacing. Let's say you use it in a `div`, and that `div` contains a `textarea` element. Replacing the letter "x...
(more)
almost 2 years ago
Comment Post #286307 As already pointed by @#53305, your code might completely destroy the HTML - in your case, it probably "worked" by luck/coincidence, because you're being more restrict: you select only one specific element (the one that has the `new_pages` class), and I guess there were no tags or attributes with the...
(more)
almost 2 years ago
Comment Post #286258 @#56529s My bad, `querySelector` returns the first element it finds, while `getElementsByTagName` returns a list of elements (and you should get only the first one). I edited the answer with the correct code
(more)
about 2 years ago
Comment Post #286151 @#53853 How are you compiling those files? I could reproduce the error, but it happens only if I compile `MainClass.java` before `QueueObject.java` (just `javac MainClass.java` before compiling `QueueObject`). If I compile both (such as `javac *.java` or even `javac MainClass.java QueueObject.java...
(more)
about 2 years ago
Comment Post #286047 May I suggest you to change the exception type in your example? `ArrayIndexOutOfBoundsException` is an unchecked exception, therefore the behaviour you described doesn't happen (it only does when it's a checked exception).
(more)
about 2 years ago
Comment Post #286031 Let's see if I understood: `B::add` is called multiple times, and you want to check if all calls receives a different argument? Let's say, if it calls `b.add(1)` and `b.add(2)`, the test passes, but if it calls `b.add(1)` twice, it fails. Is `BMock` required for that? Or only checking for a repeat...
(more)
about 2 years ago
Comment Post #286031 Well, inside `BMock`'s constructor, just add `super(whateverArgsBConstructorExpects)` and that's it :-) Or maybe you could use PowerMockito: see the "Replacing" section in [this link](https://blog.jayway.com/2013/03/05/beyond-mocking-with-powermock/)
(more)
about 2 years ago
Comment Post #286031 In that case, you could do `BMock extends B` and then set `a.b = new BMock()`
(more)
about 2 years ago
Comment Post #286031 I'm trying to test your code, but I think there are some details missing. I understood that `A::add` calls `B::add` (as shown in the code), which in turn will call `BMock::add` (`B` code wasn't provided, so I'm guessing). Which one do you want to test? "_If it gets called twice with the same item_...
(more)
about 2 years ago
Comment Post #286017 @#8196 Well, I think you don't want to change the code for the wrong reasons: "*less lines*" isn't necessarily "better", you should try to write good, clean, readable and correct code, regardless of how many lines you need to achieve that. Sometimes less is better, of course, but sometimes the attemp...
(more)
about 2 years ago
Comment Post #286017 `Foo` could have a constructor that receives `x`, so it becomes `bar.fun(new Foo(42))`, or static factory methods, such as `Foo.withX(42)` that returns a `Foo` instance with `x` value set.
(more)
about 2 years ago
Comment Post #285968 Perhaps that's another question, but in `void* p = malloc(n); scanf("%d", p);`, what happens if `n` is less than `sizeof(int)`? I guess it's UB, right?
(more)
about 2 years ago