Archive 2013

Interactive Ruby : simplify your computing

Interactive Ruby helps you to make complex computations without having to write a whole program.
Under linux type irb.

Ex1. calculate (10-7+500)*(4 power 3 )-square root of(900)

irb(main):001:0> (10-7+500)*(4**3)-Math.sqrt(900)
=> 32162.0

Ex2. get exact date at 14 days before now (in seconds 14x24x60x60 before now)

irb(main):002:0> Time.new – (14*24*60*60)
=> Thu Nov 21 15:52:53 +0100 2013

upgrade sonar 3 to 4

so easy as 5 simple steps :
– Download and unzip new sonarqube-4.0.zip : > unzip sonarqube-4.0.zip -d $NEW_SONAR_HOME
– Manually edit sonarqube-4.0/conf/sonar.properties and sonarqube-4.0/conf/wrapper.conf and copy old properties values from old sonar conf
– Copy extensions from old sonar to the new one (only extensions not having correspondent in the new sonar)
– stop old sonar and start the new one :
> $OLD_SONAR_HOME/bin/yourOS/sonar.sh stop
> $NEW_SONAR_HOME/bin/yourOS/sonar.sh start
– Go to http://localhost:9000/setup (assuming sonar listen in localhost) and finally click under upgrade button

losing sonar admin password

by default sonar creates admin account : user: admin, password : admin
when sonar admin password is changed and lost, simple way to reinitialize password to admin is with a simple sql command :
> musql -u sonar -p
mysql> use sonar
mysql> update users set crypted_password = ’88c991e39bb88b94178123a849606905ebf440f5′, salt=’6522f3c5007ae910ad690bb1bdbf264a34884c6d’ where login = ‘admin’
that’s all.

ajax loader with APEX

1. Prerequisites in plsql oracle packages

1.1. Stored procedure GENERATE_REPORT

procedure GENERATE_REPORT(p_report_id in number) is
begin
    --------------
    -- long time process to generate report
    -- blabla
    -- babla
    ----------------
    
    update REPORT
        set STATUS = 'FINISH'
    where REPORT_ID = p_report_id;
    
    exception when others then
        update REPORT
            set STATUS = 'ERROR'
        where REPORT_ID = p_report_id;  
end;

1.2. Stored function START_GENERATE_REPORT

function START_GENERATE_REPORT() return number is
    l_report_id number;
    l_dummy     number;
begin
    l_report_id := SEQ_REPORT.nextval;
    insert into 
    REPORT(REPORT_ID,STATUS)
    VALUES(l_report_id,'GENRATING');
    
    DBMS_JOB.SUBMIT(l_dummy,'begin GENERATE_REPORT('||l_report_id||'); end;');
    
    return l_report_id;
end;

1.3. Stored function GET_REPORT_STATUS

function GET_REPORT_STATUS(p_report_id in number) return varchar2 is
 l_status varchar2(100);
begin
    select STATUS into l_status
        from REPORT
    where REPORT_ID = p_report_id;
    
    return l_status;
    
    exception when others then
        return 'ERROR';
end;

2. APEX application

HIDDEN TEXT ELEMENT ‘PAGE_REPORT_ID’
BUTTON ELEMENT ‘generate’: button click submits page
PAGE PROCESS ELEMENT ‘processGenerate’: activated on ‘generate’ button click

declare
  l_report_id number;
begin
  l_report_d := START_GENERATE_REPORT();
  :PAGE_REPORT_ID := l_report_d;
end;

HTML FORM ELEMENT ‘loader’
– condition : PAGE_REPORT_ID content is not null
– content :

refreshReportLoader();

APPLICATION PROCESS ELEMENT : PROCESS_REPORT_STATUS
In apex go to application process and create new process. be sure you select “On Demand” as Point property of your process. 

declare
    l_param_report_id varchar2(100);
    l_result_status   varchar2(100);
begin
    owa_util.mime_header('text', FALSE );
    htp.p('Cache-Control: no-cache');
    htp.p('Pragma: no-cache');
    owa_util.http_header_close; 
    
    l_param_report_id := wwv_flow.g_x01;
    l_result_status := GET_REPORT_STATUS(to_number(l_param_report_id));
    htp.prn(l_result_status);
end;

IN PAGE HEADER
put javascript following javascript function :

function refreshReportLoader(){
    var get = new htmldb_Get(null, $v('pFlowId'), 'APPLICATION_PROCESS=PROCESS_REPORT_STATUS',0);   
    get.addParam('x01',$v('P_REPORT_ID'));
    gStatus = get.get('TEXT');

    var loader = document.getElementById("divLoader");
    loader.innerHTML= gStatus ;
    
    if(!gStatus == 'FINISH' && !gStatus == 'ERROR'){
         setTimeout(function(){refreshReportLoader()},3000);
    }
}

3. how to use

click on button ‘generate’ and see the loader div which must change content according to REPORT.STATUS