Pages

Friday, January 29, 2010

Ruby - Can't install gems on Leopard

After installing Mac OS X Leopard on my MacBook, I'm unable to install gems on my machine. I need to update the system.


sudo gem update --system


After this command, I'm able to install gems without errors.

Tuesday, January 26, 2010

MacOS X -=- Show / Hide Hidden Files

Hi!

By default, Mac OS X hides hidden files in Finder. To show hidden files in Finder, open a terminal and types.

defaults write com.apple.finder AppleShowAllFiles TRUE
killall Finder


If you want to hide hidden file, replace the TRUE for FALSE in the preceding command.

MacOS X - French Canadian Keyboard Layout

Hi!

For those like me who need the French Canadian keyboard layout for your Mac, you should have noticed that Apple's French Canadian keyboard layout is not like the keyboard layout that we use in Qu├ębec. If you want this keyboard layout, you can download it here:

MacOSX_ClavierCanadienFrancais.zip

Monday, January 25, 2010

SSH Port Forwarding in 30 seconds

For those who want to access data behind a firewall, you can forward remote port onto a local port on your machine. For example, we want to forward the port 80 for abc.com to your localhost on port 8088. The only command you have to type is
ssh -L 8088:abc.com:80 user@abc.com
  • 8088 is the local port on your computer
  • abc.com is the distant host
  • 80 is the distant port to forward
  • user@abc.com is the credential used to log onto the host

SSH Login without password

In order to log from host A onto host B without a password, you need to add the RSA key from host A into the trusted key list of host B. In order to do that, follow theses steps:
  1. Create RSA Key as a user. Don't enter any passphrase. The generated public key will be stored in HOME/.ssh/id_rsa.pub
    ssh-keygen -t rsa
  2. Create on host B .ssh folder
    mkdir ~/.ssh
  3. Export RSA public key to host B with this command on host A
    cat .ssh/id_rsa.pub | ssh b@B 'cat >> .ssh/authorized_keys'
  4. Be sure that the permission are 700. You can this command to set permission
    chmod -R 700 ~/.ssh

ExtJS -=- Disabling FormPanel submit if validation fails

To disable the FormPanel’s submit button if the validation fails (example like allowBlank:false). You will need to set the FormPanel’s monitorValid to true and the submit button’s formBind to true.


var form=new Ext.form.FormPanel{
monitorValid:true,
items:[{
name:"testing",
xtype:'textfield',
fieldLabel:'Test',
allowBlank:false,   //Must be filled in
value:''            //Set the value so that the validation will trigger
}],
buttons:[{
text:'Submit',
formBind:true   //If validation fails disable the button
}
]
}

ExtJS -=- Validation Types Collection

Hi!

Here's a collection of validation types very useful for fields in ExtJS. You just have to put this code in a JavaScript file, include it, and use the validation type by setting the property

vtype: "VTYPE_NAME"




Ext.form.VTypes["dollar"] = /^[\$]?[\d]*(.[\d]{2})?$/;
Ext.form.VTypes["dollarMask"] = /[\d\$.]/;
Ext.form.VTypes["dollarText"] = 'Not a valid dollar amount.  Must be in the format "$123.45" ($ symbol and cents optional).';


Ext.form.VTypes["time"] = /^([1-9]|1[0-9]):([0-5][0-9])(\s[a|p]m)$/i;
Ext.form.VTypes["timeMask"] = /[\d\s:amp]/i;
Ext.form.VTypes["timeText"] = 'Not a valid time.  Must be in the format "12:34 PM".';
 

Ext.form.VTypes["phone"] = /^(\d{3}[-]?){1,2}(\d{4})$/;
Ext.form.VTypes["phoneMask"] = /[\d-]/;
Ext.form.VTypes["phoneText"] = 'Not a valid phone number.  Must be in the format 123-4567 or 123-456-7890 (dashes optional)';


Ext.form.VTypes["hostnameVal1"] = /^[a-zA-Z][-.a-zA-Z0-9]{0,254}$/;
Ext.form.VTypes["hostnameVal2"] = /^[a-zA-Z]([-a-zA-Z0-9]{0,61}[a-zA-Z0-9]){0,1}([.][a-zA-Z]([-a-zA-Z0-9]{0,61}[a-zA-Z0-9]){0,1}){0,}$/;
 

Ext.form.VTypes["ipVal"] = /^([1-9][0-9]{0,1}|1[013-9][0-9]|12[0-689]|2[01][0-9]|22[0-3])([.]([1-9]{0,1}[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])){2}[.]([1-9][0-9]{0,1}|1[0-9]{2}|2[0-4][0-9]|25[0-4])$/;



Ext.form.VTypes["netmaskVal"] = /^(128|192|224|24[08]|25[245].0.0.0)|(255.(0|128|192|224|24[08]|25[245]).0.0)|(255.255.(0|128|192|224|24[08]|25[245]).0)|(255.255.255.(0|128|192|224|24[08]|252))$/;



Ext.form.VTypes["portVal"] = /^(0|[1-9][0-9]{0,3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])$/;


Ext.form.VTypes["multicastVal"] = /^((22[5-9]|23[0-9])([.](0|[1-9][0-9]{0,1}|1[0-9]{2}|2[0-4][0-9]|25[0-5])){3})|(224[.]([1-9][0-9]{0,1}|1[0-9]{2}|2[0-4][0-9]|25[0-5])([.](0|[1-9][0-9]{0,1}|1[0-9]{2}|2[0-4][0-9]|25[0-5])){2})|(224[.]0[.]([1-9][0-9]{0,1}|1[0-9]{2}|2[0-4][0-9]|25[0-5])([.](0|[1-9][0-9]{0,1}|1[0-9]{2}|2[0-4][0-9]|25[0-5])))$/;


Ext.form.VTypes["usernameVal"] = /^[a-zA-Z][-_.a-zA-Z0-9]{0,30}$/;
Ext.form.VTypes["passwordVal1"] = /^.{6,31}$/;
Ext.form.VTypes["passwordVal2"] = /[^a-zA-Z].*[^a-zA-Z]/;

Ext.form.VTypes["hostname"] = function(v) {
if (!Ext.form.VTypes["hostnameVal1"].test(v)) {
Ext.form.VTypes["hostnameText"] = "Must begin with a letter and not exceed 255 characters"
return false;
}
Ext.form.VTypes["hostnameText"] = "L[.L][.L][.L][...] where L begins with a letter, ends with a letter or number, and does not exceed 63 characters";
return Ext.form.VTypes["hostnameVal2"].test(v);
}
Ext.form.VTypes["hostnameText"] = "Invalid Hostname"
Ext.form.VTypes["hostnameMask"] = /[-.a-zA-Z0-9]/;
Ext.form.VTypes["ip"] = function(v) {
return Ext.form.VTypes["ipVal"].test(v);
}


Ext.form.VTypes["ipText"] = "1.0.0.1 - 223.255.255.254 excluding 127.x.x.x"
Ext.form.VTypes["ipMask"] = /[.0-9]/;



Ext.form.VTypes["netmask"] = function(v) {
return Ext.form.VTypes["netmaskVal"].test(v);
}
Ext.form.VTypes["netmaskText"] = "128.0.0.0 - 255.255.255.252"
Ext.form.VTypes["netmaskMask"] = /[.0-9]/;



Ext.form.VTypes["port"] = function(v) {
return Ext.form.VTypes["portVal"].test(v);
}
Ext.form.VTypes["portText"] = "0 - 65535"
Ext.form.VTypes["portMask"] = /[0-9]/;



Ext.form.VTypes["multicast"] = function(v) {
return Ext.form.VTypes["multicastVal"].test(v);
}
Ext.form.VTypes["multicastText"] = "224.0.1.0 - 239.255.255.255"
Ext.form.VTypes["multicastMask"] = /[.0-9]/;



Ext.form.VTypes["username"] = function(v) {
return Ext.form.VTypes["usernameVal"].test(v);
}
Ext.form.VTypes["usernameText"] = "Username must begin with a letter and cannot exceed 255 characters"
Ext.form.VTypes["usernameMask"] = /[-_.a-zA-Z0-9]/;


Ext.form.VTypes["password"] = function(v) {
if (!Ext.form.VTypes["passwordVal1"].test(v)) {
Ext.form.VTypes["passwordText"] = "Password length must be 6 to 31 characters long";
return false;
}
Ext.form.VTypes["passwordText"] = "Password must include atleast 2 numbers or symbols";
return Ext.form.VTypes["passwordVal2"].test(v);
}
Ext.form.VTypes["passwordText"] = "Invalid Password"
Ext.form.VTypes["passwordMask"] = /./;

JBoss - Encoding UTF-8 lost in application with EJB3

While developping a web application using EJB3 and JBoss, I've got a strange issue. The database (PostgreSQL) was in UTF-8, and the front end was also specifying UTF-8. But when I retrieve french characters with accents, they aren't showed correctly. It seems they are broken with ISO 8859-1 characters between the database and the JPA layer.

In ordrer to resolve the problem, I found that we need to force JBoss to use UTF-8. To do that, open {JBOSS_HOME}/bin/run.conf and add JVM option

-Dfile.encoding=UTF-8

Saturday, January 23, 2010

ExtJS -=- Search field with clearable functionality

Here is a new ExtJS component. It shows a search field that works like a clearable combo box. It has the same configuration than the Ext.form.ComboBox. You can enter some informations (minimum 3 characters) and the component will find the corresponding data in the JSON store. When entering data a clearable trigger appears so you can clear the combo.



Ext.namespace("Ext.Ice");

Ext.Ice.SearchField = Ext.extend(Ext.form.ComboBox, {
    /**
     * The triggers icons
     */
    trigger1Class: 'x-form-clear-trigger',
    trigger2Class: 'x-form-search-trigger',

    selectOnFocus: true,
    forceSelection: true,
    editable: true,

    /**
     * Type ahead config
     */
    typeAhead: true,
    typeAheadDelay: 1000,
    minChars: 3,
    
    /**
     * Hide the clear trigger by default
     */
    hideTrigger1: true,

    /**
     * Grabbing config from TwinTrigger Field
     */
    initComponent: Ext.form.TwinTriggerField.prototype.initComponent,
    getTrigger: Ext.form.TwinTriggerField.prototype.getTrigger,
    initTrigger: Ext.form.TwinTriggerField.prototype.initTrigger,

    /**
     * Reset function to hide the clear icon
     */
    reset : Ext.form.Field.prototype.reset.createSequence(function() {
        this.triggers[0].hide();
    }),


    /**
     * Show the clear trigger icon
     */
    onViewClick: Ext.form.ComboBox.prototype.onViewClick.createSequence(function() {
        this.triggers[0].show();
    }),

    /**
     * Trigger for the search functionnality
     */
    onTriggerClick : function() {
        if (this.getRawValue().length < 3) {
            Ext.Msg.show({
                title:'Please refine your search',
                msg: 'Please refine your search by entering at least 3 characters.',
                buttons: Ext.Msg.OK,
                animEl: 'elId',
                icon: Ext.MessageBox.INFO
            });
        } else {
            Ext.Ice.SearchField.superclass.onTriggerClick.call(this);
        }
    },


    /**
     * The Search button
     */
    onTrigger2Click : function() {
        this.onTriggerClick();
    },

    /**
     * The clear icon
     */
    onTrigger1Click : function() {
        if (this.hiddenField) {
            this.hiddenField.value = '';
        }
        this.setRawValue('');
        this.lastSelectionText = '';
        this.applyEmptyText();
        this.value = '';
        this.triggers[0].hide();
        this.fireEvent('clear', this);
    }
});


// We register this new component in ExtJS
Ext.reg('searchfield', Ext.Ice.SearchField);

Flushing DNS cache in Mac OS X

DNS request are usually cache, that’s good as it speeds up the lookups within the same host but sometimes we will want to clear the cache so it don’t hold the values that are no longer valid. To do that in Mac (OS Tiger and below) we used the following command:
lookupd -flushcache


However a Mac OSX 10.5 Leopard user will tell you this command did not work on their terminal. In Leopard a new command has been used to replace flushcache, so to clear DNS cache in Leopard, just type this in your Terminal and hit enter.
dscacheutil -flushcache

Monday, January 18, 2010

EJBQL 3.0 Quick Reference Guide

Hi!

This is a nice built quick reference guide for EJB Query Language 3.0.

You can find it here: EJBQL 3.0 Quick Reference Guide

Yann

Friday, January 15, 2010

Very Nice Subversion Cheat Sheet

Hi!

I've found a very nice Subversion Cheat Sheet. You can download it there SVN Cheat Sheet.

Thanks to the guys of AddedBytes.com!

Yann

Welcome to my blog!

Hi!

Welcome to my blog! A blog talking about technology and software engineering!

Have a nice day!

Yann