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 |
|---|---|---|---|---|
| Suggested Edit | Post #291744 |
Suggested edit: reworded title and body (more) |
helpful | over 2 years ago |
| Edit | Post #291746 | Initial revision | — | over 2 years ago |
| Answer | — |
A: Regex to get text outside brackets > Perhaps regex is not the best solution. Although it's possible, the expression will be so complicated that it won't be worth the trouble, IMO. But if you insist on using regex... I'm afraid we can't get all the groups in a single step. You said that the strings can have many pairs of brac... (more) |
— | over 2 years ago |
| Comment | Post #291704 |
Out of curiosity, do you know why they chose this character? I'm asking because many languages use `_` as a digit separator, so I'm wondering why they opted for a different one. (more) |
— | over 2 years ago |
| Edit | Post #291667 |
Post edited: added relevant tags |
— | over 2 years ago |
| Suggested Edit | Post #291667 |
Suggested edit: added relevant tags (more) |
helpful | over 2 years ago |
| Edit | Post #291672 |
Post edited: |
— | over 2 years ago |
| Edit | Post #291672 | Initial revision | — | over 2 years ago |
| Answer | — |
A: How is this code "dividing" by a string? As already said by another answer, you're not "dividing a string by another string". I'd just like to complement by providing more details about how this works. If you try to divide a string by another, such as `x = 'a' / 'b'`, you'll get an error. Therefore, in your code, `HOMEDIRECTORY` ... (more) |
— | over 2 years ago |
| Comment | Post #291667 |
Classes can overload operators. One example is the [`Path` class from `pathlib` module](https://docs.python.org/3/library/pathlib.html#operators), which overloads the division operator `/`, so `path / anotherpath_or_string` creates another `Path` object:
```python
from pathlib import Path
... (more) |
— | over 2 years ago |
| Edit | Post #291492 |
Post edited: |
— | over 2 years ago |
| Edit | Post #291492 | Initial revision | — | over 2 years ago |
| Answer | — |
A: In javascript is there really a good reason to never check for boolean true || false such as if(var){}else{}? As mentioned in another answer, when you have code such as `if (someVar)`, you're subject to truthiness. To be more precise, this code will run under the rules of Boolean coercion. In JavaScript, when you have `if (someVar)`, the variable `someVar` can be basically "anything" - even a boolean ... (more) |
— | over 2 years ago |
| Edit | Post #283669 |
Post edited: |
— | over 2 years ago |
| Edit | Post #291075 |
Post edited: |
— | over 2 years ago |
| Edit | Post #291075 |
Post edited: |
— | over 2 years ago |
| Edit | Post #291075 | Initial revision | — | over 2 years ago |
| Answer | — |
A: How to group a flat list of attributes into a nested lists? You could create a dictionary to map each attribute to its respective list of items. Then you get the dictionary values to create the final list. Something like this: ```python import re pattern = re.compile(r'attr\d+') just to simulate a "file" file = [ 'attr1 apple 1', 'attr1 banana... (more) |
— | over 2 years ago |
| Edit | Post #290969 |
Post edited: |
— | over 2 years ago |
| Edit | Post #290969 | Initial revision | — | over 2 years ago |
| Answer | — |
A: How to log first n lines of a stack trace in Java? It's not clear where this stack trace comes from (either from an exception or the current thread), but it doesn't matter, the way to do it is the same. Both `Exception`'s and `Thread`'s have the `getStackTrace()` method. For the current thread, you can use `Thread.currentThread().getStackTrace... (more) |
— | over 2 years ago |
| Edit | Post #290953 | Initial revision | — | over 2 years ago |
| Answer | — |
A: How to delete a remote branch in git? The other answer already provides the more straighforward solution (`push` with `--delete` option). But there's an older syntax that also works: ```bash git push : ``` Note that there's the `:` character before the branch name. Example: ```bash git push origin :my-branch ``` T... (more) |
— | over 2 years ago |
| 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... (more) |
— | over 2 years ago |
| Edit | Post #279716 |
Post edited: |
— | almost 3 years ago |
| Edit | Post #281552 |
Post edited: |
— | almost 3 years 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) |
— | almost 3 years 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... (more) |
— | almost 3 years 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 com... (more) |
— | almost 3 years ago |
| Edit | Post #289929 |
Post edited: |
— | almost 3 years ago |
| Edit | Post #289929 |
Post edited: |
— | almost 3 years 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) |
— | almost 3 years ago |
| Edit | Post #289929 |
Post edited: |
— | almost 3 years ago |
| Edit | Post #289929 | Initial revision | — | almost 3 years ago |
| Answer | — |
A: How to overwrite lines of STDOUT in Python? The solution proposed by the other answer works, but there's a corner case. If the last message is shorter than the previous one, you might not get what you want. Example: ```python print("this is some text", end="\r") print("abc") ``` Testing this in a Linux terminal, the output is: ... (more) |
— | almost 3 years 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 ... (more) |
— | almost 3 years 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) |
— | almost 3 years 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 tre... (more) |
— | about 3 years ago |
| Edit | Post #289491 |
Post edited: |
— | about 3 years ago |
| Edit | Post #289491 |
Post edited: |
— | about 3 years ago |
| Edit | Post #289491 | Initial revision | — | about 3 years ago |
| Answer | — |
A: Git: How to clone only a few recent commits? > How do I clone the repository with only part of the history? It depends on what part you want. It's possible to have shallow clones (which is exactly what you need, only a part of the commit history), and the documentation says there are the following options: > `--depth ` > Create a s... (more) |
— | about 3 years ago |
| Edit | Post #289295 |
Post edited: |
— | about 3 years 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) |
— | about 3 years ago |
| Edit | Post #289295 |
Post edited: |
— | about 3 years ago |
| Edit | Post #289295 |
Post edited: |
— | about 3 years ago |
| Edit | Post #289295 |
Post edited: |
— | about 3 years ago |
| Edit | Post #289295 | Initial revision | — | about 3 years ago |
| Answer | — |
A: Why is git merge from rather than to? I can't speak for the people who designed it, but I guess it was made this way because you can merge multiple branches all at once. Let's say I've created multiple branches: ```none C---D => b1 / / E---F => b2 | / A--B--G--H => master \ ... (more) |
— | about 3 years 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) |
— | about 3 years ago |
