Most Popular

1500 questions
1278
votes
7 answers

How to exit git log or git diff

I'm trying to learn Git with the help of Git Immersion. There's one thing that frustrates me whenever I use git log or git diff: I can't figure out what to do next when I encounter this (END) word. I can't type any commands, and I end up closing…
Wern Ancheta
  • 22,397
  • 38
  • 100
  • 139
1278
votes
44 answers

How to get line count of a large file cheaply in Python?

How do I get a line count of a large file in the most memory- and time-efficient manner? def file_len(filename): with open(filename) as f: for i, _ in enumerate(f): pass return i + 1
SilentGhost
  • 307,395
  • 66
  • 306
  • 293
1278
votes
32 answers

Pipe to/from the clipboard in a Bash script

Is it possible to pipe to/from the clipboard in Bash? Whether it is piping to/from a device handle or using an auxiliary application, I can't find anything. For example, if /dev/clip was a device linking to the clipboard we could do: cat /dev/clip …
moinudin
  • 134,091
  • 45
  • 190
  • 216
1278
votes
12 answers

What do Clustered and Non-Clustered index actually mean?

I have a limited exposure to DB and have only used DB as an application programmer. I want to know about Clustered and Non clustered indexes. I googled and what I found was : A clustered index is a special type of index that reorders the way …
P.K
  • 18,587
  • 11
  • 45
  • 51
1277
votes
21 answers

How do I check if a string contains another string in Objective-C?

How can I check if a string (NSString) contains another smaller string? I was hoping for something like: NSString *string = @"hello bla bla"; NSLog(@"%d",[string containsSubstring:@"hello"]); But the closest I could find was: if ([string…
Jonathan.
  • 53,997
  • 54
  • 186
  • 290
1276
votes
16 answers

How do I provide a username and password when running "git clone git@remote.git"?

I know how to include a username and password in a https Git URL like this: git clone https://username:password@host But I'd like to know how to provide a username and password to an SSH remote like this: git clone git@host.git I've tried like…
coordinate
  • 15,224
  • 6
  • 24
  • 24
1275
votes
8 answers

How to tag an older commit in Git?

We are new to git, and I want to set a tag at the beginning of our repository. Our production code is the same as the beginning repository, but we've made commits since then. A tag at the beginning would allow us to "roll back" production to a…
hogsolo
  • 13,565
  • 6
  • 24
  • 25
1275
votes
26 answers

How do I connect to a MySQL Database in Python?

How do I connect to a MySQL database using a python program?
Marc Lincoln
1275
votes
49 answers

Easy interview question got harder: given numbers 1..100, find the missing number(s) given exactly k are missing

I had an interesting job interview experience a while back. The question started really easy: Q1: We have a bag containing numbers 1, 2, 3, …, 100. Each number appears exactly once, so there are 100 numbers. Now one number is randomly picked out of…
polygenelubricants
  • 376,812
  • 128
  • 561
  • 623
1275
votes
46 answers

Detecting a mobile browser

I'm looking for a function that returns a boolean value if the user is using a mobile browser or not. I know that I can use navigator.userAgent and write that function by using regex, but user-agents are too various for different platforms. I doubt…
ave
  • 18,083
  • 9
  • 30
  • 39
1274
votes
33 answers

Using Node.js as a simple web server

I want to run a very simple HTTP server. Every GET request to example.com should get index.html served to it but as a regular HTML page (i.e., same experience as when you read normal web pages). Using the code below, I can read the content of…
idophir
  • 14,451
  • 5
  • 24
  • 21
1274
votes
10 answers

What is a correct MIME type for .docx, .pptx, etc.?

For older *.doc documents, this was enough: header("Content-Type: application/msword"); What MIME type should I use for new .docx documents? Also, for pptx and xlsx documents?
Richard Knop
  • 81,041
  • 149
  • 392
  • 552
1274
votes
42 answers

How can I disable the UITableView selection?

When you tap a row in a UITableView, the row is highlighted and selected. Is it possible to disable this so tapping a row does nothing?
davidmytton
  • 38,604
  • 37
  • 87
  • 93
1273
votes
10 answers

Group by in LINQ

Let's suppose if we have a class like: class Person { internal int PersonID; internal string car; } I have a list of this class: List persons; And this list can have multiple instances with same PersonIDs, for example:…
test123
  • 13,865
  • 9
  • 28
  • 33
1273
votes
41 answers

How to remove the space between inline/inline-block elements?

There will be a 4 pixel wide space between these span elements: span { display: inline-block; width: 100px; background-color: palevioletred; }

Foo Bar

Fiddle Demo I understand that I could get rid…
Šime Vidas
  • 182,163
  • 62
  • 281
  • 385