|
The () seems silly. is there a better way?
For example:
ExternalId.IfNotNullDo(()=>ExternalId=ExternalId.Trim());
Started by brendanjerwin on
, 5 posts
by 5 people.
Answer Snippets (Read the full thread at stackoverflow):
For a lambda....
Whether there ever will be one or not is a different matter .
I know that the C# team feels your pain, and have tried to find an alternative .
Lambda expressions are optimised (in terms of syntax) for the single parameter case .
No, there isn't.
|
|
Quick one, but thought I'd ask.
Is there a better way of getting the column values from a model's column than something like this?
Item.count(:all, :group => 'status').reject! { |i, e| i.blank? }.collect { |i,e| i}
Started by The Pied Pipes on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
Status is blank? count is blank?
Item.find(:all, :select....
But then could you please specify more criteria you want? i.e .
Maybe not ..
Is it the same thing as the following code?
Item.count(:all, :group => "status", :conditions => "status != ''"}
. .
|
|
What is the better way of getting the IP address in PHP:
getenv('REMOTE_ADDR');
or,
$_SERVER['REMOTE_ADDR'];
please tell me the difference, if any, between the two.
Started by Sachindra on
, 6 posts
by 6 people.
Answer Snippets (Read the full thread at stackoverflow):
The common approach is to use....
Getenv() can be used to access any environment variables (PHP simply registers REMOTE_ADDR as an environment variable for the script), while with $_SERVER you obviously only access the contents of the $_SERVER superglobal .
|
Ask your Facebook Friends
|
This is related to my question asked here today on SO. Is there a better way to build a packet to send over serial rather than doing this:
unsigned char buff[255]; buff[0] = 0x02 buff[1] = 0x01 buff[2] = 0x03 WriteFile(.., buff,3, &dwBytesWrite,..);
Note...
Started by Changeling on
, 7 posts
by 7 people.
Answer Snippets (Read the full thread at stackoverflow):
There is a much better way, which is using structs to set.
:-)
Is there a better way to build a packet than concerns like this can help reuse.
This is left as an exercise for the reader.
|
|
On a PHP file, I receives more than 20 variables coming from the client(submitted via a web form) and I have to apply mysql_real_escape_string() more than 20 times, it is quite troublesome, is there a better way to do this job?
Started by Steven on
, 5 posts
by 5 people.
Answer Snippets (Read the full thread at stackoverflow):
They're a little bit wordy.
);
is there a better way to do this job?
Certainly: parameterised queries .
|
|
Is there a better way of doing data validation in Perl than regex?
I have Perl code that does string and numeric data validation using complex regex, and this makes code difficult to read and follow, for everyone.
Started by not-exactly-a-unixhater on
, 8 posts
by 8 people.
Answer Snippets (Read the full thread at stackoverflow):
If you want to make sure variable values fit a certain pattern, there is no better way than to use.
|
|
In this answer to a question I asked. Kathy Van Stone says that adding an array like so
jList1.setListData(LinkedHashMap.keySet().toArray());
is a better way than to do it like this
jList1.setListData(new Vector<String>(LinkedHashMap.keySet()));...
Started by Soldier.moth on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
I would prefer the first one, simply because there is no need to involve yet another collection (Vector)
Do you need the synchronization... .
Take a look at implementation of both setListData methods in JList class and you will see that it really doesn't matter .
|
|
Hi, This is probably trivial, but I can't think of a better way to do it. I have a COM object that returns a variant which becomes an object in C#. The only way I can get this into an int is
int test = int.Parse(string.Format("{0}", myobject))
Is there...
Started by Steve on
, 7 posts
by 7 people.
Answer Snippets (Read the full thread at stackoverflow):
Int test; bool result = Int32.TryParse(value, out test); if (result) { Console.WriteLine("Sucess"); } else { if (value == null) value = ""; Console.WriteLine... .
Use Int32.TryParse as follows.
Watch out for exception, in both cases.
Maybe Convert.ToInt32.
|
|
I've always handled optional parameters in Javascript like this:
function myFunc(requiredArg, optionalArg){ optionalArg = optionalArg || 'defaultValue'; //do stuff }
Is there a better way to do it?
Are there any cases where using || like that is going...
Started by Mark Biek on
, 7 posts
by 7 people.
Answer Snippets (Read the full thread at stackoverflow):
Your logic fails if optionalArg is passed, but evaluates as false - try this as an alternative
optionalArg = (typeof optionalArg == "undefined")?'defaultValue':optionalArg
http://www.openjs.com/articles/optional_function_arguments.php
Try this basically... .
|
|
I have a TreeSet, which will be full of integers. To make a long story short, I'm trying to loop starting after the last (greatest) value stored in the list. What I'm doing now to get the starting variable is:
Object lastObj = primes.last(); Integer last...
Started by Jeremy on
, 7 posts
by 7 people.
Answer Snippets (Read the full thread at stackoverflow):
Int start = 1 + last;
http://java.sun.com/j2se/1.5.0/docs/guide/language/autoboxing.html
Also, if you know they're all going to be Integer objects, use the parameterized type:... .
In J2SE 5 or later it happens automatically, with the "autoboxing" feature .
|