syntax

Ruby: What's the proper syntax for a boolean regex method?

What is the proper syntax for a method that checks a string for a pattern, and returns true or false if the regex matches? Basic idea: def has_regex?(string) pattern = /something/i return string =~ pattern end Use case: if has_regex?("something") # woohoo else # nothing found: panic! end ...

How to verify a datatype mismatch? (not=== false)

What's the opposite of triple equals matching in PHP? $mail_01 = filter_var($mail_01, FILTER_VALIDATE_EMAIL); if($mail !== false){ echo "Email address required"; } Is the !== usage correct? Thanks for any help. ...

Why this is not valid MySQL query?

mysql> ALTER TABLE bdds_arts ADD test VARBINARY; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 something wrong with varbinary type? here is output of mysql --version mysql Ver 14.12 Distrib 5.0.24a, for Win32 (...

SQL Syntax with AS and ORDER BY in nested queries

I have a query with the following syntax: select x.a as a, x.b as b, x.c as c from (select distinct a from foo order by y) as x left join zzz.... left join yyy...; I want to now put in an order by into the outer select statement. attaching it to the end - it doesn't like the syntax, and putting it before the as is apparent...

How to get generic's class

Class Model<T>{ private T t; ..... private void someMethod(){ //now t is null Class c = t.getClass(); } ..... } Of course it throws NPE. Class c = t.getClass(); What syntax should i use to get class of T if my instance is null? Is it possible? ...

Redirecting paginator->sort to the first page in Cakephp

How do I do a paginator sort and also specify it to go to the first page: echo $paginator->sort('Make', 'Car.make'); If you're on page 6 and want to sort the list by car make. It sorts the list but puts you on page 6 of the sorted list. When someone clicks on the sort by "make" button, I want the paginator to take them to page 1 of th...

JavaScript syntax

In another question answered here I found the following JavaScript code: function _dom_trackActiveElement(evt) { if (evt && evt.target) { document.activeElement = evt.target == document ? null : evt.target; } } But this syntax is unknown to me, could someone explain exactly what document.activeElement = evt.target =...

SQLDataReader: Dealing with null values

Some tables I am dealing with have null values and are throwing errors. So far ive tried a few solutions to deal with the nulls with no success. Here are the code samples from my efforts so far; If (r("datemodified").Equals(DBNull.Value)) Then datemodified = String.Empty Else datemodified = (...

Invoking methods

Hi, Now that I have a better grasp of Classes and their importance in C#, I have a question about how to handle a certain situation. I have to perform 5-6 tests using 3 different external devices that all require about 10 or so commands to be setup at the begining of each test. So there are approx 10 commands for each device for 6 tes...

Python comparison evaluation

As per the python documentation,x<y<z comparison is translated to x<y and y<z and expression y is evaluated only once at most. Now my question is , does an expression y ( look at the code below) is evaluated only once here? if(x<y and y<z): ...

Ruby lambda arguments

This code works as expected (does nothing, even doesn't produce warning/errors): l = lambda {|i|} l.call(1) This code produces warning (warning: multiple values for a block parameter (0 for 1)): l = lambda {|i|} l.call And this code fails with error (ArgumentError: wrong number of arguments (0 for 2)): l = lambda {|i, y|} l.call ...

Sort mysql table based on number of rows in another table

Hi, I'm trying to sort a user table based on how many comments they have linked to them in a secondary comment-table, I figured a sub-select will be the best tool but I can't get the syntax correct. Users table testdata: id | user_id 1 | 1000 2 | 1001 3 | 1002 Comment table testdata id | link_id 1 | 1002 2 | 1000 3 | 1002 4 |...

Java: Adding to an array list

public class Maze { public static final int ACTIVE = 0; public static final int EXPLORER_WIN = 1; public static final int MONSTER_WIN = 2; private Square[][] maze; private ArrayList<RandomOccupant> randOccupants; private Explorer explorer; private int rows; private int cols; public Maze(Square[][] maze, i...

Simple C++ syntax question about colon

Hi everyone, I just saw a code snippet with a piece of syntax that I have never seen before. What does bool start : 1; mean? I found it inside a class definition in a header file. ...

How to extract the most common YEAR from an array of DateTime objects using LINQ

Hi, im trying to extract the most common YEAR from an array of DateTime objects using LINQ. can someone help me? With the following its telling me i need to implement IComparable.. DateTime modeDate = (from c in dates group c by c.Year into g select g).Max(...

How can I use Vim syntax files to collapse single line comments into one region?

I'm putting together a syntax for editing Java Manifest files (at github, if anyone's interested). I'm trying to collapse multiple single-line-comments (which I'm matching at the moment with syntax match manifestComment "#.*"). However, if I try to use a syntax region, then the entire file is marked and the entire thing collapses. What ...

When to use || vs. OR in ColdFusion in a <cfif>?

When do I use an "OR" vs a || in a ColdFusion cfif statement? ...

postgresql help with create table syntax

I'm more a mysql person, but I have to do a db in pg and the following CREATE TABLE keeps generating syntax errors... I just get an error: ERROR: syntax error at or near "(" and error: ERROR: syntax error at or near ")" Googling around didn't give me much help... I'm sure that I'm doing something mysql-esque and that's causing problems...

What's the correct syntax for applying a function to sub elements of a matrix without using a loop?

I have a defined a function (GetDepth) which does something fairly trivial, eg takes in a 2x4 matrix and outputs a 2x1 matrix. I then have an 2x4xn matrix I want to apply it to, and I'm expecting an 2x1xn matrix result. What is the correct syntax to apply my function to the matrix without resorting to using a loop? ed. As requested, h...

What are [] in C#?

For example: [TestFixtureSetUp] public void Init() { GetTestRepo(false); } [TestFixtureSetUp] in this example, what does it do? From my experience, [] usually refers to lists. ...