Archive for July, 2013
If you need to secure every method of a Codeigniter controller, you can do it with one line instead of checking the session in every method before doing anything else. In the constructor of the controller simply check that $this->router->fetch_method is not equal to your login method and that a user isn't logged in. If you meet both of these criteria, redirect to the login method.
We bought an Emerson Ice maker about two years ago because the built-in ice maker in our freezer stopped working, and I'm a huge consumer of ice. So, I wanted a dedicated ice maker. It worked well for a few months. Then it decided that it didn't want to make ice. I should have sent it back but I decided to tear it apart and try to fix it. I wasn't able to really get anywhere with it. So, I put it back together and plugged it back up and miraculously enough it started working again.
Since then, I discovered why it was failing to make ice. I post this because there may be someone else out there with the same problem from their Emerson Ice Maker.
The problem I have stems from the 120mm exhaust fan used in this device. I'm no expert on refrigeration, but I think this fan has to be running in order for the thing to make ice correct. It puts out a lot of heat. With my very basic knowledge of thermal dynamics, I'm assuming that this is how the ice is made. It removes the heat, thus reducing temperature and creating ice.
This fan is the exact fan used in a lot of computers. So if it isn't running, you may need to replace it. However, I took a shortcut that seems to have worked, a little trick I've learned from working on computers. You can give it a try if you want. It's pretty simple.
The fan has a sticker in the center. This should have some sort of logo on it, but it also has a second purpose. It holds a little rubber cap in place. Under that cap are the bearings for the fan. If you oil the bearings and replace this sticker, the fan may start to work again. You can get to the fan by removing the cover. I won't go into details here how to do that, because I don't have enough time to write the detailed instructions. It's pretty easy to do. In my case the fan grill was almost broken completely out. So, I just finished it off for easy access to the fan.
"What can you use to oil the bearings", you may ask. I used baby oil, because it's basically mineral oil with a little fragrance. You can use mineral oil and there are some actual products that are made for greasing fan bearings. There are a ton of videos on Youtube on how to do this to a regular computer fan.
I hope this helps. If it does, leave a comment! I like to hear when I help.
So, I am creating a simple multi-threaded game server (generic client/server) app in Java. I ran into a problem with threading that I thought I would post about. It may help someone else save a few hours of their time.
I have a class called TCPServer which implements Runnable (used for Java threading) and serves as a socket listener for my server. It waits for connections and then adds those connections to a connection manager. Each connection starts its own thread. The thing about threads is that they are easy to make, but melt my mind when it comes to managing them correctly. I thought I had a good handle on it. I did actually, but it made me think I was crazy for a few hours none-the-less.
So in my main class I have a command that starts the TCPServer. It creates a new one and then in the constructor, I start the thread. Well, as you may know, Thread.stop() is a deprecated and shunned method. Don't use it. I thought I was going to have to, but I forced myself to find the real reason for my issue.
Let me discuss the issue. The thread starts and a while loop checks a variable called receivingConnections. Theoretically, if this variable is set to false, it should break out of the thread and everything should be hunky dorey. I created a stop method which set this variable to false and then closed the ServerSocket.
Here's where the fun began. When I issued the command to execute the stop method, I kept getting a "socket closed" exception. This was being caught on the accept() method of ServerSocket. I couldn't figure out why it was throwing the exception. The socket was closed, true... but why did it keep trying to use the accept() method after the socket is closed.
I thought that it was due to the receivingConnections variable not being volatile. I changed this but still ran into the same issue.
The answer is rather crazy. You see, ServerSocket's accept() method just waits for a connection. The while loop that it was in was just stalled waiting on a new connection. Closing the socket triggered the exception. Even though right before the accept() method was called, I was checking if the socket was closed. My guess is that the accept() method simply starts its own infinite loop and waits on the new connection. As far as I can see, there's no way to break out of that.
The solution... set your flag variable to false. In my case it was the receivingConnections variable. Create a new client socket connection to the server and close it immediately. Then you can safely close the ServerSocket. This fools the accept() method, which forces an iteration of your while loop, which sees that your flag is now false, breaking out of the loop.