Most Popular

1500 questions
2189
votes
45 answers

When should I use double or single quotes in JavaScript?

console.log("double"); vs. console.log('single'); I see more and more JavaScript libraries out there using single quotes when handling strings. What are the reasons to use one over the other? I thought they're pretty much interchangeable.
aemkei
  • 10,846
  • 6
  • 35
  • 29
2186
votes
31 answers

Get selected value in dropdown list using JavaScript

How do I get the selected value from a dropdown list using JavaScript? I tried the methods below, but they all return the selected index instead of the value: var e = document.getElementById("ddlViewBy"); function show(){ var as =…
Fire Hand
  • 23,886
  • 22
  • 49
  • 74
2185
votes
18 answers

How can I randomly select an item from a list?

Assume I have the following list: foo = ['a', 'b', 'c', 'd', 'e'] What is the simplest way to retrieve an item at random from this list?
Ray
  • 179,335
  • 97
  • 219
  • 202
2184
votes
15 answers

How to know if an object has an attribute in Python

How do I determine if an object has some attribute? For example: >>> a = SomeClass() >>> a.property Traceback (most recent call last): File "", line 1, in AttributeError: SomeClass instance has no attribute 'property' How can you…
Lucas Gabriel Sánchez
  • 37,640
  • 20
  • 54
  • 81
2182
votes
31 answers

What is 'Context' on Android?

In Android programming, what exactly is a Context class and what is it used for? I read about it on the developer site, but I am unable to understand it clearly.
Brigadier
  • 22,591
  • 4
  • 16
  • 9
2177
votes
29 answers

Get int value from enum in C#

I have a class called Questions (plural). In this class there is an enum called Question (singular) which looks like this. public enum Question { Role = 2, ProjectFunding = 3, TotalEmployee = 4, NumberOfServers = 5, …
jim
  • 25,128
  • 13
  • 49
  • 66
2176
votes
13 answers

How do I get the number of elements in a list in Python?

How do I get the number of elements in the list items? items = ["apple", "orange", "banana"] # There are 3 items.
y2k
  • 64,108
  • 26
  • 59
  • 85
2170
votes
14 answers

How do I set a variable to the output of a command in Bash?

I have a pretty simple script that is something like the following: #!/bin/bash VAR1="$1" MOREF='sudo run command against $VAR1 | grep name | cut -c7-' echo $MOREF When I run this script from the command line and pass it the arguments, I am not…
John
  • 22,123
  • 5
  • 23
  • 25
2170
votes
24 answers

What is a JavaBean exactly?

I understood, I think, that a "Bean" is a Java-class with properties and getters/setters. As much as I understand, it is the equivalent of a C struct. Is that true? Also, is there a real syntactic difference between a JavaBean and a regular class?…
2167
votes
39 answers

What is Inversion of Control?

Inversion of Control (IoC) can be quite confusing when it is first encountered. What is it? Which problem does it solve? When is it appropriate to use and when not?
Mike Minutillo
  • 52,255
  • 14
  • 45
  • 41
2165
votes
10 answers

Should I use Vagrant or Docker for creating an isolated environment?

I use Ubuntu for development and deployment and have a need for creating an isolated environment. I am considering either Vagrant or Docker for this purpose. What are the pros and cons, or how do these solutions compare?
murtaza52
  • 46,097
  • 28
  • 80
  • 119
2164
votes
13 answers

How to leave/exit/deactivate a Python virtualenv

I'm using virtualenv and the virtualenvwrapper. I can switch between virtualenv's just fine using the workon command. me@mymachine:~$ workon env1 (env1)me@mymachine:~$ workon env2 (env2)me@mymachine:~$ workon env1 (env1)me@mymachine:~$ How do I…
Apreche
  • 26,893
  • 8
  • 40
  • 50
2163
votes
23 answers

When should I use 'self' over '$this'?

In PHP 5, what is the difference between using self and $this? When is each appropriate?
Casey Watson
  • 49,426
  • 10
  • 31
  • 30
2158
votes
26 answers

Vertically align text next to an image?

Why won't vertical-align: middle work? And yet, vertical-align: top does work. span{ vertical-align: middle; }
small img Doesn't work.
sam
  • 22,083
  • 3
  • 19
  • 14
2153
votes
51 answers

How to copy files from host to Docker container?

I am trying to build a backup and restore solution for the Docker containers that we work with. I have Docker base image that I have created, ubuntu:base, and do not want have to rebuild it each time with a Docker file to add files to it. I want to…
user3001829
  • 21,914
  • 5
  • 16
  • 21