C# binary literals

Update C# 7.0 now has binary literals, which is awesome. [Flags] enum Days { None = 0, Sunday = 0b0000001, Monday = 0b0000010, // 2 Tuesday = 0b0000100, // 4 Wednesday = 0b0001000, // 8 Thursday = 0b0010000, // 16 Friday = 0b0100000, // etc. Saturday = 0b1000000, Weekend = Saturday | Sunday, Weekdays = … Read more

Java method with return type compiles without return statement

Question 1: Why does the following code compile without having a return statement? public int a() { while(true); } This is covered by JLS§8.4.7: If a method is declared to have a return type (§8.4.5), then a compile-time error occurs if the body of the method can complete normally (§14.1). In other words, a method … Read more

What do you call the -> operator in Ruby?

In Ruby Programming Language (“Methods, Procs, Lambdas, and Closures”), a lambda defined using -> is called lambda literal. succ = ->(x){ x+1 } succ.call(2) The code is equivalent to the following one. succ = lambda { |x| x + 1 } succ.call(2) Informally, I have heard it being called stabby lambda or stabby literal.

What is the benefit of using $() instead of backticks in shell scripts? [duplicate]

The major one is the ability to nest them, commands within commands, without losing your sanity trying to figure out if some form of escaping will work on the backticks. An example, though somewhat contrived: deps=$(find /dir -name $(ls -1tr 201112[0-9][0-9]*.txt | tail -1l) -print) which will give you a list of all files in … Read more

Test for non-zero length string in Bash: [ -n “$var” ] or [ “$var” ]

Edit: This is a more complete version that shows more differences between [ (aka test) and [[. The following table shows that whether a variable is quoted or not, whether you use single or double brackets and whether the variable contains only a space are the things that affect whether using a test with or … Read more

JavaScript error (Uncaught SyntaxError: Unexpected end of input)

Add a second });. When properly indented, your code reads $(function() { $(“#mewlyDiagnosed”).hover(function() { $(“#mewlyDiagnosed”).animate({‘height’: ‘237px’, ‘top’: “-75px”}); }, function() { $(“#mewlyDiagnosed”).animate({‘height’: ‘162px’, ‘top’: “0px”}); }); MISSING! You never closed the outer $(function() {.