Find     Softwares Questions Affiliate
 
0
12/30/2008 12:05:25
1 votes

Trying to redirect a URL on one webserver on my LAN to another webserver on my LAN. I assumed that all I needed was a .htaccess file in my /var/www directory whose contents are the following 3 lines only:

Options +FollowSymLinks

RewriteEngine on

RewriteMatch newsite\.level2\.level1\.com http://192.168.0.250:8080

Also I created a symbolic link in folder /etc/apache2/mods-enabled to /etc/apache2/mods-available/rewrite.load

1st: When I enter "newsite.level2.level1.com" in browser I end up at "level2.level1.com" 2nd: Does RewriteMatch support ports appended to the new URL

Should mention that level2.level1.com is thru DynDns.org as I have Comcast and the function to allow *.level2.level1.com is enabled

Thanks for looking, Rich

MrG
787
12/30/2008 12:04:41
5 votes

What is the correct way to separate between F1 and i.e. CTRL+F1 respective SHIFT-CTRL+F1 within an KeyListener registered behind i.e. a JButton?

public void keyPressed(KeyEvent event) {
    int key = event.getKeyCode();

    logger.debug("KeyBoard pressed char(" + event.getKeyChar() + ") code (" + key + ")");
}

.. always gives me 112 for F1, 113 for F2 and so on. I understand that I can handle it by taking care of the keyPressed() respective for keyReleased for CTRL / SHIFT / ALT / etc on my own, but I hope that there is a better way.

Many many thanks!!!

177
12/30/2008 12:04:16
13 votes

I've been extensively using smart pointers (boost::shared_ptr to be exact) in my projects for the last two years. I understand and appreciate their benefits and I generally like them a lot. But the more I use them, the more I miss the deterministic behavior of C++ with regarding to memory management and RAII that I seem to like in a programming language. Smart pointers simplify the process of memory management and provide automatic garbage collection among other things, but the problem is that using automatic garbage collection in general and smart pointer specifically introduces some degree of indeterminisim in the order of (de)initializations. This indeterminism takes the control away from the programmers and, as I've come to realize lately, makes the job of designing and developing APIs, the usage of which is not completely known in advance at the time of development, annoyingly time-consuming because all usage patterns and corner cases must be well thought of.

To elaborate more, I'm currently developing an API. Parts of this API requires certain objects to be initialized before or destroyed after other objects. Put another way, the order of (de)initialization is important at times. To give you a simple example, let's say we have a class called System. A System provides some basic functionality (logging in our example) and holds a number of Subsystems via smart pointers.

class System {
public:
    boost::shared_ptr< Subsystem > GetSubsystem( unsigned int index ) {
        assert( index < mSubsystems.size() );
        return mSubsystems[ index ];
    }

    void LogMessage( const std::string& message ) {
        std::cout << message << std::endl;
    }

private:
    typedef std::vector< boost::shared_ptr< Subsystem > > SubsystemList;
    SubsystemList mSubsystems;    
};

class Subsystem {
public:
    Subsystem( System* pParentSystem )
         : mpParentSystem( pParentSystem ) {
    }

    ~Subsystem() {
         pParentSubsystem->LogMessage( "Destroying..." );
         // Destroy this subsystem: deallocate memory, release resource, etc.             
    }

    /*
     Other stuff here
    */

private:
    System * pParentSystem; // raw pointer to avoid cycles - can also use weak_ptrs
};

As you can already tell, a Subsystem is only meaningful in the context of a System. But a Subsystem in such a design can easily outlive its parent System.

int main() {
    {
        boost::shared_ptr< Subsystem > pSomeSubsystem;
        {
            boost::shared_ptr< System > pSystem( new System );
            pSomeSubsystem = pSystem->GetSubsystem( /* some index */ );

        } // Our System would go out of scope and be destroyed here, but the Subsystem that pSomeSubsystem points to will not be destroyed.

     } // pSomeSubsystem would go out of scope here but wait a second, how are we going to log messages in Subsystem's destructor?! Its parent System is destroyed after all. BOOM!

    return 0;
}

If we had used raw pointers to hold subsystems, we would have destroyed subsystems when our system had gone down, of course then, pSomeSubsystem would be a dangling pointer.

Although, it's not the job of an API designer to protect the client programmers from themselves, it's a good idea to make the API easy to use correctly and hard to use incorrectly. So I'm asking you guys. What do you think? How should I alleviate this problem? How would you design such a system?

Thanks in advance, Josh

Guy
8907
12/30/2008 12:03:15
3 votes

In Silverlight 2 I have the following class declaration for a control:

public partial class ClassX : UserControl

I wish to replace UserControl with ClassXBase which derives from UserControl but I'm getting the reasonable error "Partial declarations of 'ClassX' must not specify different base classes"

However, I'm unable to find the other partial class to replace its base class. Any idea where this other partial class is or how I do this?

2021
12/30/2008 12:01:15
2 votes

Here is my issue. I have an array containing the name of cities that I need to lookup the weather for. So I'm looping through each city and performing an AJAX request to retrieve the weather.

var LOCATION = 'http://www.google.com/ig/api?weather=';

$( document ).ready( function() {
    for( var cityIdx = 0; cityIdx < cities.length; cityIdx++ ) {
    	$.ajax({
    		type: 'GET',
    		url: LOCATION + cities[ cityIdx ],
    		dataType: 'xml',
    		success: function( xml ) {
    			if( $( xml ).find( 'problem_cause' ) != 0 ) {
    				// Do what I want with the data returned
                    var weather = $( xml ).find( 'temp_c' ).attr( 'data' );
    			}
    		}
    	});
    }
});

The issue I'm encountering is that in the success function, I can't access the city name (via cities[cityIdx]). I inserted an alert() in the for loop and the success function and it seems like the loop gets executed cities.length times, then I get the success function alerts. My goal is to simply loop through each city getting the weather and showing it on my page along with the associated city name.

Also, what would you suggest I should do to separate content with presentation?

Thank you. :)

35457
12/30/2008 11:57:37
4 votes

I am working on some schema changes to an existing database.

I backed up the database to get a dev copy, and have made my changes. I will be creating a single roll script to migrate the changes on the production machine in a single transaction.

Is there a best practice for creating a rollback script encase a deployment issue arises? Before I've written then by hand using the following pattern:

  • Drop new constraints and indexes
  • Alter tables to remove new columns
  • Drop added tables
  • Commit transaction

Is there a better approach?

2361
12/30/2008 11:53:52
1 votes

We have a SQL server database which, according to Microsoft SQL Server Management Studio has just 119Mb out of 6436Mb available.

Yet the command: EXEC sp_msforeachtable 'sp_spaceused ''?'''
reveals a total reserved space that is less than 2Gb

How can we find out where the rest of the space is being used?

7332
12/30/2008 11:49:53
1 votes

I want all buttons to perform an action before and after their normal onclick event. So I came up with the "brilliant" idea of looping through all those elements and creating a wrapper function.

This appeared to work pretty well when I tested it, but when I integrated it into our app, it fell apart. I traced it down to the 'this' value was changed by my wrapper. The sample code illustrates this; before you wrap the event handlers, each button displays the button id when you click, but after wrapping it the displayed name is 'undefined' in this example, or 'Form1' if you run it from within a form.

Does anybody know either a better way to do the same thing? Or a good way to maintain the originally intended 'this' values?

As you can imagine, I don't want to modify any of the existing event handler code in the target buttons.

Thanks in advance.

PS-The target browser is IE6 & up, crossbrowser functionality not required

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<script language="javascript" type="text/javascript">
    function btnWrap_onClick()
    {
    	var btns = document.getElementsByTagName("button");
    	for( var i = 0; i < btns.length; i++)
    	{
    		var btn = btns[i];

    		// handle wrap button differerntly
    		if( "btnWrap" == btn.id)
    		{
    			btn.disabled = true;
    			continue; // skip this button
    		}

    		// wrap it
    		var originalEventHandler = btn.onclick;
    		btn.onclick = function()
    		{
    		    alert("Starting event handler");
    		    originalEventHandler();
    		    alert("Finished event handler");
    		}
    	}

    	alert("Buttons wrapped successfully");
    }
</script>
<body>
    <p>
    <button id="TestButton1" onclick="alert(this.id);">TestButton1</button>
    <button id="TestButton2" onclick="alert(this.id);">TestButton2</button>
    </p>
    <button id="btnWrap" onclick="btnWrap_onClick();">Wrap Event Handlers</button>
</body>
</html>
jpm
2582
12/30/2008 11:47:34
51 votes

I would like to customize both the background and the border color of a grouped-style UITableView.

I was able to customize the background color by using the following:

tableView.contentView.backgroundColor = [UIColor greenColor];

But the border color is still something I don't know how to change.

How do I customize these two aspects of the grouped-style table view?

31
12/30/2008 11:36:51
6 votes

First off, let’s agree that namespace should match folder structure and that each language artefact should be in its own file.

(see http://stackoverflow.com/questions/4664/should-the-folders-in-a-solution-match-the-namespace ).

The next question is how the folders should actually be organised on disk.
Suppose I have ClassC in the A.B.C namespace and ClassD in the A.B.C.D namespace.
Let’s also assume that each namespace is built into its own assembly (project) and that namespaces have dependencies from right to left as per accepted best practice (A.B.C.D can depend on A.B.C which can depend on A.B which can depend on A). I appreciate that each namespace doesn’t have to be in a separate assembly but in the general case we will have some namespaces in separate assemblies and my example illustrates that.

I can see (at least) two ways to create the folder tree – which I’ll call “nested folders” and “flat folders”:

1 - Nested folders:

A
--A.csproj
--B
----A.B.csproj
----C
------A.B.C.csproj
------classC.cs
------D
--------A.B.C.D.csproj
--------classD.cs

OR

2 – Flat folders:

A
--A.csproj
A.B
--A.B.csproj
A.B.C
--A.B.C.csproj
--classC.cs
A.B.C.D
--A.B.C.D.csproj
--classD.cs

You will see I’ve made a few assumptions already:

  • Each project file has a fully qualified name (FQN) based on the namespace.
  • Each class file uses a non-FQN

Nested folders seems more natural (we all like hierarchies), but may be a bit harder to navigate in large solutions:

When you look at your solution in VS, it shows a flat list of projects rather than a nested view. This looks more like “flat folders” so there may be merit in organising the folders on disk to match the view in VS.

If you look in each folder on disk you will see the folder artefacts for that project plus the sub folder for the namespace: taking C as an example:

C
--bin
--D
--obj
--Properties
--A.B.C.csproj
--classC.cs

Depending on D’s real name it may not be obvious that D is a namespace folder rather than an organisational folder in the C namespace.

I know we’ve had folders and namespaces from day one in .NET (8 or 9 years ago) and Java before that, but, personally speaking, we don’t appear to have come to a consensus on best practice project organisation for large solutions. I’d be really interested to find out what you all think.

Thanks
Michael