syntax

Why does Javascript's OR return a value other than true/false?

I saw this construction in order to get the browser viewport width: function () { return window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth; } I understand the browser quirks involved. What I don't understand is why || returns the value. So I tried this alert(undefined || 0 || 3); and sure enough, i...

Nesting, grouping Sqlite syntax?

I can't for the life of me figure out this Sqlite syntax. Our database contains records like: TX, Austin OH, Columbus OH, Columbus TX, Austin OH, Cleveland OH, Dayton OH, Columbus TX, Dallas TX, Houston TX, Austin (State-field and a city-field.) I need output like this: OH: Columbus, Cleveland, Dayton TX: Dallas, Houston, Austin ...

json object composition details

in .json text, is the 'value' in a basic single pair object the title of a value type (e.g. [string, number, object]), or a value for a typed object (e.g. 2, or "dog", or Object3)? This is how http://www.json.org/ presents the information: "An object is an unordered set of name/value pairs. An object begins with { (left brace) a...

Is there a neater syntax for displaying a variable in erb?

I'm new to Ruby, and I found the <%= @my_variable %> a little lengthy and less readable. Shouldn't erb have something like ${@my_variable} (like the good old Velocity engine in Java)? ...

"boolean and include .." works but "boolean and unset($v)" reports syntax error in PHP?

This works: !function_exists('testfunc') and include("testfunc.php"); This will report syntax error: !function_exists('testfunc') and unset($q); Aren't they the same thing? ...

Why I'm not warned of this problem?

Suppose I have two classes defined the following way: public class A { public A() { foo(); } public void foo() { System.out.println("A"); } } public class B extends A { private String bar; public B() { bar = "bar"; } @Override public void foo() { System.out.println(bar); } } ...

Is it possible to assign the same value to multiple keys in a dict object at once?

In Python, I need a dictionary object which looks like: {'a': 10, 'b': 20, 'c': 10, 'd': 10, 'e': 20} I've been able to get this successfully by combining the dict.update() and dict.fromkeys() functions like so: myDict = {} myDict.update(dict.fromkeys(['a', 'b', 'c'], 10)) myDict.update(dict.fromkeys(['b', 'e'], 20)) However, bec...

C# Lambda expression syntax: are brackets necessary?

I'm new in C# and earlier I saw the lambda expression is like (params) => { expression;} but in LINQ, I saw examples like IEnumerable<string> customerFirstNames = customers.Select(cust => cust.FirstName); No brackets. Are they the same or is there any difference? Thanks a lot. ...

should I use semicolon at end of line when coding JavaScript?

Possible Duplicates: Do you recommend using semicolons after every statement in JavaScript? Why use semicolon? What are the ups and downs of using semicolons to end commands in JavaSript? What are the arguments for and against doing so? ...

Should my if statement work, is it structured properly?

if (file_exists($cachefile) && (time() - $cachetime < filemtime($cachefile)) && $_SERVER['REQUEST_URI'] != "login" || "thankyou" || "confirm") Should this code work, operators wise and syntax wise? ...

What dose this mean? Parse error: syntax error, unexpected ':' How do i fix it?

Parse error: syntax error, unexpected ':' ...

jQuery $.each(arr, foo) versus $(arr).each(foo)

In jQuery, what's the difference between the following two constructions of jQuery.each: // Given var arr = [1,2,3,4], results = [], foo = function (index, element) { /* something done to/with each element */ results.push(element * element); // arbitrary thing. } // construction #1 $.each(arr, foo); // result...

Rails newb syntax question

I'm in the console, looking at someone else's app. I come across the following: >> p.location => [#<Tag id: 2, name: "projects">] Why do I see this result, which seems to be the object name, and how do I access the actual attribute name, "projects"? >> p.location.name => "Tag" Thank you very much! ...

C++ WCHAR: Cannot allocate an array of constant size 0

I'm trying to create a WCHAR: LONG bufferSize = foo.bar() + 1; WCHAR wszBaz[bufferSize]; The compiler issues an error: error C2057: expected constant expression error C2466: cannot allocate an array of constant size 0 error C2133: 'wszBaz' unknown size What am I doing wrong? UPDATE: I added const but it still gives the same error:...

ruby language syntax(how platform_info variable is used

class EncodeDemoTest < Test #inheritance in ruby def setup(platform_info, logdir) @telnet_ip = platform_info["telnet_ip"] @telnet_login = platform_info["telnet_login"] @telnet_password = nil @filesys_path = platform_info[...

PHP Object Access Syntax Question with the $

I've been having trouble searching for this answer because I am not quite sure how to phrase it. I am new to PHP and still getting my feet on the ground. I was writing a page with a class in it that had the property name. When I originally wrote the page there was no class so I just had a variable called $name. When I went to encapsu...

SQL Query to truncate table in IBM DB2

Hi, Can any one give me the syntax to truncate a table in IBM DB2. I m running the following command: truncate table tableName immediate; The eror is DB2 SQL Error: SQLCODE=-104, SQLSTATE=42601, SQLERRMC=table;truncate ;JOIN , DRIVER=3.50.152 Message: An unexpected token "table" was found following "truncate ". Expected tokens may in...

C++: Cannot convert from foo& to foo*

I have a method: odp(foo& bar); I'm trying to call it: foo baz; odp(&baz); I get a compiler error: error C2664: "odp" cannot convert parameter 1 from 'foo *' to 'foo &' What am I doing wrong? Aren't I passing in a reference to baz? UPDATE: Perhaps I have a misconception about the relationship between pointers and references. I ...

Want to learn Objective-C but syntax is very confusing

Coming from Java background I am guessing this is expected. I would really love to learn Objective-C and start developing Mac apps, but the syntax is just killing me. For example: -(void) setNumerator: (int) n { numerator = n; } What is that dash for and why is followed by void in parenthesis? I've never seen void in parenthesis...

How to use A ? x:y syntax with heredoc in PHP?

I tried this but only got a syntax error: <?php $a = true; $str = <<< EOF {$a ? 1 : 2} EOF; echo $str; Is it possible to use such kind of conditional statement inside heredoc? ...