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
...
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.
...
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 (...
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...
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?
...
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...
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 =...
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 = (...
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...
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):
...
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
...
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 |...
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...
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.
...
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(...
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 do I use an "OR" vs a || in a ColdFusion cfif statement?
...
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...
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...
For example:
[TestFixtureSetUp]
public void Init()
{
GetTestRepo(false);
}
[TestFixtureSetUp] in this example, what does it do? From my experience, [] usually refers to lists.
...