How do I sort a dictionary by value?
I have a dictionary of values read from two fields in a database: a string field and a numeric field. The string field is unique, so that is the key of the dictionary. I can sort on the keys, but how...
- Modified
- 20 Mar at 22:50
What is the difference between call and apply?
What is the difference between using `Function.prototype.apply()` and `Function.prototype.call()` to invoke a function? ``` var func = function() { alert('hello!'); }; ``` `func.apply();` vs `func....
- Modified
- 30 Oct at 12:56
Git refusing to merge unrelated histories on rebase
During `git rebase origin/development` the following error message is shown from Git: ``` fatal: refusing to merge unrelated histories Error redoing merge 1234deadbeef1234deadbeef ``` My Git versio...
Difference between "git add -A" and "git add ."
What is the difference between [git add [--all | -A]](https://git-scm.com/docs/git-add#Documentation/git-add.txt--A) and [git add .](https://git-scm.com/docs/git-add)?
How can I convert a string to boolean in JavaScript?
Can I convert a string representing a boolean value (e.g., 'true', 'false') into a intrinsic type in JavaScript? I have a hidden form in HTML that is updated based upon a user's selection within a li...
- Modified
- 29 Nov at 07:14
How to check if a string contains a substring in Bash
I have a string in Bash: ``` string="My string" ``` How can I test if it contains another string? ``` if [ $string ?? 'foo' ]; then echo "It's there!" fi ``` Where `??` is my unknown operator. Do ...
What is a serialVersionUID and why should I use it?
Eclipse issues warnings when a `serialVersionUID` is missing. > The serializable class Foo does not declare a static final serialVersionUID field of type long What is `serialVersionUID` and why ...
- Modified
- 17 Mar at 22:44
Case insensitive 'Contains(string)'
Is there a way to make the following return true? ``` string title = "ASTRINGTOTEST"; title.Contains("string"); ``` There doesn't seem to be an overload that allows me to set the case sensitivity. Cu...
- Modified
- 28 Jan at 12:44
How do I format a date in JavaScript?
How do I format a `Date` object to a string?
- Modified
- 17 Jul at 20:41
Git is not working after macOS Update (xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools)
I updated to the latest OS, and/or restarted my computer (this happens on every major update, but this time all I did was restart my computer on 2022-09-13) This morning I navigated to my work's codeb...
- Modified
- 13 Sep at 14:7
How can I change an element's class with JavaScript?
How can I change the class of an HTML element in response to an `onclick` or any other events using JavaScript?
- Modified
- 27 Oct at 05:52
How do I iterate over the words of a string?
How do I iterate over the words of a string composed of words separated by whitespace? Note that I'm not interested in C string functions or that kind of character manipulation/access. I prefer elegan...
Echo newline in Bash prints literal \n
How do I print a newline? This merely prints `\n`: ``` $ echo -e "Hello,\nWorld!" Hello,\nWorld! ```
Improve INSERT-per-second performance of SQLite
Optimizing SQLite is tricky. Bulk-insert performance of a C application can vary from 85 inserts per second to over 96,000 inserts per second! We are using SQLite as part of a desktop application. We...
- Modified
- 30 Jan at 15:19
"Least Astonishment" and the Mutable Default Argument
Anyone tinkering with Python long enough has been bitten (or torn to pieces) by the following issue: ``` def foo(a=[]): a.append(5) return a ``` Python novices would expect this function call...
- Modified
- 22 Jul at 11:6
How can I check if an object is an array?
I'm trying to write a function that either accepts a list of strings, or a single string. If it's a string, then I want to convert it to an array with just the one item so I can loop over it without f...
- Modified
- 14 Aug at 07:41
Why is "using namespace std;" considered bad practice?
I have heard `using namespace std;` is bad practice, and that I should use `std::cout` and `std::cin` directly instead. Why is this? Does it risk declaring variables that share the same name as someth...
- Modified
- 4 Jul at 21:5
How do I check if a list is empty?
For example, if passed the following: ``` a = [] ``` How do I check to see if `a` is empty?
event.preventDefault() vs. return false
When I want to prevent other event handlers from executing after a certain event is fired, I can use one of two techniques. I'll use jQuery in the examples, but this applies to plain-JS as well: ###...
- Modified
- 26 Aug at 10:9
How to iterate over a dictionary?
I've seen a few different ways to iterate over a dictionary in C#. Is there a standard way?
- Modified
- 8 May at 18:13
How do I disable the resizable property of a textarea?
I want to disable the resizable property of a `textarea`. Currently, I can resize a `textarea` by clicking on the bottom right corner of the `textarea` and dragging the mouse. How can I disable this?...
How can I merge properties of two JavaScript objects dynamically?
I need to be able to merge two (very simple) JavaScript objects at runtime. For example I'd like to: ``` var obj1 = { food: 'pizza', car: 'ford' } var obj2 = { animal: 'dog' } obj1.merge(obj2); //o...
- Modified
- 15 Dec at 17:58
How do you disable browser autocomplete on web form field / input tags?
How do you disable autocomplete in the major browsers for a specific input (or form field)?
- Modified
- 8 Apr at 23:1
What does cherry-picking a commit with Git mean?
What does [git cherry-pick <commit>](https://git-scm.com/docs/git-cherry-pick) do?
- Modified
- 11 Jul at 05:58
How do I test a class that has private methods, fields or inner classes?
How do I use JUnit to test a class that has internal private methods, fields or nested classes? It seems bad to change the access modifier for a method just to be able to run a test.
- Modified
- 19 Oct at 20:41