Most Popular

1500 questions
1338
votes
4 answers

\d less efficient than [0-9]

I made a comment yesterday on an answer where someone had used [0123456789] in a regex rather than [0-9] or \d. I said it was probably more efficient to use a range or digit specifier than a character set. I decided to test that out today and found…
weston
  • 54,145
  • 21
  • 145
  • 203
1338
votes
14 answers

How do I escape a single quote in SQL Server?

I am trying to insert some text data into a table in SQL Server 9. The text includes a single quote '. How do I escape that? I tried using two single quotes, but it threw me some errors. eg. insert into my_table values('hi, my name''s tim.');
tim_wonil
  • 14,970
  • 6
  • 29
  • 42
1337
votes
20 answers

Difference Between Select and SelectMany

I've been searching the difference between Select and SelectMany but I haven't been able to find a suitable answer. I need to learn the difference when using LINQ To SQL but all I've found are standard array examples. Can someone provide a LINQ To…
Tarik
  • 79,711
  • 83
  • 236
  • 349
1337
votes
28 answers

How to determine if a JavaScript array contains an object with an attribute that equals a given value

I have an array like vendors = [{ Name: 'Magenic', ID: 'ABC' }, { Name: 'Microsoft', ID: 'DEF' } // and so on... ]; How do I check this array to see if "Magenic" exists? I don't want to loop, unless I have to. I'm working with…
David Lozzi
  • 14,697
  • 9
  • 28
  • 44
1337
votes
34 answers

How to overcome "datetime.datetime not JSON serializable"?

I have a basic dict as follows: sample = {} sample['title'] = "String" sample['somedate'] = somedatetimehere When I try to do jsonify(sample) I get: TypeError: datetime.datetime(2012, 8, 8, 21, 46, 24, 862000) is not JSON serializable What can I…
Rolando
  • 58,640
  • 98
  • 266
  • 407
1336
votes
27 answers

How can I read a text file into a string variable and strip newlines?

I have a text file that looks like: ABC DEF How can I read the file into a single-line string without newlines, in this case creating a string 'ABCDEF'? For reading the file into a list of lines, but removing the trailing newline character from…
klijo
  • 15,761
  • 8
  • 34
  • 49
1336
votes
19 answers

How to perform an integer division, and separately get the remainder, in JavaScript

In JavaScript, how do I get: The whole number of times a given integer goes into another? The remainder?
Yarin
  • 173,523
  • 149
  • 402
  • 512
1336
votes
43 answers

How to make a class JSON serializable

How to make a Python class serializable? class FileItem: def __init__(self, fname): self.fname = fname Attempt to serialize to JSON: >>> import json >>> x = FileItem('/foo/bar') >>> json.dumps(x) TypeError: Object of type 'FileItem' is…
Sergey
  • 19,487
  • 13
  • 44
  • 68
1333
votes
11 answers

How do you use bcrypt for hashing passwords in PHP?

Every now and then I hear the advice "Use bcrypt for storing passwords in PHP, bcrypt rules". But what is bcrypt? PHP doesn't offer any such functions, Wikipedia babbles about a file-encryption utility and Web searches just reveal a few…
Vilx-
  • 104,512
  • 87
  • 279
  • 422
1333
votes
15 answers

How does the @property decorator work in Python?

I would like to understand how the built-in function property works. What confuses me is that property can also be used as a decorator, but it only takes arguments when used as a built-in function and not when used as a decorator. This example is…
ashim
  • 24,380
  • 29
  • 72
  • 96
1331
votes
24 answers

Get a list from Pandas DataFrame column headers

I want to get a list of the column headers from a Pandas DataFrame. The DataFrame will come from user input, so I won't know how many columns there will be or what they will be called. For example, if I'm given a DataFrame like this: y gdp …
natsuki_2002
  • 24,239
  • 21
  • 46
  • 50
1330
votes
11 answers

Which characters are valid in CSS class names/selectors?

What characters/symbols are allowed within the CSS class selectors? I know that the following characters are invalid, but what characters are valid? ~ ! @ $ % ^ & * ( ) + = , . / ' ; : " ? > < [ ] \ { } | ` #
Darryl Hein
  • 142,451
  • 95
  • 218
  • 261
1327
votes
37 answers

How do I reverse a list or loop over it backwards?

How do I iterate over a list in reverse in Python? See also: How can I get a reversed copy of a list (avoid a separate statement when chaining a method after .reverse)?
Leo.peis
  • 13,673
  • 6
  • 22
  • 20
1326
votes
39 answers

Remove all child elements of a DOM node in JavaScript

How would I go about removing all of the child elements of a DOM node in JavaScript? Say I have the following (ugly) HTML:

hello

world

And I grab the node I want like so: var myNode =…
DigitalZebra
  • 39,494
  • 39
  • 114
  • 146
1326
votes
24 answers

How can I customize the tab-to-space conversion factor?

How do I customize the tab-to-space conversion factor when using Visual Studio Code? For instance, right now in HTML it appears to produce two spaces per press of TAB, but in TypeScript it produces 4.
J. Abrahamson
  • 72,246
  • 9
  • 135
  • 180