Archive for category Programming

jMonkeyEngine “An instance of the program cannot access specified user directory”

This is a simple issue and most Linux users can probably figure it out rather quickly. I don’t mean to offend anyone, but the error message is pretty straight-forward when it comes to the problem. However, I’ll explain it to those who run into it and want to know how to fix it. Then again, I may be the only person who runs into this problem. Either way, I’m posting it for anyone who may need it.

The problem stems with the installation of jMonkeyEngine. The installer is a .sh file which which can be executed like so:

1
sh jME3_SDK_Beta-Linux.sh

However, if you are like me, you may have ran it with sudo like this:

1
sudo sh JME3_SDK_Beta-Linux.sh

The good thing about using sudo is that the program will be installed for all users on the machine. I’ve not ran it without sudo to see if it will install for only the user running the installer, but I’m assuming that it will.

After the installation occurs, it asks you if you want to start jMonkeyEngine. If you answer yes, it will start it as root, and it will write it’s hidden users directory in your home directory. The home directory will have root:root as the owner because the program was first started by the root user.

So when you go back and run the program again, it will not have access to the required folder. The solution is to change the owner of the folder. This is accomplished simply by typing this in a terminal while in your home folder (the terminal should open in your home folder automatically, but just to make sure we’ll change directory into it first). In the following example the word “username” should be replace with your actual username.

1
2
cd ~/
chown -R username:username .jmonkeyplatform

You should now be able to open jMonkeyEngine. The -R, for those of you interested, means “recursive”, which will change the owner of all files and folder inside of .jmonkeyplatform, not just the folder itself.

, ,

No Comments

Increasing the size of tmpDSK and /tmp in a CPanel Environment

I recently ran into an issue in cPanel after recompiling Apache with some new settings. I enabled the eAccelerator extension in my EasyApache configuration for PHP. Now cPanel uses a default size for its /tmp mount of 512mb. I found out rather quickly that this isn’t enough for eAccelerator. I actually ended up resetting this value to 4096mb (4GB). As a reminder to myself and so anyone else looking for the solution to this problem, I will outline what needs to be done below.

First, ssh into your server and login as root or su – root after logging in as a regular user. Now use the power of the command line. Don’t panic!

Stop Apache, MySQL, and cPanel

1
2
3
service httpd stop
service mysql stop
service cpanel stop

Next unmount the existing /tmp

1
umount -l /tmp

Remove /usr/tmpDSK

1
rm -rf /usr/tmpDSK

Next, use your favorite editor (Vim in this example) to change the config file for the tmpDSK

1
vim /scripts/securetmp

Search the file for “tmpdsksize” (in Vim type /tmpdsksize and hit enter). The line should look like this by default:

1
my $tmpdsksize     = 512000;    # Must be larger than 250000

Change the 512000 to a higher number in Kilobytes. For my 4GB, I changed it to 4096000.
Save the file (vim :wq enter).
Run the script…

1
/scripts/securetmp

Answer y to the two questions it asks.
Finally start your services back up.

1
2
3
service httpd start
service mysql start
service cpanel start

That should have you set with more /tmp space.

, , , ,

No Comments

Marte Engine Define() and Check()

I’m not very fond of the way that Marte Engine’s Input checking occurs. It simplifies things a bit in one area and complicates things in all other areas. The simplification comes from the fact that one can list all the keys for a given action in the listener definition (define(“name”, keys…), and that is pretty helpful.

However there’s something I don’t really care for when it comes to the way Marte Engine handles keyboard input, namely, it’s too fast. The key repeat becomes an issue when working with things like menus.

Disclaimer: I’m far from being a Java or game development guru. I’m merely pointing out that I ran into this issue. There could very well be a work-around for this within the Marte engine itself. I ran into this problem while trying to implement a main menu for a test game I was working on. When I would push a button, the menu selection cursor would jump to the bottom of the menu, which isn’t at all what I wanted it to do.

The believe the reason for this is that the input definitions one can make with a define() method are set to handle only KeyDown events, while I needed a KeyPressed event. Since I could find no other way to force it to use a keypress instead of a keydown, I decided to remove my input event definitions and use a standard check on the input to see if a certain button has been pressed (down and released). This solved my issue with the key events. Now my menu cursor performs as expected.

, , ,

No Comments

Marte Engine TextEntity setColor()

I’ve been focusing on learning Java game development over the last couple of weeks. I’ve found that lwjgl, Slick2d, and Marte Engine are great libraries to help with the basic game functionality. In fact, they take a lot of the work out of it and leave you to focus on the game design itself. For instance, the Marte engine comes with a great resource manager class that helps keep up with images, sounds, and spritesheets for your game. Marte also has some good classes which extend Slick2D’s Entity class which can be very useful.

The one I’m going to focus on is TextEntity, which is great for adding text to the screen. However, I was unable to change the text color for the text directly using the setColor() method from the Entity class, which is inherited by TextEntity. There’s not a lot of documentation for either Slick2D or Marte, so I wasn’t exactly sure if I was missing something or if I had found a problem with the class.

Fixing the problem is rather simple. I created a new class called MyText and copied everything over from the TextEntity class. I could have extended it, but instead I wanted a new class which extends Entity directly. Then I changed the code in the render() method as such:

1
2
3
4
5
6
7
8
9
10
11
public void render(GameContainer container, Graphics g)	throws SlickException {
	if (font == null) {
		font = container.getDefaultFont();
		this.calculateHitBox();
	}
	g.setFont(font);
	if (text != null) {
		g.setColor(this.getColor());
		g.drawString(text, x, y);
        }
}

I then added a new constructor that takes a color as the fifth parameter:

1
2
3
4
5
6
public MyText(float x, float y, Font font, String text, Color color) {
	super(x,y);
	this.setColor(color);
	this.font = font;
	this.setText(text);
}

This gave me the functionality I was after. This change basically just sets the graphics object color property to the Entity’s color property, which is exactly how I thought it should have worked to begin with.

If there’s a better way to accomplish this, let me know. I’m only intermediate with Java.

No Comments

Adding Slick 2D and lwjgl to Eclipse Project

I spent some time today trying to get Slick and the light-weight java game library setup correctly in Eclipse. The tutorial I was watching was in Netbeans and I was very unfamiliar with adding libraries to a Java project in Eclipse (very familiar now). I’m going to go over how to do this as an overview, mainly just to remind me how to do it later hehe. It may also be of use to others who don’t need a step by step picture guide of the process. So, here goes!

  1. Create a new project in Eclipse
  2. Right-click the project and choose New -> Folder (call it “lib”)
  3. Right-click the lib folder and choose Import… then General -> File System
  4. Browse to your slick folder and choose the slick.jar and the lwjgl.jar files.
  5. Right-click on the project and choose Properties
  6. Choose “Java Build Path” and click the “Libraries” tab
  7. Click “Add Jars”. It will show a tree of your project. Expand it till you see your lib folder. Expand it. Select the two jars (utilize shift for multiple selection). Click OK.
  8. Click OK again to go out to the workspace.
  9. Right-click on the lib folder and Import again. This time use “Archive File” instead of “File System”. Click Next.
  10. Browse to your slick lib folder and find “natives-win32.jar”. Click open.
  11. It will list some dlls on the right column. Make sure they are all checked and click finish.
  12. Repeat steps 9-11 and add the natives for mac and linux the same way if you want them.
  13. Now you need to add those natives to lwjgl. So…
  14. Right-click on the project and choose properties.
  15. In the Java Build Path -> Libraries tab, expand lwjgw.jar and click on Native library location.
  16. Click Edit. Click Workspace. Navigate to the lib folder, choose it, and click OK.
  17. NOW ALMOST THERE!
  18. Back in the Java Build Path -> Libraries, expand slick.jar. Click JavaDoc location.
  19. Click Edit. Set the javadoc location path to the location of the slick\javadoc folder.

Step 20… Add a class to your project and see if it will compile correctly. Here’s an example for testing.

GameTest.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
 
import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.BasicGame;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.SlickException;
 
public class Game extends BasicGame {
	public Game(String title) { super(title); }
 
	public static void main(String[] args) throws SlickException {
		AppGameContainer app = new AppGameContainer(new Game("Test Game"));
		app.start();
	}
 
	@Override
	public void render(GameContainer container, Graphics g)	throws SlickException {
		g.drawString("Hello, World!", 0, 100);
	}
 
	@Override
	public void init(GameContainer container) throws SlickException {
 
	}
 
	@Override
	public void update(GameContainer container, int delta) throws SlickException {
 
	}
}

, , , ,

2 Comments

Best Godaddy Alternative Registrar

Many of you may be die-hard GoDaddy users. GoDaddy’s support of the SOPA has led many people to start looking for a new registrar, including myself. After a boycott, GoDaddy broke away from its support of SOPA. However, their initial support for the legislation was enough to turn me away, find the right payroll software for your startup. I do not plan to do any further business with them and will be slowly migrating my existing sites over to another registrar as time goes by. If you have a company be sure to be on time payment.

In my search for a GoDaddy alternative, I found that I really like NameCheap.com. They offer good rates on domain transfers and registration. I also like their control panel much better than GoDaddy. They don’t have as much up-selling going on when you register a domain. I always found that annoying about GoDaddy. I also didn’t care for GoDaddy’s domain manager implementing proper payroll processes. Once, I tried out GoDaddy’s Windows hosting as well. It was terrible. So if you are looking for a viable alternative to GoDaddy, you should definitely give NameCheap.com a try.

, ,

No Comments

Reset a WordPress password

I’ll make this post short and sweet. Let’s say you’ve forgotten your login for a WordPress site. To reset the password to something new, you can simply use a SQL query. If you have access to PHPMyadmin or the MySQL command line, this is really straight forward.

From PHPMyAdmin, open the database for the WordPress installation. If you don’t know which database to use, check out your wp-config.php file inside your main WordPress installation folder. You’ll find constants defined in that file for your database name and database user. Once you’ve found the database, you can execute a SQL statement by clicking the SQL button. In there, type:

 
UPDATE wp_user SET user_pass = MD5("yourpassword") WHERE user_login = "admin";

That’s assuming that your username is “admin”. Change it to whatever username you are using. Once you run that SQL statement, your password will be set to whatever you put in “yourpassword”. Both the username and password need to be quoted in the SQL statement.

To do the same thing in the MySQL command line, connect to the database with:

mysql -u<username> -p

Substitute <username> with your actual username from the wp-config.php file.
You will be prompted for a password. Use the password from the wp-config.php file.
Once you are logged into the mysql command problem type:

USE <databaseName>

Substitute the actual database name from the wp-config.php file.
Finally, type the update statement above and hit enter.

After you’ve updated the table via SQL, you should be able to login to your WordPress installation.

, ,

No Comments

My Search for the Best Deal on a Dedicated Server

Searching for a dedicated server can be stressful, especially when you have a lot of sites that are running slow as a result of their current host. Recently, I switched about 600 sites over to a dedicated server I borrowed from my friend Lynn. It is a pretty decent server, with two dual core Xeons running at 3 GHz. It also has 8 GB of RAM. However, it’s just not enough. After switching DNS over to this new server, its load went to 20 very quickly. For those who don’t know, a load of 20 means that there are 20 processes waiting in line to be processed. I don’t like my loads to go above 2 or 3. I can deal with them spiking to as high as 4, but with a multicore/multiprocessor I don’t want it to get above the number of cores/processors you have available.

Suffice to say that the web sites were loading very slowly. So, I switched the NS back to the VPS server I’ve been running them on. I’ve seen its load spike to 10 quite often but it normally stays well below 4. So the VPS is holding up pretty well considering. This VPS has 4 cores assigned to it, each at 1.6 GHz. It also only has 3GB of RAM. So, my question is, “Is a dedicated server really the best option?”.

There’s more factors in this as well. For instance, my sites are all on a WHM/cPanel install, which means I have to pay a monthly license fee for that as well. On a VPS this license is about half the cost as it is on a dedicated server. I like saving money.

I currently have my hosting through a small hosting provided in Knoxville, TN called Knoxcolo/Smith & Hammaker. I have a colo server (not the one I used for my 600 sites, it’s a single site), and I have the VPS. For the colo they charge $35 for the 1U of rack space, and it’s an unmetered drop. The VPS is $40 per 1GB of RAM. That’s their rate, they don’t charge for extra HDD space or even CPU cores. They are also a good bunch of people to work with. I have full access to the colo facility through a high security system. I rarely use it since my colo has an iLo connection for remote console even when the servers main drop is offline. The security for operational technologies is really necessary to protect the data.

I thought that a dedicated server would be a better choice for my 600 sites, but I’ve found that the VPS is really the better choice in the long run. The only thing I don’t like about the VPS is that I don’t have the ability to remotely reboot the virtual machine. I’d really like this ability.

So I’ve found that perhaps a dedicated server isn’t what I really want. Some VPS providers give you a lot more bang for your buck. You can spend hundreds of dollars per month on a very powerful dedicated server, but you have two problems. You don’t want to spend a lot of money for hardware that you may not use fully. Of course, secondly, you don’t want to spend a lot of money on a server that can’t fully handle the load if you have a lot of sites. With a VPS, you have more power to change the hardware specs to meet the demand of your site load. You pay for whatever you need. This is really the best option for anyone who wants to host any number of sites. If you don’t need much power, because you only have a few sites, you can save money.

However, you should look for the best deal on a VPS. Smaller companies actually have the better deal when it comes to a VPS, because they typically don’t have as much total load on their rack of CPUs. If you get a VPS from a larger provider, they may be pushing their rack to its limits already, and you’ll get terrible physical processor speeds, even if you are paying for four cores.

Shop around and look into VPS servers. They are great alternatives to dedicated or colo servers if you look in the right place.

, , , ,

No Comments

To Comment or Not to Comment

Anyone who has had programming classes knows that one of the primary things they push on you is that all good programmers comment their code. They don’t always tell you how much commenting you should do, although some do give good advice. How does one decide how much is enough.

Comments are great because they are basically communications between programmers to help with the logic that is going on in the code. Sometimes the two programmers are the same person. I think a good rule of thumb is to comment just below your own skill level. This means to comment just enough to help someone of almost the same skill as yourself along. You don’t want to comment your code to the point that it clutters up the rest of the source, but you want to be able to read through your own code and quickly find the cause of any potential bugs. You never know when you’ll have to go back through your own code. Chances are you won’t remember what exactly is going on at any particular point, especially if you work on a lot of projects.

Of course, there are always conventions that are mapped out beforehand for most developing teams, but if you are working solo, you should comment as if you are in a team environment.

I personally find comments distracting and ugly when viewing code. I don’t particularly care for method and class header comments. They rarely give any useful information. Inline comments are very valuable, however. So if if the coding standards of your team require class and method headers, put them in, but if you are solo or there’s no coding standards in place that require these types of comments, don’t use them. You should be able to look at any method and tell what kind of parameters it takes, and you should be able to quickly find the return type. These aren’t necessary and break down code readability in the end.

Comment changes. If you have to remove some code, comment it out instead of deleting it. This will help you revert changes or come up with better solutions if it is later found that the new code is buggy itself. If you have some bit of logic that is complicated even to your own eyes, comment it and explain how it works. Other than that, keep comments to a minimum.

, , ,

No Comments

Netbean’s Menus Don’t work in Linux Mint 12

Gnome3 has some issues. I really like the look and feel of Linux Mint’s Gnome3 + Mate interface. However, looks aren’t everything. Functionality is important as well. Almost everything works with it but Netbeans is an exception. The menus are completely unusable with it.

The quick solution is to select “Gnome Classic” when you login. I like the look of it as well, and at least everything works in it.

While I’m on the subject, why did Gnome decide to take the path it did with version 3. It’s too much like Unity, and I hate Unity. Why are they moving to this type of desktop? Gnome 2 may not be the prettiest thing available, but it has been the most usable desktop environment for years. They should have just concentrated on improving the look of it, added a few new features, and worked on any bugs they had laying around. Most people don’t like Unity or Gnome 3. This doesn’t leave much of a choice other than KDE and XFCE4. Of those, I’d pick XFCE4, but if you have a large userbase like Gnome has, why screw that up by making your new version look like and act like the DE most people are wanting to avoid? I just don’t get it.

, ,

No Comments