What’s the difference between a string and a symbol in Ruby?

The main difference is that multiple symbols representing a single value are identical whereas this is not true with strings. For example: irb(main):007:0> :test.object_id => 83618 irb(main):008:0> :test.object_id => 83618 irb(main):009:0> :test.object_id => 83618 Those are three references to the symbol :test, which are all the same object. irb(main):010:0> “test”.object_id => -605770378 irb(main):011:0> “test”.object_id => … Read more

How to count instances of character in SQL Column

This snippet works in the specific situation where you have a boolean: it answers “how many non-Ns are there?”. SELECT LEN(REPLACE(col, ‘N’, ”)) If, in a different situation, you were actually trying to count the occurrences of a certain character (for example ‘Y’) in any given string, use this: SELECT LEN(col) – LEN(REPLACE(col, ‘Y’, ”))

What is the meaning of + in a regex?

+ can actually have two meanings, depending on context. Like the other answers mentioned, + usually is a repetition operator, and causes the preceding token to repeat one or more times. a+ would be expressed as aa* in formal language theory, and could also be expressed as a{1,} (match a minimum of 1 times and … Read more

Symbol hiding in static libraries built with Xcode

Hiding internal names requires a few simple Xcode build settings, and it is not generally necessary to modify source or change the type of the built product. Eliminate any internal symbols required between modules by performing a single-object prelink. Set the Xcode build setting named “Perform Single-Object Prelink” to Yes (GENERATE_MASTER_OBJECT_FILE=YES). This causes ld to … Read more

What does this symbol mean in PHP

To add to Mark’s answer: The short_tags option must be enabled for the <?= syntax to be valid. This presents a major portability problem when moving to a server that has this option disabled. See the PHP Manual for more info on short tags

When to use symbols instead of strings in Ruby?

TL;DR A simple rule of thumb is to use symbols every time you need internal identifiers. For Ruby < 2.2 only use symbols when they aren’t generated dynamically, to avoid memory leaks. Full answer The only reason not to use them for identifiers that are generated dynamically is because of memory concerns. This question is … Read more

What is the purpose of the ‘@’ symbol in CSS?

@ has been around since the days of @import in CSS1, although it’s arguably becoming increasingly common in the recent @media (CSS2, CSS3) and @font-face (CSS3) constructs. The @ syntax itself, though, as I mentioned, is not new. These are all known in CSS as at-rules. They’re special instructions for the browser, not directly related … Read more