odd-behavior

java swing - layout oddness when using different layout managers

Bit of oddness, seen if I do the following: import javax.swing.*; public class FunkyButtonLayout { public static void main(String[] args) { JFrame frame = new JFrame(""); JPanel j0 = new JPanel(); // j0 gets added to the root pane j0.setLayout(null); JPanel j1 = new JPanel(); // j1 gets added ...

AS3 Project - Mouse Move Listener Reacting Outside of Application

I'm getting an unusual behavior that I can't seem to get to the bottom of. When I run this, if I move in the swf area it traces normally on mouse move. To be expected. But it's tracing for the move event when I click anywhere on screen. If I click and drag, it traces as if I were moving in the swf area of the browser. Here's the code. ...

Strange behavior: Hash's keys cancel dynamic method definition

Let's say I want some instance of String behave differently from other, "normal" instances - for example cancel the effect of the "upcase" method. I do the following: class String def foo def self.upcase self end self end end It seems to work fine, and the way I need it: puts "bar".upcase #=> "BAR" puts "bar".fo...

Java counter-intuitive code

I remember reading a book named: Java Puzzlers Traps, Pitfalls, and Corner Cases that described odd behavior in Java code. Stuff that look completely innocent but in actuality perform something completely different than the obvious. One example was: (EDIT: This post is NOT a discussion on this particular example. This was the firs...

Why does C++ define the norm as the euclidean norm squared

This may sound like a bit of a rhetorical question, but I ask it here for two reasons: It took me a while to figure out what C++ std::norm() was doing differently from Matlab/Octave, so others may stumble upon it here. I find it odd to define the norm() function as being something different (though closely related) to what is generally...

Why doesn't this subroutine work? (vb.net DataGridView oddity)

For Each row As DataGridViewRow In DGV.Rows DGV.Rows.RemoveAt(CInt(row.Index.ToString)) Next The above code will remove every other row For i As Integer = 0 To 7 Step 1 For Each row As DataGridViewRow In DGV.Rows DGV.Rows.RemoveAt(CInt(row.Index.ToString)) ...

Silverlight 3 Dataform Commit Button not activating

I'm writing a ChecklistBox control, which is a listbox that renders CheckBoxes inside the list. I'm then using this control inside of a DataForm's EditTemplate. Along with this control, I've got two text boxes that are bound to properties of the DataContext of the Dataform. For reference, the ChecklistBox has three implemented propert...

Java OutOfMemoryError message changes when trying to create Arrays of different sizes

In the question by DKSRathore How to simulate the Out Of memory : Requested array size exceeds VM limit some odd behavior was noted when creating an arrays. When creating an array of size Integer.MAX_VALUE an exception with the error java.lang.OutOfMemoryError Requested array size exceeds VM limit was thrown. However when an array was...

Qt Python Combo-Box "currentIndexChanged" firing twice

I have a combo, which is showing some awkward behavior. Given a list of options from the combo-box, the user should pick the name of a city clicking with the mouse. Here is the code: QtCore.QObject.connect(self.comboCity, QtCore.SIGNAL("currentIndexChanged(QString)"), self.checkChosenCity) def checkChosenCity(self): ...

Why does tarfile.extractall ignore errors by default?

Python's tarfile module ignores errors during extraction by default, unless errorlevel is set to either 1 or 2 (or debug to 1 if only error messages need to be printed). Try doing a mkdir /tmp/foo && sudo chown root /tmp/foo && chmod a-w /tmp/foo and using tarfile to extract a .tar.gz file over /tmp/foo -- you will see that your Python...

How to avoid automatic renaming of sub signature parameters in visual basic 6.

In Visual basic 6, i declare a sub like this: Private Sub test1(ByRef XmlFooOutput As String) ... End Sub Aafter that, I declare another sub like the following one: Private Sub test2(ByRef xmlFooOutput As String) ... End Sub Automagically, the first method is transformed in: Private Sub test1(ByVal xmlFooOutput As String) ....

Double forward slash in a string using stripos() will not match a string even if it is present?

I ran into a little problem today when I was creating a really quick script to scan lines files in a user specified directory for //todo:... So I had a line like this: if (stripos($data, '//todo:')) { //case-insensitive search ^^ //deal with the data appropriately } This did not find //todo: anywhere in any of the files! This was ...

Can you explain this edge case involving the C# 'using' keyword with namespace declarations and members?

Consider the following short code snippet. namespace B { public class Foo { public string Text { get { return GetType().FullName; } } } } namespace A.B { public class Foo { public string Text { get { return GetType().FullName; } } } } Get ...

Strange CUDA behavior in vector multiplication program

Hi, I'm having some trouble with a very basic CUDA program. I have a program that multiplies two vectors on the Host and on the Device and then compares them. This works without a problem. What's wrong is that I'm trying to test different number of threads and blocks for learning purposes. I have the following kernel: __global__ void m...

Bizzare APS.net "Object reference not set to an instance of an object"

So a bit of an overview around the lead up to this exception. I've created a website on my dev machine (windows xp, asp.net 4) and targeted it to .Net 3.5. I then deployed the 100% working website on the stage machine (Windows 7, ASP.net 2, IIS 7.5). After sorting out numerous security problems, I've come to a stop at this bewildering...

Two files, exactly the same code, different output?

This is the weirdest thing that has ever happened to me sime I am a (PHP) programmer... I have two files, with the following code (proj. euler stuff) that return different outputs. <?php $numbers =<<<eot 2,3 5,2 9,3 4,9 6,3 10,5 eot; $numbers = explode("\n",$numbers); $max = 0; foreach($numbers as $k => $n){ list($base,$expo) = exp...

Why does adding or removing a newline change the way this perl for loop functions?

I'm starting to learn perl, using the Wrox Beginning Perl available on perl.org and have a question regarding a for loop example they provide in Chapter 3. #!/usr/bin/perl use warnings; use strict; my @count = (1..10); for (reverse(@count)) { print "$_...\n"; sleep 1; } print "Blast Off!\n" This is the script they pr...

C# int byte conversion

Why is byte someVar; someVar -= 3; valid but byte someVar; someVar = someVar - 3; isnt? ...

UserControl and binding paths--is it magic or logic?

I'm trying to confirm a binding behavior I believe I have observed, but I'm not exactly sure of. My original understanding was that a UserControl was sort of a black box, where if you wanted to share information back and forth with the controls contained within, you had to (1) use the DataContext or (2) define them on the surface of the...

C#: Why do mutations on readonly structs not break?

In C#, if you have a struct like so: struct Counter { private int _count; public int Value { get { return _count; } } public int Increment() { return ++_count; } } And you have a program like so: static readonly Counter counter = new Counter(); static void Main() { // print the new v...