October 2007 - Posts
I've been looking this morning for a WYSIWYG editor to integrate with one of the personal projects I'm planning to make. It's going to be a WIKI that would allow anyone in my team to add, edit, view or search entries for best known knowledge. I'm planning on proposing the app to them a day or two before I leave the company. I also wanted to test the PHP MVC framework(Just an ambitious thought) that I am working on (somehow patterned after the Servlet and JSP technology, though not 100%). Anyway, I wanted a WYSIWYG editor similar to what we have here in devpinoy. It's good that I found TinyMCE . Though I haven't tried it yet, I am quite satisfied with the demo that I've seen in their website. Here's a little info about TinyMCE from their website:
What is TinyMCE?
TinyMCE is a platform independent web based Javascript HTML WYSIWYG editor control released as Open Source under LGPL by Moxiecode Systems AB.
It has the ability to convert HTML TEXTAREA fields or other HTML
elements to editor instances. TinyMCE is very easy to integrate into
other Content Management Systems.
This might not be something new to a typical web developer. But nonetheless, this should be very exciting to integrate with my app! 
If you have any other suggestions that are also free/opensource then I'd be glad to take a look at it.
In my previous company I have developed an online recruitment system in Struts framework. Have I ever mentioned why I prefer working in a team? It's because it's easier for other to point out your mistake. And because I am a self-taught, self-proclaimed Struts user and a lone developer during that time, it wasn't very easy to know what I was doing wrong.
So what did I do wrong?
Eventhough the app was working completely fine, I made my model classes extend ActionForm. I just found out that this is very very very bad! ActionForm classes should only have to do with your HTML form(To get data from a form and to validate) and not your model classes. You model classes, as much as possible, should be POJOs. But well, the app did work. I'll be sure to remember this the next time I use struts.
This realization came to me when I examined the code in Head First Servlets and JSP's Struts Beer App when I finally decided to read the book(seriously) after 2 years. Lolz!
While I was trying to implement MVC in PHP, It came to me how I would be able to secure my code (i.e. prevent HTTP GET access to some parts). My friend who is a PHP programmer forgot that in some webserver, the .inc extension is not configured as a MIME type for PHP. Good thing I told him about that. Other than this, I related to my experience in J2EE Web Containers where everything in the WEB-INF directory is restricted from external access.
In Apache Webserver, I know that it's possible to restrict some parts of your app's directory. I'm not entirely sure if that would include direct access to files like
www.myapp.com/forbiddendirectory/ <---Might be possible to protect directory listing
www.myapp.com/forbiddendirectory/myunsecurescript.php <--- I don't know if possible to secure through Server configuration
I didn't want to take any chances so I confided with my friend if he knew such solution. He showed me JOOMLA's security feature where every code(?) has this line written(looks something like this):
<?php defined('SECURE_FILES') or die("Access denied"); ?>
And in the main page(index), something like this is defined
<?php define('SECURE_FILE', 1); ?>
it's a good thing for me because I only have index.php as the main point of entry to all requests (ala Front Controller). Thus, all access to my PHP classes are restricted w/out going through index.php first.
I've been thinking my whole career through what the Levels of Data Normalization means. I know I've been doing it, but I didn't know on which level I am at during this process. I had a discussion with an office colleague and he told me to follow the standards, i.e., up to the 3rd level of normalization. But I didn't know what that it meant! I know this is discussed way back in College but for some reason, I couldn't remember if it was indeed taught to us by our teacher.
So I researched the internet and came up with this link here.
An excerpt from the link:
Disclaimer: The writer is a dummy in bit shifting and therefore this post does not come with any warranty of replacing your job if you replace all the business calculations in your system with the methods mentioned here.
The below examples only work for int, byte, short and not on floating point values.
You may have read about bit shifting somewhere. Or perhaps your Highschool or College teacher taught this to you or you learned it on your own. But where you able to apply it in real-world situations? In most cases, the purpose of bit shifting is to improve performance. Let's look at the two most common operators
>> - The Right shift operator
<< - The Left shift operator
In applications where performance is critical, you don't only have to optimize your algorithm. You also have to optimize your code. When building a game for example, how would you code the player's speed times two? Probably like this...
player_speed *= 2;
There's nothing wrong with that. Besides, it helps readability of your code. But we can optimize it more
player_speed = player_speed << 1;
What's my basis? Well... I just know that the right shift and left shift operators are low-level operators, that's all.
You might wonder why I right shifted with 1 there. If you remember the number systems and what each bit in the binary system represents, you'll get the idea
128 64 32 16 8 4 2 1
Now, assuming player_speed is initially 4
player_speed = player_speed << 2 //this would equal 16
do you now get the idea? Here's a more detailed diagram
----------------------------------------
(7) (6) (5) (4) (3) (2) (1) (0)
128 64 32 16 8 4 2 1
----------------------------------------
128 - 7
64 - 6
32 - 5
16 - 4
8 - 3
4 - 2
2 - 1
1 - 0
----------------------------------------
So if you want to multiply by 2, you only have to remember that table above and see that to achieve the same result of multiplying a number by 2 using the multiplication operator can also be achieved using the left shift operator and that the integer literal 1 would yield the result of times two.
Use left shift(<<) if you want to perform multiplication and right shift(>>) for division.
Java Sample
public class Main {
/** Creates a new instance of Main */
public Main() {
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
int bitShift = 4 << 1;
System.out.println("Left shift by 1: " + bitShift);
bitShift = bitShift >> 1;
System.out.println("Right shift by 1: " + bitShift);
}
}
For more detailed tutorials on bit shifting. Visit these links
http://www.javaranch.com/journal/200406/Journal200406.jsp
http://www.javaranch.com/campfire/StoryBits.jsp