I know you Ruby people will laugh at my bad Ruby code:
i=0
for blah in blahs
puts i.to_s + " " + blah
i+=1
end
I want to use a for-each and a counter... is there a better way to do it?
Note: I don't know if blahs is an array or a hash, but having to do blahs[i] wouldn't make it much sexier. Also I'd like to know how to write ...
Is it OK to use == on enums in Java, or do I need to use .equals()? In my testing, == always works, but I'm not sure if I'm guaranteed of that. In particular, there is no .clone() method on an enum, so I don't know if it is possible to get an enum for which .equals() would return a different value than ==.
For example, is this OK:
pu...
I have a jquery menu that has so many entries that it extends further than the length of the page. I want to get the amount of entries in each menu section so I can use that number to resize a padding div at the end of the page.
$('.hideMe').click(function(){
alert( $(this).next('ul').children() );
});
So I want to find out the a...
When you encounter working code that is unpleasing to the eye, how likely are you to refactor it? I know code aesthetics is mostly subjective, but I'm bothered a lot by "ugly" code and find it difficult to resist the urge to clean it up.
I don't like:
Heavy function nesting
AndFinally(AndThenDoThis(DoThis(strVar, 1, DoThat("February"...
In the following ruby code, the output becomes: "x y"
x = "x %s"
y = "y"
z = "z"
print x % y %z
The %z is ignored.
I want the output to be "x y z".
To understand the possibilities and limitations of the syntax of Ruby, I want to use only the print command and the %s and % flags. I know how to do this using sprintf but I want to kno...
I'm expecting this output:
output:xyz
But if I type the following:
a = ["x", "y", "z"]
print "output:" + a.each {|i| print i}.to_s
Why do I get an 'xyz' before the word output as well as after it?
xyzoutput:xyz
...
I've never seen undef - or any thing else that allows you to undefine a method - in any other programming languages. Why is it needed in Ruby?
EDIT: I'm not arguing that there is anything wrong with this. I just don't understand the purpose of defining methods at runtime? What's the purpose of that? How is it used? I've never done this ...
What's the difference between eq, eql, equal, and equalp in Lisp? I understand that some of them check types, some of them check across types an all that, but which is which? When is one better to use than the others?
...
When writing my first asp.net MVC application using C#, I see that there are some variables whose name start with an underscore character(_).
What does this mean? Is there any specific meaning for this?
...
When have you run into syntax that might be dated, never used or just plain obfuscated that you couldn't understand for the life of you.
For example, I never knew that comma is an actual operator in C. So when I saw the code
if(Foo(), Bar())
I just about blew a gasket trying to figure out what was going on there.
I'm curious what ...
I've just read this nice piece from reddit.
They mention "and" and "or" being "Alternative Tokens" to && and ||
I was really unaware of these just till now. Of course, everybody knows about the di-graphs and tri-graphs but "and" and "or"? Seriously? Since when? Is this a recent addition to the standard?
I've just checked it with Visua...
I know that you can use a javascript: pseudo protocol for URLs in an <a> tag. However, I've noticed that Firefox and IE will both allow 'javascript:' to precede javascript code within a <script> tag. Is this valid syntax? Does it change the scoping rules?
Examples:
I've seen this many times:
<a onclick="javascript:alert('hello world...
&& is notoriously hard to search for on google, but the best I've found is this article which says to use -and.
Unfortunately it doesn't give any more information, and I can't find out what I'm supposed to do with -and (again, a notoriously hard thing to search for)
The context I'm trying to use it in is "execute cmd1, and if successfu...
MODEL:
class Pathology(models.Model):
pathology = models.CharField(max_length=100)
class Publication(models.Model):
pubtitle = models.TextField()
class Pathpubcombo(models.Model):
pathology = models.ForeignKey(Pathology)
publication = models.ForeignKey(Publication)
List of pathology sent to HTML template as drop dow...
In Perl, one can often avoid using control blocks, like this:
print "$_\n" foreach(@files);
instead of:
foreach(@files){
print "$_\n";
}
How does this syntax work in the following, more complex case:
die("Not a file: $_") unless -f $_ foreach(@files);
It gives me a syntax error. I'm not trying to write obfuscated code, it's ju...
I've seen the word static used in different places in C code; is this like a static function/class in C# (where the implementation is shared across objects)?
...
What's the most elgant way in Groovy to specify a range of integers and the 0.5 steps between them? e.g.: 1, 1.5, 2, 2.5, 3, 3.5, 4
Edit: To clarify: As an end result I need a range object for use in a Grails constraint. Though I suppose a list would be OK too.
...
I'm writing a PHP IDE in Qt4 for my Master's project. I am trying to duplicate a lot of the functionality of Eclipse or Visual Studio without all the bloat and the overhead. I'm trying to do some code completion but I need to do some syntax analyzing to have intelligent code completion. I've looked at the PHP source code and thought abou...
Hello,
i want to create some simple wrapper classes for an existing class library. To make the syntax nice to read AND nice to guess (via code completion) i'd like to remove the methods of java.lang.Object.
The problem is that all non-atomic things in java inherit from Object and thus have these methods. I already tried to create the wr...
I'm using an if statement to declare whether a user is an admin, mod or neither with this code below, but its messing up by always making $status = "admin" even if that person is neither, this has really baffled me.
if($info['rights'] == "m") {
$status = '<font color="#FFFFFF">(mod)</font>';
}elseif ($info['rights'] == "a"); {
$...