Posts Tagged ‘tip’

.NET Path.Combine() in PHP

Wednesday, September 1st, 2010

I’m the type of person who prefers to do things in a way that I perceive as the proper or correct way. While this tends to make things take a bit longer to accomplish, I feel the result ends up being better overall. One such thing I noticed is that file and path handling in PHP was missing a function I used quite a bit when writing C# code. In C# there is a Path.Combine() function that appends two file paths together to form one complete path without having to care what the beginning character and ending character of the two paths are. I wrote up a little function in PHP to mimic what happens.

//take a path and/or a filename and combine them into one file path
function filePathCombine($path1, $path2)
{
  $completedPath = '';

  if(substr($path1, strlen($path1) - 2, strlen($path1) - 1) !== DIRECTORY_SEPARATOR)
  {
		$completedPath = $path1 . DIRECTORY_SEPARATOR;
  }
  else
  {
		$completedPath = $path1;
  }

  if(substr($path2, 0, 1) !== DIRECTORY_SEPARATOR)
  {
		$completedPath .= $path2;
  }
  else
  {
		$completedPath .= substr($path2, 1, strlen($path2) - 1);
  }

  return $completedPath;
}

Looking through the code you will notice DIRECTORY_SEPARATOR, which is a global PHP constant. While it isn’t needed considering using / instead of \ would work on Windows and Linux, I thought it best to try to stay with my idea on how to do things the proper way.

Speed up Netbeans in Ubuntu Linux

Saturday, August 28th, 2010

Java Netbeans is a pretty decent editor for PHP code. I use Linux Ubuntu now for my primary desktop computer, so it’s quite convenient and easy to get running.

One issue is that in default configuration the program is a bit slow feeling.

Doing a quick search I found this page:

http://performance.netbeans.org/howto/jvmswitches/

Which describes a few command line parameters that might help the IDE function faster.

I’m currently running the command “/usr/bin/netbeans -J-Xverify:none -J-Xmx384m -Dsun.java2d.opengl=true”

Basically, it removes one unnecessary verification check, adds 256mb of RAM to the default RAM pool the program can use, and attempt to use OpenGL to render the IDE. I am currently using closed-source video card drivers, so your mileage could very with that last parameter.

You can modify your default system menu link by doing this:
Right-click on the “Applications” dropdown system menu. Select the “Edit Menus” list item.
Click the Programming menu and then the Netbeans X.X icon. There will be a Properties button where you can modify the command being called. Just add the parameters you would like to try out in there.

Overall I feel a noticeable improvement in scrolling, auto-completion pop-ups, and switching between tabbed documents with the limited bit of testing I’ve done so far.

DLL Files And .NET ClickOnce Deployment

Saturday, March 1st, 2008

I want to deploy one of my .NET apps as a ClickOnce application. The issue is that I am connecting to Oracle (see previous posts here and here). Connecting to Oracle requires at least, 4 DLL files that generally have to be in the same directory as the EXE file. The issue is that when the program is published, the DLLs are not referenced in any way, so the program won’t work.

Then I read about adding the files to the project, so that ClickOnce and the Publish processor will figure out that the DLLs are required and add them to the manifest.

Here is the process in Visual Studio 2005:
1. Put the 4 DLL files in their own directory in your solution directory (for ease of use mostly).
2. Add all four files to your project by going to “Project->Add Existing Item…”
3. Click on each DLL file in the solution explorer and then change their property: “Copy To Output Directory” to “Copy Always”.

That’s it! Now when I publish or even run the application I don’t have to worry about if the DLL files are where they should be.

C# .NET Programming Tip: Oracle Connection Revised

Saturday, March 1st, 2008

Take not that Microsoft will discontinue support for System.Data.OracleClient in .NET 4.0. This method should still work, but it will be depreciated…

Now that I have had more time to work with Oracle, I found a better way to connect then described in my previous post. With this new method you can connect to multiple instances in one program by getting rid of that tnsnames file.

*Remember that a project reference to System.Data.OracleClient must be added:

OracleConnection dbConnection;

string connectionString = "Server=(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = *******)(PORT = 1521))(CONNECT_DATA = (SID = *****)));Persist Security Info=true;User Id=*****;Password=*****;";

dbConnection = new OracleConnection(connectionString);

It’s really that simple. The key here is that the connection string must use the “Server” attribute instead of the “Data Source” one. I ran upon that while looking at the specification on Microsoft’s MSDN documentation site.

It’s basically a tnsnames string with a few more attributes like user id and password. Just remember that:
host is the name of your server or ip address, sid is the name of your database meaning the *** part of ***.world, and of course the user id and password are your login credentials.

There is another helpful step that I will be posting about. It relates to ClickOnce and the 4 DLL files that you need to connect to Oracle.




The Way Of Coding



 
Scott J. Waldron Photography
Stock Photo Website
Tech Learning Site
Follow me on Twitter

Popular Article Tags

Archives

Pages