Tuesday, May 31, 2011

Ext Js Login Sample



This is a simple login application using PHP and ExtJs. I used to master ExtJs but since I shifted to Java, some of the knowledge I acquired has gone away. Instead of forgetting all of it, which I tend to, I chose to post them here so I can remember them when they will be needed.

What to do?

1. Create a php file for the view section. I've named it authenticateView.php



<div style="height:300px;width: 500px;">
    <div id="login-panel">

    </div>
</div>
2. Created a javascript file which I named it authenticate.js.
Ext.onReady(function(){
    Ext.QuickTips.init();

   new Ext.Panel({
       id           : "ext-panel",
       renderTo     : "login-panel",
       bodyStyle    : "background-color:aliceblue;",
       height       : 250,
       width        : 500,
       items        : [
           new Ext.FormPanel({
                id      : "login-form",
                bodyStyle : "background-color:transparent",
                style   : {
                    'padding-top': 80
                },
                border  : false,
                height  : 180,
                width   : 370,
                monitorValid : true,
                items   : [
                    new Ext.form.TextField({
                        id          : 'username',
                        name        : 'username',
                        fieldLabel  : 'Username',
                        allowBlank  : false,
                        blankText   : 'Username is required.',
                        msgTarget   : 'side',
                        width       : 200
                    }),
                    new Ext.form.TextField({
                        id          : 'password',
                        name        : 'password',
                        inputType   : 'password',
                        fieldLabel  : 'Password',
                        blankText   : 'Password is required.',
                        allowBlank  : false,
                        msgTarget   : 'side',
                        width       : 200
                    })
                ],
                buttons:[
                    {
                       text : 'Login',
                       handler : function(){
                           authenticate(Ext.getCmp('username').getValue(),Ext.getCmp('password').getValue())
                       }
                    },
                    {
                       text : 'Reset',
                       handler : function(){
                           Ext.getCmp('login-form').getForm().reset();
                       }
                    }
                ]
           })
       ]
   })
})

function authenticate(u,p){
    var dataPanel = Ext.getCmp('ext-panel');
    Ext.Ajax.on('beforerequest',function(conn,o,result){
        dataPanel.getEl().mask('Authenticating...','x-mask-loading');
    })

    Ext.Ajax.on('requestcomplete',function(conn,o,result){
        dataPanel.getEl().unmask(true);
    })

    Ext.Ajax.on('requestexception',function(conn,o,result){
        dataPanel.getEl().unmask(true);
        Ext.MessageBox.show({
            title   : 'Message',
            msg     : '<div style="margin-top:5px;text-align:center;color:red;">Server Error</div>',
            width   : 300,
            buttons : Ext.MessageBox.OK,
            animEl  : 'ext-panel',
            iconCls : 'login-button-icon'
        });
    });

    Ext.Ajax.request({
        url : "index.php?page=login&action=authenticateScript&wp=0",
        method : "POST",
        params : {_password:p,_user:u},
        callback : function(options,success,result){
            var response = Ext.util.JSON.decode(result.responseText);
            if(!response.success){
                Ext.MessageBox.show({
                    title   : 'Message',
                    msg     : '<div style="margin-top:5px;text-align:center">' + response.error.reason + '</div>',
                    width   : 300,
                    buttons : Ext.MessageBox.OK,
                    animEl  : 'ext-panel',
                    iconCls : 'login-button-icon'
                });
            }else{
                Ext.MessageBox.show({
                    title   : 'Message',
                    msg     : '<div style="margin-top:5px;text-align:center">Login Successful</div>',
                    width   : 300,
                    buttons : Ext.MessageBox.OK,
                    animEl  : 'ext-panel',
                    iconCls : 'login-button-icon'
                });
            }
        }
    })
}

3. Created a Controller which I named it LoginController.php
<?php
class LoginController extends ActionController{
    
    function doAuthenticate(){
        $this->dynamicJs = "";
    }

    function doAuthenticateScript(){
        $message['success'] = false;

        $name = $_POST['_user'];
        $pass = $_POST['_password'];

        require_once 'application/model/login/LoginModel.php';

        $loginModel = new LoginModel();
        $loginModel->autheticateUser($name, $pass);

        if(!LoginModel::$SUCCESS){
            $message['error']['reason'] = LoginModel::$MESSAGE;
        }else{
            $message['success'] = true;
        }

        echo json_encode($message);
    }
}
?>

4. Created the model layer which I name it LoginModel.php
<?php

class LoginModel{

    public static $SUCCESS = false;
    public static $MESSAGE;


    function autheticateUser($user,$pass){
        if($user == 'admin'){
            if($pass == 'admin'){
                LoginModel::$SUCCESS = true;
            }else{
                LoginModel::$MESSAGE = "Password is invalid!";
            }
        }else{
            LoginModel::$MESSAGE = "Username is invalid!";
        }
    }
}
?>
5. Got a working login with with php and extjs.
When authenticating a user...

If username is invalid...
If password is invalid...

When login is succesfull...

I can share the code if you want to have it. Pop me an email at theredfont01@gmail.com

Learn More:

Monday, May 30, 2011

Best Potato Salad

Image From: http://eatocrazy.cnn.com

I'm not much on food though, however it is one of the sizzling hot topics on Google Trends so I got to share my piece. Constant googling landed me to this site which I may say that it is the most favorable article for those food lovers. This site includes the recipes and the steps on how to cook the best potato salad(?).

The figure above just show you how this deliciously looking potato salad looks like. Want to know the secrets? Read more...

Learn More:

Saturday, May 28, 2011

Customize CSS for Blogger



Blogger is so much flexible. It has so much to offer. Though it has its limitations, I'm sure it is still convenient to use specially for people who may want to begin blogging. Moreso, there are blogger help sites who offer very conservative solutions so complex situations. There are also blogger help forums which you can ask help and get answers real-time.

Though blogger templates are offered, sometimes we do not want to use the default. So we may want to consider some tweaks and alter the default template design to be favorable to us. Here, I'll show you a blogger hack to add a customize CSS to your page.
Go to the Design tab and click on Template Designer
Look for Advanced and Add CSS. You'll be able to add your customize CSS to the text area on the right side.
Sample CSS is shown below.

.customCSS{
 font-family: Calibri;
 color: red;
 font-weight: bold;
 opacity: 0.5;
} 

Add the customize CSS to any acceptable html tags.


Here is the result:

The style is a customize CSS.

Learn More:

Friday, May 27, 2011

Why Do Men Get Sleepy After Sex?



Most often than not, men get sleepy after sex. Why is this? Haven't you ask yet yourself or ever ponder upon. Haven't you ever wondered what facts of science lies beyond this reality?

One of my friends as me about this so I tried googling. Bet, I found an article that explains it. Here is what the article have to tell you.






"For many women, the correlation between sex and snoring is one of those annoying facts of life: no matter when passionate encounters occur, men always seem to fall asleep immediately afterwards. Dave Zinczenko, the author of Men, Love and Sex: The Complete User Guide For Women, explained the phenomenon to Huffington Post writer Arianna Huffington this way: “Men go to sleep because women don’t turn into a pizza.”

I doubt I am ever going to become a pizza, and I’ll never have the foresight to order one beforehand. So in lieu of a cure, a better explanation will have to do. Although women sometimes feel sleepy after sex, the phenomenon does seem more pronounced in men. What is it, then, that spirals them into the land of nod?

First, the obvious reasons for sex’s somnolent sway: the act frequently takes place at night, in a bed, and is, after all, physically exhausting (often more so for the man than the woman, although this certainly varies). So when sex is over, it’s natural for a guy to feel sleepy.

Secondly, research using positron emission tomography (PET) scans has shown that in order for a person to reach orgasm, a primary requirement is to let go of “all fear and anxiety.” Doing so also tends to be relaxing and might explain the tendency to snooze.



Then there is the biochemistry of the orgasm itself. Research shows that during ejaculation, men release a cocktail of brain chemicals, including norepinephrine, serotonin, oxytocin, vasopressin, nitric oxide (NO), and the hormone prolactin. The release of prolactin is linked to the feeling of sexual satisfaction, and it also mediates the “recovery time” that men are well aware of—the time a guy must wait before “giving it another go.” Studies have also shown that men deficient in prolactin have faster recovery times.

Prolactin levels are naturally higher during sleep, and animals injected with the chemical become tired immediately. This suggests a strong link between prolactin and sleep, so it’s likely that the hormone’s release during orgasm causes men to feel sleepy.

(Side note: prolactin also explains why men are sleepier after intercourse than after masturbation. For unknown reasons, intercourse orgasms release four times more prolactin than masturbatory orgasms, according to a recent study.)

Oxytocin and vasopressin, two other chemicals released during orgasm, are also associated with sleep. Their release frequently accompanies that of melatonin, the primary hormone that regulates our body clocks. Oxytocin is also thought to reduce stress levels, which again could lead to relaxation and sleepiness.

What about the evolutionary reasons for post-sex sleepiness? This is trickier to explain. Evolutionarily speaking, a man’s primary goal is to produce as many offspring as possible, and sleeping doesn’t exactly help in his quest. But perhaps since he cannot immediately run off with another woman anyway—damn that recovery time!—re-energizing himself via sleep may be the best use of his time.

And although there is conflicting information as to whether women feel sleepy after sex, a woman often falls asleep with the man anyway (or uses it for some key cuddling time), which is good news for him: it means she is not off finding another mate. When the man wakes up and she’s still there, he just might be ready to go again.

It’s also possible that sleepiness is just a “side effect” associated with a more evolutionarily important reason for the release of oxytocin and vasopressin. In addition to being associated with sleep, both chemicals are also intimately involved in what is called “pair bonding,” the social attachment human mates commonly share. The release of these brain chemicals during orgasm heightens feelings of bonding and trust between sexual partners, which may partially explain the link between sex and emotional attachment. This bond is favorable should the couple have a baby, as cooperative child rearing maximizes the young one’s chances for survival.

The bottom line is this: there are many potential biochemical and evolutionary reasons for post-sex sleepiness, some direct and some indirect—but no one has yet pinpointed the exact causes. One thing, however, is certain: we females better get used to it, because it doesn’t look likely to change anytime soon.

I will leave frustrated American women with one final thought: if you are upset at the ubiquity of the post-sex snoring phenomenon, remember that things could be a lot worse. A recent survey of 10,000 English men revealed that 48 percent actually fall asleep during sex."


Article Source: http://scienceline.org

Do you really feel exhausted after making love? I leave it for your reaction.

Learn More:

Thursday, May 26, 2011

Conflicting Technologies



It is so common to find that two technologies are substitutes of each another to accomplish certain process. Think of Apple vs. IBM PC, VHS vs. Betamax, front wheel vs. rear wheel drive cars, and so on. It is certain that one of the two methods will become the preferred one. Sometimes, the two methods keep on being used side by side for a long period of time. This gives the impression that one process will never be superseded by the other. Such reading is usually erroneous and often very costly. If consumers have similar access to both methods (in terms of price, distribution and service) , and both methods accomplish the same task, the method that is more cost effective will attract more customers, lower its cost through economies of scale, and push the other method out of the market. In determining which technology is more cost effective, one must distinguish technological efficiency (i.e. physical performance), and consumer preference (i.e. convenience of usage). It is the latter that is determinant.

Take for instance, Betamax that was recognized as technologically superior to VHS. Yet, it is VHS that consumers liked better eventually, possibly because there were more VHS VCR's, and cassettes could be exchanged between users. Another example is that of floppy disks. The three and a half disk format pushed the five and quarter format out of the market because the latter had an open exposed area that users were afraid to touch, even though the five and a quarter format was much cheaper and could hold almost the same amount of data. The exception that confirms the rule is that of Apple computers that offered a MacIntosh visual (i.e. on screen mouse controlled) operating system that users liked better than DOS, and that Microsoft duplicated in its Windows operating systems. MacIntosh continues to survive because it has become Windows compatible, while retaining advantages of its own operating system.

One may note that in many cases the successful technology is not necessarily the one of the company that is considered the technology leader in the industry. Sony is and has been considered the technology leader in electronics, and the failure of its Betamax format was its most bitter failure. Likewise in the PC industry where IBM format became the most widely used technology, IBM itself pulled out of the PC market because it was underpriced by competitors.

Source: http://www.peoi.org

Learn More:

Tuesday, May 24, 2011

VB6 Stinks



Ok, so I am a developer / programmer / software engineer. Choose a name. It doesn't matter to me as long as the paycheck clears! Some people I know get very bent out of shape over titles.

Anyway, I am a hardcore fan of Java(C++, C#, C, etc.). I am not a BIG fan of 'Basic'(VB,Delphi etc.) style language. I'm with Object-Oriented Programming. Why? I dunno. I guess, I have already incorporated the best programming practices. OOP is clean and readable. They are explainable because you associate your code to an object. It is very maintainable and easy to fix. Not like the "pain in the ass" VB6 (sorry VB6 die hard fans!). Most probably, you are getting more pissed with this reactions on VB6.

  • VB code looks ugly. Ugly, ugly, ugly...
  • Visual basic is like programming with your eyes poked out. Even the editor sux - always interrupting you by making stupid assumptions about what you're typing. Set Dim Yuk. More words that contribute nothing.
  • if (your_programskill is Nothing) then Goto VisualBasic
  • Not only is it a programming language for horrible programmers, it also does a horrible job at doing so! There is SO much more power, speed, and cross-platform compatibility that can be harnessed with languages such as Python, if only people could learn JUST a bit more...no, I'm not talking about IronPython.
  • Visual Basic produces sh***y programmers.

As for my own experience, VB6 is boring. Is not worth of the time studying. Moreover, I don't to be labeled as DRAG ADDICT. DRAG that Form now!

Learn More:

Vista Internal Video That Makes me Laugh

Centering JFrame To Any Screen Size



You have adjusted the location of your application so that is stays right at the center of your screen on load. It looks good and works perfectly fine however, when it is deployed to other computer, you have discovered that it does not stay at the center of the screen but at the bottom. You tried another computer screen and it stays at the top when loaded. That's probably horrible.

You have to address certain situations where it is out of your control. This variable changes as the end users uses different sizes of screen. This is the objective of this discussion actually. To create a Java Frame that stays at the center of any screen at any given size.

Java has a lot of API's that can be abused to create a better application.  By using the AWT Toolkit, you're done. With it, getting the screen size is a lot easier nowadays. Armed with simple mathematical computations, then you're ready to go.

Given samples below will show you how to compute the x and y values that will be used to position the window application.
Size of the screen:
height = 2000
width = 2100

Size of your application:
height = 200
width = 300

get the x and y positions:
y = ((height of the screen /2) - (height of the window/2))
= (2000/2) - (200/2)
x = ((width of the screen/2) - (width of the application/2))
= (2100/2) - (300/2))

Actually we don't really know the screen size so translating that to java code, we have this:

/*
 * @author: theredfont
 */
package com.javaswing;

import javax.swing.JFrame;
import javax.swing.SwingUtilities;

public class JavaSwing implements Runnable{
 
 private JFrame frame;
 
 public JavaSwing(){
  this.init();
 }
 public void init(){  
  frame = new JFrame("Screen Centered Frame");
  frame.setSize(300, 300);
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 }
 
 @Override
 public void run() {
  frame.setVisible(true);     
 }
 public static void main(String []argv){
  Runnable runnable = new JavaSwing();  
  SwingUtilities.invokeLater(runnable);
 }
}


We created a JFrame using the code above. The above is a working code. When the code is executed, the frame stays at the right most top corner of the screen. To make it stay at the center, follow the code below.
/*
 * @author: theredfont
 */
package com.javaswing;

import javax.swing.JFrame;
import javax.swing.SwingUtilities;

import java.awt.Toolkit;

public class JavaSwing implements Runnable{
 
 private JFrame frame;
 
 Toolkit toolkit;
 public JavaSwing(){
  this.init();
 }
 public void init(){
  toolkit = Toolkit.getDefaultToolkit();   
  frame = new JFrame("Screen Centered Frame");
  frame.setSize(300, 300);
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  this.setLocation();
 }
 
 public void setLocation(){
  int screenX = toolkit.getScreenSize().width;
  int screenY = toolkit.getScreenSize().height;
  int x = ((screenX/2) - (frame.getWidth())/2);
  int y = ((screenY/2) - (frame.getHeight())/2);
  frame.setLocation(x, y);
 }
 @Override
 public void run() {  
  frame.setVisible(true);    
 }
 public static void main(String []argv){
  Runnable runnable = new JavaSwing();  
  SwingUtilities.invokeLater(runnable);
 }
}



You can see the code changes on the above.

Learn More:

Monday, May 23, 2011

Level Up with FATE



Ever played dungeons and dragons online? This game is liken to it. It is an adventure game wherein you have to complete certain tasks at certain level. This game brings so much fun. OK, let start the fun. Let's rock!

After many days of travel, you've reached the forest town of Grove. On the outskirts of town, and once inside the fiery dungeon gates, you'll find fame, adventure and fortune. Get tips from townspeople and acquire power with unique weaponry and magic spells. Your invincible pet defends you against monsters that lurk within dark, dangerous corridors. Determine your FATE with unlimited replay and countless levels in this superb dungeon-crawling RPG!


Details
Game Developer/Publisher:
WildTangent
Categories:
Adventure, Explore, Enthusiast, Roleplaying
Release Date:
5/18/2005


System Requirements
  • Processor: Pentium - 800MHz or better
  • RAM: 256MB
  • Video Card RAM: 16MB, 3D hardware acceleration required
  • DirectX Version: 8.0 or above
  • Keyboard and Mouse: Supported
  • Operating System: Windows 7, Vista, and XP
The Game is ON!. The FATE is in your hands.

FREE TO DOWNLOAD HERE

Learn More:

MySQL Password Reset



Forgetting the root MySQL password is a nuisance especially if the data has been contained into it. If you were in that situation, don't worry, I'm here to the rescue. Just follow the instructions below and your good to go.

1. Log in as an Admin to your system.

2. Stop mysql service. You can do this by opening your command prompt and type 'net stop mysql' then press enter. You can also type services.msc in the Run, look for MySQL in the services and stop the service.

3. Create a text file. The file should contain the following:

UPDATE mysql.user SET Password=PASSWORD('MyNewPass') WHERE User='root';
FLUSH PRIVILEGES;

4. Save the file to drive c:\ with the filename mysql-init.txt (actually, any filename should do).

5. Start MySQL service using the command below:
        c:\mysql\bin\mysqld-nt --init-file=c:\mysql-init.txt
        Note* Remember to change (c:\mysql) to the actual root where you have your MySQL installed.

6.  You must be able to start your MySQL with the new password. Execute this command in the command   prompt: mysql -u root -p then press enter. Supply the new password and your done.

Learn More:

Sunday, May 22, 2011

Catholic Arguments against RH Bill are Spiritually Backward and Misinformed





Religion and darkness... do they sometimes mix?











House Bill No. 5043, also called the RH or Reproductive Health Bill, is probably the first bill to address the overpopulation problem of the Philippines. It requires the provision of sex education as well as reproductive health services to the general populace. While this response may be a bit late, and the RH Bill is not prominent on the controversy radar, it is still relevant as the bill has not yet been passed and it continues to raise a storm of controversy, especially from the Catholic church.
I will focus on one prominent response from a Catholic entity because of how it alarmed me. Fr. Bing Arellano, spiritual director of the Alliance of the Holy Family International, posted a video response on Youtube stating why the RH Bill should be opposed. The video can be found here:

Fr. Arellano on the RH Bill:

I believe each point he made deserved strong refutation, because those points are based on biased, poorly informed views and could do harm, despite the good intentions.
First, Fr. Arellano refutes the RH Bill’s two-child policy. He says the ideal family is from 5 to 7 children. Now this is only an opinion of a person, and for the church to dictate the ideal size of a family reflects an imperialistic attitude. Looking at it factually, 5 to 7 children is hardly ideal; it is more likely to put more children into poverty, given the economic condition of many families today. But the killer is this; nowhere does the RH Bill enforce a 2-child policy! It encourages two children, but “attaining the ideal family size is neither mandatory nor compulsory..... READ MORE

Source: ChinoF, http://antipinoy.com




Other Stuff You Want To Look At