Most Popular

1500 questions
1144
votes
8 answers

What is the difference between canonical name, simple name and class name in Java Class?

In Java, what is the difference between these: Object o1 = .... o1.getClass().getSimpleName(); o1.getClass().getName(); o1.getClass().getCanonicalName(); I have checked the Javadoc multiple times and yet this never explains it well. I also ran a…
Mohamed Taher Alrefaie
  • 15,698
  • 9
  • 48
  • 66
1143
votes
20 answers

What is attr_accessor in Ruby?

I am having a hard time understanding attr_accessor in Ruby. Can someone explain this to me?
dennismonsewicz
  • 25,132
  • 33
  • 116
  • 189
1143
votes
49 answers

Calculate distance between two latitude-longitude points? (Haversine formula)

How do I calculate the distance between two points specified by latitude and longitude? For clarification, I'd like the distance in kilometers; the points use the WGS84 system and I'd like to understand the relative accuracies of the approaches…
Robin Minto
  • 15,027
  • 4
  • 37
  • 40
1143
votes
20 answers

Best way to remove an event handler in jQuery?

I have an input type="image". This acts like the cell notes in Microsoft Excel. If someone enters a number into the text box that this input-image is paired with, I setup an event handler for the input-image. Then when the user clicks the image,…
Randy L
  • 14,384
  • 14
  • 44
  • 73
1142
votes
16 answers

How do I clear/delete the current line in terminal?

If I'm using terminal and typing in a line of text for a command, is there a hotkey or any way to clear/delete that line? For example, if my current line/command is something really long like: > git log --graph --all --blah..uh oh i want to cancel…
triad
  • 20,407
  • 13
  • 45
  • 50
1142
votes
12 answers

Insert into a MySQL table or update if exists

I want to add a row to a database table, but if a row exists with the same unique key I want to update the row. For example: INSERT INTO table_name (ID, NAME, AGE) VALUES(1, "A", 19); Let’s say the unique key is ID, and in my Database, there is a…
Keshan
  • 14,251
  • 10
  • 48
  • 72
1142
votes
12 answers

Grouping functions (tapply, by, aggregate) and the *apply family

Whenever I want to do something "map"py in R, I usually try to use a function in the apply family. However, I've never quite understood the differences between them -- how {sapply, lapply, etc.} apply the function to the input/grouped input, what…
grautur
  • 29,955
  • 34
  • 93
  • 128
1142
votes
18 answers

What is an idempotent operation?

What is an idempotent operation?
Will
  • 19,789
  • 10
  • 43
  • 45
1141
votes
14 answers

Static Classes In Java

Is there anything like static class in Java? What is the meaning of such a class? Do all the methods of the static class need to be static too? Is it required the other way round as well? That if a class contains only static methods, the class shall…
Kraken
  • 23,393
  • 37
  • 102
  • 162
1141
votes
43 answers

How can I represent an 'Enum' in Python?

I'm mainly a C# developer, but I'm currently working on a project in Python. How can I represent the equivalent of an Enum in Python?
John Rutherford
  • 10,704
  • 7
  • 30
  • 32
1141
votes
21 answers

Best way to use multiple SSH private keys on one client

I want to use multiple private keys to connect to different servers or different portions of the same server (my uses are system administration of server, administration of Git, and normal Git usage within the same server). I tried simply stacking…
Justin
  • 11,483
  • 3
  • 16
  • 7
1141
votes
36 answers

How can I change the name of an iOS app in Xcode?

I began an iPhone project the other day with a silly development code name, and now I want to change the name of the project since it's nearly finished. How can I do this?
Robert Gould
  • 68,773
  • 61
  • 187
  • 272
1141
votes
60 answers

Find the min/max element of an array in JavaScript

How can I easily obtain the min or max element of a JavaScript array? Example pseudocode: let array = [100, 0, 50] array.min() //=> 0 array.max() //=> 100
HankH
  • 11,453
  • 4
  • 17
  • 4
1140
votes
22 answers

LINQ query on a DataTable

I'm trying to perform a LINQ query on a DataTable object and bizarrely I am finding that performing such queries on DataTables is not straightforward. For example: var results = from myRow in myDataTable where results.Field("RowNo") == 1 select…
Calanus
  • 25,619
  • 25
  • 85
  • 120
1138
votes
15 answers

Check whether a string matches a regex in JS

I want to use JavaScript (I can also use jQuery) to do check whether a string matches the regex ^([a-z0-9]{5,})$, and get a true or false result. match() seems to check whether part of a string matches a regex, not the whole thing. Does it solve the…
Richard
  • 31,629
  • 29
  • 108
  • 145