Most Popular
1500 questions
1634
votes
28 answers
How to add a class to a given element?
I have an element that already has a class:
Now, I want to create a JavaScript function that will add a class to the div (not replace, but add).
How can I do that?
Blankman
- 259,732
- 324
- 769
- 1,199
1633
votes
16 answers
How do I remove a directory from a Git repository?
How can I delete a single directory containing files from a Git repository?
Sahat Yalkabov
- 32,654
- 43
- 110
- 175
1631
votes
12 answers
if/else in a list comprehension
I have a list xs containing a mixture of strings and None values. How can I use a list comprehension to call a function on each string, but convert the None values to '' (rather than passing them to the function)?
I tried:
[f(x) for x in xs if x is…
AP257
- 89,519
- 86
- 202
- 261
1628
votes
25 answers
1626
votes
90 answers
Does JavaScript have a method like "range()" to generate a range within the supplied bounds?
In PHP, you can do...
range(1, 3); // Array(1, 2, 3)
range("A", "C"); // Array("A", "B", "C")
That is, there is a function that lets you get a range of numbers or characters by passing the upper and lower bounds.
Is there anything built-in to…
alex
- 479,566
- 201
- 878
- 984
1626
votes
28 answers
Why do we need virtual functions in C++?
I'm learning C++ and I'm just getting into virtual functions.
From what I've read (in the book and online), virtual functions are functions in the base class that you can override in derived classes.
But earlier in the book, when learning about…
Jake Wilson
- 88,616
- 93
- 252
- 370
1625
votes
7 answers
application/x-www-form-urlencoded or multipart/form-data?
In HTTP there are two ways to POST data: application/x-www-form-urlencoded and multipart/form-data. I understand that most browsers are only able to upload files if multipart/form-data is used. Is there any additional guidance when to use one of the…
max
- 29,122
- 12
- 52
- 79
1624
votes
39 answers
What is the difference between null and undefined in JavaScript?
I want to know what the difference is between null and undefined in JavaScript.
user605334
1622
votes
31 answers
How do I get the filename without the extension from a path in Python?
How do I get the filename without the extension from a path in Python?
"/path/to/some/file.txt" → "file"
Joan Venge
- 315,713
- 212
- 479
- 689
1621
votes
37 answers
Creating a singleton in Python
This question is not for the discussion of whether or not the singleton design pattern is desirable, is an anti-pattern, or for any religious wars, but to discuss how this pattern is best implemented in Python in such a way that is most pythonic. In…
theheadofabroom
- 20,639
- 5
- 33
- 65
1620
votes
6 answers
Try-catch speeding up my code?
I wrote some code for testing the impact of try-catch, but seeing some surprising results.
static void Main(string[] args)
{
Thread.CurrentThread.Priority = ThreadPriority.Highest;
Process.GetCurrentProcess().PriorityClass =…
Eren Ersönmez
- 38,383
- 7
- 71
- 92
1620
votes
27 answers
SQL select only rows with max value on a column
I have this table for documents (simplified version here):
id
rev
content
1
1
...
2
1
...
1
2
...
1
3
...
How do I select one row per id and only the greatest rev?
With the above data, the result should contain two rows: [1, 3,…
Majid Fouladpour
- 29,356
- 21
- 76
- 127
1619
votes
7 answers
What is the Python 3 equivalent of "python -m SimpleHTTPServer"
What is the Python 3 equivalent of python -m SimpleHTTPServer?
ryanbraganza
- 16,863
- 3
- 17
- 24
1619
votes
31 answers
When should I use a struct rather than a class in C#?
When should you use struct and not class in C#? My conceptual model is that structs are used in times when the item is merely a collection of value types. A way to logically hold them all together into a cohesive whole.
I came across these rules…
Alex Baranosky
- 48,865
- 44
- 102
- 150
1619
votes
53 answers
How do you convert a byte array to a hexadecimal string, and vice versa?
How can you convert a byte array to a hexadecimal string and vice versa?
alextansc
- 4,626
- 6
- 29
- 45