Most Popular

1500 questions
2105
votes
36 answers

What are drawbacks or disadvantages of singleton pattern?

The singleton pattern is a fully paid up member of the GoF's patterns book, but it lately seems rather orphaned by the developer world. I still use quite a lot of singletons, especially for factory classes, and while you have to be a bit careful…
Ewan Makepeace
  • 5,318
  • 8
  • 30
  • 31
2103
votes
31 answers

How to convert a string to an integer in JavaScript?

How do I convert a string to an integer in JavaScript?
None
2102
votes
25 answers

How do I print curly-brace characters in a string while using .format?

Non-working example: print(" \{ Hello \} {0} ".format(42)) Desired output: {Hello} 42
Schitti
  • 22,219
  • 8
  • 22
  • 21
2091
votes
8 answers

What do 'real', 'user' and 'sys' mean in the output of time(1)?

$ time foo real 0m0.003s user 0m0.000s sys 0m0.004s $ What do real, user and sys mean in the output of time? Which one is meaningful when benchmarking my app?
Iraimbilanja
2088
votes
23 answers

Is there a way to run Python on Android?

We are working on an S60 version and this platform has a nice Python API.. However, there is nothing official about Python on Android, but since Jython exists, is there a way to let the snake and the robot work together??
e-satis
  • 551,433
  • 107
  • 289
  • 326
2083
votes
10 answers

Why is reading lines from stdin much slower in C++ than Python?

I wanted to compare reading lines of string input from stdin using Python and C++ and was shocked to see my C++ code run an order of magnitude slower than the equivalent Python code. Since my C++ is rusty and I'm not yet an expert Pythonista, please…
JJC
  • 8,561
  • 8
  • 41
  • 51
2083
votes
17 answers

Why can templates only be implemented in the header file?

Quote from The C++ standard library: a tutorial and handbook: The only portable way of using templates at the moment is to implement them in header files by using inline functions. Why is this? (Clarification: header files are not the only…
MainID
  • 27,272
  • 19
  • 55
  • 70
2082
votes
46 answers

How do I create an Excel (.XLS and .XLSX) file in C# without installing Microsoft Office?

How can I create an Excel spreadsheet with C# without requiring Excel to be installed on the machine that's running the code?
mistrmark
  • 4,349
  • 6
  • 21
  • 15
2073
votes
12 answers

How to use java.net.URLConnection to fire and handle HTTP requests

Use of java.net.URLConnection is asked about pretty often here, and the Oracle tutorial is too concise about it. That tutorial basically only shows how to fire a GET request and read the response. It doesn't explain anywhere how to use it to, among…
BalusC
  • 1,040,783
  • 362
  • 3,548
  • 3,513
2061
votes
16 answers

Download a specific tag with Git

I'm trying to figure out how I can download a particular tag of a Git repository - it's one version behind the current version. I saw there was a tag for the previous version on the git web page, with object name of something long hex number. But…
Jack BeNimble
  • 34,491
  • 37
  • 120
  • 196
2059
votes
31 answers

How to check if a column exists in a SQL Server table

I need to add a specific column if it does not exist. I have something like the following, but it always returns false: IF EXISTS(SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'myTableName' AND…
Maciej
  • 20,968
  • 3
  • 19
  • 23
2057
votes
14 answers

What is a smart pointer and when should I use one?

What is a smart pointer and when should I use one?
Alex Reynolds
  • 94,180
  • 52
  • 233
  • 338
2054
votes
29 answers

Retrieve the position (X,Y) of an HTML element

I want to know how to get the X and Y position of HTML elements such as img and div in JavaScript.
monaung
2052
votes
39 answers

What's the difference between a method and a function?

Can someone provide a simple explanation of methods vs. functions in OOP context?
willc2
  • 37,901
  • 25
  • 86
  • 99
2051
votes
19 answers

How can I profile C++ code running on Linux?

I have a C++ application, running on Linux, which I'm in the process of optimizing. How can I pinpoint which areas of my code are running slowly?
Gabriel Isenberg
  • 25,069
  • 4
  • 35
  • 57