Most Popular

1500 questions
1853
votes
15 answers

How to move an element into another element?

I would like to move one DIV element inside another. For example, I want to move this (including all children):
...
into this:
...
so that I have this:
Mark Richman
  • 27,901
  • 25
  • 90
  • 155
1852
votes
20 answers

How to efficiently count the number of keys/properties of an object in JavaScript

What's the fastest way to count the number of keys/properties of an object? Is it possible to do this without iterating over the object? I.e., without doing: var count = 0; for (k in myobj) if (myobj.hasOwnProperty(k)) ++count; (Firefox did…
mjs
  • 60,733
  • 27
  • 87
  • 118
1849
votes
74 answers

How to create an array containing 1...N

I'm looking for any alternatives to the below for creating a JavaScript array containing 1 through to N where N is only known at runtime. var foo = []; for (var i = 1; i <= N; i++) { foo.push(i); } To me it feels like there should be a way of…
Godders
  • 18,966
  • 4
  • 18
  • 18
1848
votes
21 answers

How to duplicate a whole line in Vim?

How do I duplicate a whole line in Vim in a similar way to Ctrl+D in IntelliJ IDEA/ Resharper or Ctrl+Alt+↑/↓ in Eclipse?
sumek
  • 25,263
  • 11
  • 54
  • 68
1848
votes
38 answers

How do I check if a string is a number (float)?

What is the best possible way to check if a string can be represented as a number in Python? The function I currently have right now is: def is_number(s): try: float(s) return True except ValueError: return…
Daniel Goldberg
  • 18,858
  • 4
  • 20
  • 29
1848
votes
48 answers

Scroll to the top of the page using JavaScript?

How do I scroll to the top of the page using JavaScript? The scrollbar instantly jumping to the top of the page is desirable too as I'm not looking to achieve smooth scrolling.
KingNestor
  • 62,514
  • 51
  • 117
  • 151
1847
votes
34 answers

Prefer composition over inheritance?

Why prefer composition over inheritance? What trade-offs are there for each approach? When should you choose inheritance over composition?
readonly
  • 326,166
  • 107
  • 202
  • 204
1845
votes
37 answers

How to split a string in Java

I have a string, "004-034556", that I want to split into two strings: string1="004"; string2="034556"; That means the first string will contain the characters before '-', and the second string will contain the characters after '-'. I also want to…
riyana
  • 20,665
  • 10
  • 33
  • 33
1844
votes
21 answers

Comments in Markdown

How do you write a comment in Markdown, i.e. text that is not rendered in the HTML output? I found nothing on the Markdown project.
Betamos
  • 22,905
  • 9
  • 22
  • 27
1842
votes
40 answers

How to align checkboxes and their labels consistently cross-browsers

This is one of the minor CSS problems that plague me constantly. How do folks around Stack Overflow vertically align checkboxes and their labels consistently cross-browser? Whenever I align them correctly in Safari (usually using vertical-align:…
One Crayon
  • 18,969
  • 10
  • 32
  • 39
1835
votes
46 answers

How to exclude a directory in find . command

I'm trying to run a find command for all JavaScript files, but how do I exclude a specific directory? Here is the find code we're using. for file in $(find . -name '*.js') do java -jar config/yuicompressor-2.4.2.jar --type js $file -o $file done
helion3
  • 30,779
  • 15
  • 51
  • 95
1825
votes
19 answers

How do I commit case-sensitive only filename changes in Git?

I have changed a few files name by de-capitalize the first letter, as in Name.jpg to name.jpg. Git does not recognize this changes and I had to delete the files and upload them again. Is there a way that Git can be case-sensitive when checking for…
Gil Shulman
  • 18,269
  • 3
  • 11
  • 4
1825
votes
16 answers

Looping through the content of a file in Bash

How do I iterate through each line of a text file with Bash? With this script: echo "Start!" for p in (peptides.txt) do echo "${p}" done I get this output on the screen: Start! ./runPep.sh: line 3: syntax error near unexpected token…
Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
1822
votes
23 answers

Image Processing: Algorithm Improvement for 'Coca-Cola Can' Recognition

One of the most interesting projects I've worked on in the past couple of years was a project about image processing. The goal was to develop a system to be able to recognize Coca-Cola 'cans' (note that I'm stressing the word 'cans', you'll see why…
Charles Menguy
  • 39,774
  • 17
  • 95
  • 115
1820
votes
10 answers

Why does ++[[]][+[]]+[+[]] return the string "10"?

This is valid and returns the string "10" in JavaScript (more examples here): console.log(++[[]][+[]]+[+[]]) Why? What is happening here?
JohnJohnGa
  • 15,076
  • 17
  • 60
  • 86