Pages

Friday, August 20, 2010

Set Subversion variables

Hi,

If you want to substitute variable with Subversion data, you must create a file with the Subversion's variable and lauch a command to told to Subversion to replace them.

Possible variable are:

Date

This keyword describes the last time the file was known to have been changed in the repository, and is of the form $Date: 2006-07-22 21:42:37 -0700 (Sat, 22 Jul 2006) $. It may also be specified as LastChangedDate.
Revision
This keyword describes the last known revision in which this file changed in the repository, and looks something like $Revision: 144 $. It may also be specified as LastChangedRevision or Rev.
Author
This keyword describes the last known user to change this file in the repository, and looks something like $Author: harry $. It may also be specified as LastChangedBy.
HeadURL
This keyword describes the full URL to the latest version of the file in the repository, and looks something like $HeadURL: http://svn.collab.net/repos/trunk/README $. It may be abbreviated as URL.
Id
This keyword is a compressed combination of the other keywords. Its substitution looks something like $Id: calc.c 148 2006-07-28 21:30:43Z sally $, and is interpreted to mean that the file calc.c was last changed in revision 148 on the evening of July 28, 2006 by the user sally.

You can create a version.properties file and set this content:
$HeadURL$
$Author$
$Date$
$Revision$
After that launch this command in terminal:
 svn propset svn:keywords "Date HeadURL Author Revision" version.properties

When you will check out the project, Subversion will replace data...

Tuesday, August 10, 2010

Changing user and group ID

Hi!

If you need to change the user and the group id of an account under Mac OS X, you have to follow theses steps. We suppose that the actual id for the user and the group is 666 and we want to change them to 999.
  1. Logged as MY_USER type the command id
  2. The uid = User ID and gid is the Group ID. Note thems...
  3. Log with another account 
  4. sudo dscl . -change /Users/MY_USER UniqueID 666 999
  5. sudo dscl . -change /Users/MY_USER PrimaryGroupID 666 999
  6. sudo chown -R 999:999 /Users/MY_USER
  7. Open a session with MY_USER
Nota, if you want to connect to a NFS server, you need the same ids to be able to access the shared folders...

Tuesday, August 3, 2010

Ruby -=- undefined method `[]' for #Enumerable::Enumerator

Hi!

When I upgrade to Ruby 1.8.7 I've got some problems. I'm getting the error message undefined method `[]' for #Enumerable::Enumerator.

The problem occurs with the version 1.8.7 of Ruby and it's supposed to be corrected in the version 9. To fix this problem you can either downgrade to Ruby 1.8.6 OR put this piece of code in your environnement.rb within initializer block:

unless '1.9'.respond_to?(:force_encoding)
  String.class_eval do
    begin
      remove_method :chars
    rescue NameError
      # OK
    end
  end
end 

Monday, July 26, 2010

ExtJS FormPanel sending JSON data

Hi!

If you want your Ext.form.FormPanel sends JSON, you must extends Ext.form.Action.Submit and create a new action that format and send the data as JSON. Here's how to do this.

Ext.namespace("Ext.ux.Action");


/**
 * The JSON Submit is a Submit action that send JSON instead of send URL Encoded data... You MUST specify the jsonRoot
 * property...
 * @param form The form to submit
 * @param options The options of the HTTP Request
 */
Ext.ux.Action.JsonSubmit = function(form, options) {
    Ext.ux.Action.JsonSubmit.superclass.constructor.call(this, form, options);
};

/**
 * We are extending the default Action Submit...
 */
Ext.extend(Ext.ux.Action.JsonSubmit, Ext.form.Action.Submit, {
    type: 'jsonsubmit',

    run : function() {
        var o = this.options;
        var method = this.getMethod();
        var isGet = method == 'GET';
        if (o.clientValidation === false || this.form.isValid()) {
            var encodedParams = Ext.encode(this.form.getValues());

            Ext.Ajax.request(Ext.apply(this.createCallback(o), {
                url:this.getUrl(isGet),
                method: method,
                waitMsg: "Please wait while saving",
                waitTitle: "Please wait",
                headers: {'Content-Type': 'application/json'},
                params: String.format('{{0}: {1}}', o.jsonRoot.toLowerCase(), Ext.encode(this.form.getValues())),
                isUpload: this.form.fileUpload
            }));
        } else if (o.clientValidation !== false) { // client validation failed
            this.failureType = Ext.form.Action.CLIENT_INVALID;
            this.form.afterAction(this, false);
        }
    }
});

/**
 * We register the new action type...
 */
Ext.apply(Ext.form.Action.ACTION_TYPES, {
    'jsonsubmit' : Ext.ux.Action.JsonSubmit
});



When you are submitting the form, instead of using


myForm.getForm().submit({
//props here
})


use this

myForm.getForm().doAction("jsonsubmit",{
//props here
});

Friday, July 23, 2010

Clone an ExtJS Component

Hi!

If you want to clone an ExtJS Component, you must you the cloneConfig() method from the Ext.form.Field object. For example,

//Component 1
var comp1 = new Ext.form.TextField({});

//Component cloning...
var comp2 = comp1.cloneConfig();


Ext.form.TextField value in uppercase

Hi!

if you want to have a Ext.form.TextField only in uppercase, you can use the following code:

new Ext.form.TextField({
     style : {textTransform: "uppercase"},
     listeners:{
          change: function(field, newValue, oldValue){
                       field.setValue(newValue.toUpperCase());
                  }
     }
});

Tuesday, May 4, 2010

JavaScript String Replace All

The JavaScript function for String Replace replaces the first occurrence in the string. The function is similar to the php function str_replace and takes two simple parameters. The first parameter is the pattern to find and the second parameter is the string to replace the pattern with when found. The javascript function does not Replace All...

str = str.replace(”find”,”replace”)

To ReplaceAll you have to do it a little differently. To replace all occurrences in the string, use the g modifier like this:
 
str = str.replace(/find/g,”replace”)