Most Popular

1500 questions
3467
votes
21 answers

How do I list all files of a directory?

How can I list all files of a directory in Python and add them to a list?
duhhunjonn
  • 44,855
  • 11
  • 28
  • 15
3459
votes
104 answers

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 list. This form contains some fields which represent…
Kevin
  • 7,856
  • 11
  • 35
  • 40
3456
votes
30 answers

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 I use echo and grep? if echo "$string" | grep 'foo'; then echo…
davidsheldon
  • 38,365
  • 4
  • 27
  • 28
3456
votes
24 answers

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? const func = function() { alert("Hello world!"); }; func.apply() vs. func.call() Are there performance differences between the…
John Duff
  • 38,090
  • 5
  • 35
  • 45
3434
votes
69 answers

How do I format a date in JavaScript?

How do I format a Javascript Date object as a string? (Preferably in the format: 10-Aug-2010)
leora
  • 188,729
  • 360
  • 878
  • 1,366
3415
votes
12 answers

Difference between "git add -A" and "git add ."

What is the difference between git add [--all | -A] and git add .?
cmcginty
  • 113,384
  • 42
  • 163
  • 163
3414
votes
34 answers

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 can I sort based on the values? Note: I have read…
Gern Blanston
  • 42,482
  • 19
  • 50
  • 64
3414
votes
38 answers

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 codebase in the command line on my MacBook Pro, typed…
dustbuster
  • 79,958
  • 7
  • 21
  • 41
3410
votes
30 answers

AngularJS: Service vs provider vs factory

What are the differences between a Service, Provider and Factory in AngularJS?
3405
votes
22 answers

Echo newline in Bash prints literal \n

How do I print a newline? This merely prints \n: $ echo -e "Hello,\nWorld!" Hello,\nWorld!
Sergey
  • 47,222
  • 25
  • 87
  • 129
3397
votes
43 answers

Creating multiline strings in JavaScript

I have the following code in Ruby. I want to convert this code into JavaScript. What is the equivalent code in JS? text = <<"HERE" This Is A Multiline String HERE
Newy
  • 38,977
  • 9
  • 43
  • 59
3395
votes
25 answers

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 is it important? Please show an example where missing…
ashokgelal
  • 80,002
  • 26
  • 71
  • 84
3394
votes
17 answers

How do I select rows from a DataFrame based on column values?

How can I select rows from a DataFrame based on values in some column in Pandas? In SQL, I would use: SELECT * FROM table WHERE column_name = some_value
szli
  • 36,893
  • 11
  • 32
  • 40
3384
votes
31 answers

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. Currently I UPPERCASE them both, but that's just silly (by…
Boris Callens
  • 90,659
  • 85
  • 207
  • 305
3371
votes
34 answers

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?
Nathan Smith
  • 36,807
  • 6
  • 28
  • 25