All Questions

Filter by
Sorted by
Tagged with
3313 votes
20 answers
2.4m views

How to iterate over a dictionary?

I've seen a few different ways to iterate over a dictionary in C#. Is there a standard way?
Jake Stewart's user avatar
  • 33.3k
3313 votes
42 answers
2.1m views

How do I pass a variable by reference?

I wrote this class for testing: class PassByReference: def __init__(self): self.variable = 'Original' self.change(self.variable) print(self.variable) def change(self, ...
David Sykes's user avatar
  • 49.4k
3296 votes
22 answers
1.8m views

How do I disable the resizable property of a textarea?

I want to disable the resizable property of a textarea. Currently, I can resize a textarea by clicking on the bottom right corner of the textarea and dragging the mouse. How can I disable this?
user549757's user avatar
  • 33.6k
3282 votes
45 answers
3.8m views

How to add a column with a default value to an existing table in SQL Server?

How can I add a column with a default value to an existing table in SQL Server 2000 / SQL Server 2005?
Mathias's user avatar
  • 33.9k
3252 votes
14 answers
939k views

event.preventDefault() vs. return false

When I want to prevent other event handlers from executing after a certain event is fired, I can use one of two techniques. I'll use jQuery in the examples, but this applies to plain-JS as well: 1. ...
RaYell's user avatar
  • 70.1k
3250 votes
11 answers
3.1m views

Manually raising (throwing) an exception in Python

How do I raise an exception in Python so that it can later be caught via an except block?
TIMEX's user avatar
  • 268k
3248 votes
45 answers
484k views

JavaScript closure inside loops – simple practical example

var funcs = []; // let's create 3 functions for (var i = 0; i < 3; i++) { // and store them in funcs funcs[i] = function() { // each should log its value. console.log("My value:", i); ...
nickf's user avatar
  • 543k
3242 votes
22 answers
1.6m views

How do I modify a specific commit?

I have the following commit history: HEAD HEAD~ HEAD~2 HEAD~3 git commit --amend modifies the current HEAD commit. But how do I modify HEAD~3?
Sam Liao's user avatar
  • 45.2k
3238 votes
31 answers
4.5m views

How do I concatenate two lists in Python?

How do I concatenate two lists in Python? Example: listone = [1, 2, 3] listtwo = [4, 5, 6] Expected outcome: >>> joinedlist [1, 2, 3, 4, 5, 6]
y2k's user avatar
  • 65.8k
3236 votes
13 answers
3.8m views

How do I make a time delay? [duplicate]

How do I put a time delay in a Python script?
user46646's user avatar
  • 157k
3234 votes
7 answers
2.8m views

Understanding Python super() with __init__() methods [duplicate]

Why is super() used? Is there a difference between using Base.__init__ and super().__init__? class Base(object): def __init__(self): print "Base created" class ChildA(...
Mizipzor's user avatar
  • 51.9k
3232 votes
105 answers
1.4m views

How do you disable browser autocomplete on web form field / input tags?

How do you disable autocomplete in the major browsers for a specific input (or form field)?
Brett Veenstra's user avatar
3228 votes
49 answers
1.5m views

Detecting an undefined object property

How do I check if an object property in JavaScript is undefined?
Matt Sheppard's user avatar
3228 votes
59 answers
1.3m views

How do I test a class that has private methods, fields or inner classes?

How do I use JUnit to test a class that has internal private methods, fields or nested classes? It seems bad to change the access modifier for a method just to be able to run a test.
3224 votes
16 answers
6.1m views

How do I change the size of figures drawn with Matplotlib?

How do I change the size of figure drawn with Matplotlib?
tatwright's user avatar
  • 38.2k
3222 votes
27 answers
5.0m views

How do I check if a list is empty?

For example, if passed the following: a = [] How do I check to see if a is empty?
Ray's user avatar
  • 190k
3218 votes
34 answers
2.3m views

Using async/await with a forEach loop

Are there any issues with using async/await in a forEach loop? I'm trying to loop through an array of files and await on the contents of each file. import fs from 'fs-promise' async function ...
Saad's user avatar
  • 52.8k
3217 votes
66 answers
2.5m views

How do I print colored text to the terminal?

How do I output colored text to the terminal in Python?
aboSamoor's user avatar
  • 32.4k
3213 votes
30 answers
1.2m views

How do I find and restore a deleted file in a Git repository?

Say I'm in a Git repository. I delete a file and commit that change. I continue working and make some more commits. Then, I discover that I need to restore that file after deleting it. I know I can ...
avdgaag's user avatar
  • 41.8k
3209 votes
36 answers
2.8m views

ssh "permissions are too open"

I get the following error from ssh: Permissions 0777 for '/Users/username/.ssh/id_rsa' are too open. It is recommended that your private key files are NOT accessible by others. This private key will ...
Yannick Schall's user avatar
3208 votes
14 answers
2.6m views

I ran into a merge conflict. How do I abort the merge?

I used git pull and had a merge conflict: unmerged: some_file.txt You are in the middle of a conflicted merge. How do I abandon my changes to the file and keep only the pulled changes?
Gwyn Morfey's user avatar
  • 33.3k
3196 votes
12 answers
2.4m views

How can I see the differences between two branches?

How can I see the differences between branches branch_1 and branch_2?
isuruanu's user avatar
  • 32k
3182 votes
40 answers
1.1m views

Should I use the datetime or timestamp data type in MySQL?

Would you recommend using a datetime or a timestamp field, and why (using MySQL)? I'm working with PHP on the server side.
Gad's user avatar
  • 42.1k
3182 votes
20 answers
293k views

Is it possible to apply CSS to half of a character?

What I am looking for: A way to style one HALF of a character. (In this case, half the letter being transparent) What I have currently searched for and tried (With no luck): Methods for styling half ...
SimplyAzuma's user avatar
  • 25.5k
3180 votes
19 answers
1.8m views

What does " 2>&1 " mean?

To combine stderr and stdout into the stdout stream, we append this to a command: 2>&1 e.g. to see the first few errors from compiling g++ main.cpp: g++ main.cpp 2>&1 | head What does ...
Tristan Havelick's user avatar
3172 votes
54 answers
831k views

How to stop EditText from gaining focus when an activity starts in Android?

I have an Activity in Android, with two elements: EditText ListView When my Activity starts, the EditText immediately has the input focus (flashing cursor). I don't want any control to have input ...
Mark's user avatar
  • 39.8k
3168 votes
22 answers
664k views

How do I make function decorators and chain them together?

How do I make two decorators in Python that would do the following? @make_bold @make_italic def say(): return "Hello" Calling say() should return: "<b><i>Hello</i>&...
Imran's user avatar
  • 89.7k
3151 votes
27 answers
1.7m views

How to set, clear, and toggle a single bit

How can I set, clear, and toggle a bit?
JeffV's user avatar
  • 54k
3151 votes
17 answers
867k views

Is there an "exists" function for jQuery?

How can I check the existence of an element in jQuery? The current code that I have is this: if ($(selector).length > 0) { // Do something } Is there a more elegant way to approach this? ...
Jake McGraw's user avatar
3148 votes
34 answers
1.5m views

How can I upload files asynchronously with jQuery?

I would like to upload a file asynchronously with jQuery. $(document).ready(function () { $("#uploadbutton").click(function () { var filename = $("#file").val(); $.ajax({...
Sergio del Amo's user avatar
3146 votes
31 answers
4.5m views

`git fetch` a remote branch

The remote repository contains various branches such as origin/daves_branch: $ git branch -r origin/HEAD -> origin/master origin/daves_branch origin/master How do I switch to daves_branch in the ...
David's user avatar
  • 35.7k
3146 votes
39 answers
1.2m views

How can I check if a program exists from a Bash script?

How would I validate that a program exists, in a way that will either return an error and exit, or continue with the script? It seems like it should be easy, but it's been stumping me.
gregh's user avatar
  • 36.9k
3142 votes
24 answers
2.4m views

HTTP GET with request body

I'm developing a new RESTful webservice for our application. When doing a GET on certain entities, clients can request the contents of the entity. If they want to add some parameters (for example ...
Evert's user avatar
  • 97.8k
3135 votes
12 answers
786k views

When should static_cast, dynamic_cast, const_cast, and reinterpret_cast be used?

What are the proper uses of: static_cast dynamic_cast const_cast reinterpret_cast (type)value (C-style cast) type(value) (function-style cast) How does one decide which to use in which specific ...
e.James's user avatar
  • 118k
3127 votes
70 answers
1.7m views

How do I split a list into equally-sized chunks?

How do I split a list of arbitrary length into equal sized chunks? See also: How to iterate over a list in chunks. To chunk strings, see Split string every nth character?.
jespern's user avatar
  • 33k
3118 votes
30 answers
1.7m views

How can I change the commit author for a single commit?

I want to change the author of one specific commit in the history. It's not the latest commit. Related: How do I change the author and committer name/email for multiple commits?
MicTech's user avatar
  • 43.9k
3111 votes
20 answers
3.3m views

What is the difference between Python's list methods append and extend?

What's the difference between the list methods append() and extend()?
Claudiu's user avatar
  • 227k
3111 votes
30 answers
916k views

What is the difference between #include <filename> and #include "filename"?

What is the difference between using angle brackets and quotes in an include directive? #include <filename> #include "filename"
quest49's user avatar
  • 50.6k
3104 votes
47 answers
3.0m views

Is there a standard function to check for null, undefined, or blank variables in JavaScript? [duplicate]

Is there a universal JavaScript function that checks that a variable has a value and ensures that it's not undefined or null? I've got this code, but I'm not sure if it covers all cases: function ...
Alex's user avatar
  • 35.5k
3101 votes
21 answers
3.1m views

How do I clone a Git repository into a specific folder?

The command git clone [email protected]:whatever creates a directory named whatever containing a Git repository: ./ whatever/ .git I want the contents of the Git repository cloned into my ...
David Smith's user avatar
  • 39.3k
3095 votes
54 answers
1.3m views

Is there a unique Android device ID?

Do Android devices have a unique ID, and if so, what is a simple way to access it using Java?
Tyler's user avatar
  • 31.5k
3093 votes
17 answers
1.1m views

What is the difference between the 'COPY' and 'ADD' commands in a Dockerfile?

What is the difference between the COPY and ADD commands in a Dockerfile, and when would I use one over the other? COPY <src> <dest> The COPY instruction will copy new files from <...
Steve's user avatar
  • 55.1k
3093 votes
16 answers
1.2m views

What is the --save option for npm install?

I saw some tutorial where the command was: npm install --save What does the --save option mean?
Dmitri's user avatar
  • 35.8k
3091 votes
43 answers
1.2m views

How do I change the author and committer name/email for multiple commits?

How do I change the author for a range of commits?
Flávio Amieiro's user avatar
3083 votes
41 answers
1.8m views

How do I pass command line arguments to a Node.js program and receive them?

I have a web server written in Node.js and I would like to launch with a specific folder. I'm not sure how to access arguments in JavaScript. I'm running node like this: $ node server.js folder here ...
milkplus's user avatar
  • 33.9k
3080 votes
24 answers
1.5m views

How to store objects in HTML5 localStorage/sessionStorage

I'd like to store a JavaScript object in HTML5 localStorage, but my object is apparently being converted to a string. I can store and retrieve primitive JavaScript types and arrays using localStorage, ...
Kristopher Johnson's user avatar
3073 votes
27 answers
3.8m views

Deleting an element from an array in PHP

Is there an easy way to delete an element from an array using PHP, such that foreach ($array) no longer includes that element? I thought that setting it to null would do it, but apparently it does ...
Ben's user avatar
  • 68.1k
3068 votes
39 answers
2.5m views

How can I know which radio button is selected via jQuery?

I have two radio buttons and want to post the value of the selected one. How can I get the value with jQuery? I can get all of them like this: $("form :radio") How do I know which one is selected?
juan's user avatar
  • 81.3k
3061 votes
16 answers
3.7m views

How can I check for "undefined" in JavaScript? [duplicate]

What is the most appropriate way to test if a variable is undefined in JavaScript? I've seen several possible ways: if (window.myVariable) Or if (typeof(myVariable) != "undefined") Or if (...
makerofthings7's user avatar
3044 votes
21 answers
2.1m views

How do I modify the URL without reloading the page?

Is there a way I can modify the URL of the current page without reloading the page? I would like to access the portion before the # hash if possible. I only need to change the portion after the domain,...
Robin Rodricks's user avatar

15 30 50 per page
1
3 4
5
6 7
483861