Tuesday, July 20, 2010

run mysql as non-root user

For example in westgrid:

1) in home directory, create file .my.cnf
---------------------------------------------------------------
[mysqld]
datadir=/global/home/jiansen6/mymysql
socket=/global/home/jiansen6/mymysql/thesock
port=8081

[mysql]
socket=/global/home/jiansen6/mymysql/thesock
port=8081

[mysql.server]
user=mysql
basedir=/var/lib

[safe_mysqld]
err-log=/global/home/jiansen6/mymysql/the.log
pid-file=/global/home/jiansen6/mymysql/the.pid
-------------------------------------------------------------
2) mysql_install_db
3) mysqld_safe &

shutdown mysql
4) mysqladmin -u root -S /global/home/jiansen6/mymysql/thesock shutdown -p

Software Quality assurance

SQA (Software Quality Assurance) encompasses the entire software development process, which includes processes such as requirements definition, software design, coding, source code control, code reviews, change management, configuration management, testing, release management, and product integration. SQA is organized into goals, commitments, abilities, activities, measurements, and verifications[1].

Monday, July 19, 2010

Design MySQL

1) Normalization: carefully eliminate redundancies and other problems that will undermine the integrity of your data.
2) Design Primary key and Foreign key:
A primary key is a unique identifier that has to abide by certain rules. They must
  • Always have a value (it cannot be NULL)

  • Have a value that remains the same (never changes)

  • Have a unique value for each record in the table

Foreign keys are the representation of the primary key from Table A in Table B.

If no logical primary key exists, invent one.

3) Relationships

A relationship between two tables can be one-to-one, one-to-many, or many-to-many.

4) Create Normal Form

create first normal form , second and third normal form.
each normal form should have its primary key, reduce many-to-many
between tables.

5) Design MySQL data type

Ty p e

S i z e

D e s c r i p t i o n

CHAR[Length]

Length bytes

A fixed-length field from 0 to 255 characters long.

VARCHAR(Length)

String length + 1 bytes

A fixed-length field from 0 to 255 characters long.

TINYTEXT

String length + 1 bytes

A string with a maximum length of 255 characters.

TEXT

String length + 2 bytes

A string with a maximum length of 65,535 characters.

MEDIUMTEXT

String length + 3 bytes

A string with a maximum length of 16,777,215 characters.

LONGTEXT

String length + 4 bytes

A string with a maximum length of 4,294,967,295 characters.

TINYINT[Length]

1 byte

Range of -128 to 127 or 0 to 255 unsigned.

SMALLINT[Length]

2 bytes

Range of -32,768 to 32,767 or 0 to 65535 unsigned.

MEDIUMINT[Length]

3 bytes

Range of -8,388,608 to 8,388,607 or 0 to 16,777,215 unsigned.

INT[Length]

4 bytes

Range of -2,147,483,648 to 2,147,483,647 or 0 to 4,294,967,295 unsigned.

BIGINT[Length]

8 bytes

Range of -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 or 0 to 18,446,744,073,709,551,615 unsigned.

FLOAT

4 bytes

A small number with a floating decimal point.

DOUBLE[Length, Decimals]

8 bytes

A large number with a floating decimal point.

DECIMAL[Length, Decimals]

Length + 1 or Length + 2 bytes

A DOUBLE stored as a string, allowing for a fixed decimal point.

DATE

3 bytes

In the format of YYYY-MM-DD.

DATETIME

8 bytes

In the format of YYYY-MM-DD HH:MM:SS.

TIMESTAMP

4 bytes

In the format of YYYYMMDDHHMMSS; acceptable range ends inthe year 2037.

TIME

3 bytes

In the format of HH:MM:SS

ENUM

1 or 2 bytes

Short for enumeration, which means that each column can haveone of several possible values.

SET

1, 2, 3, 4, or 8 bytes

Like ENUM except that each column can have more than one ofseveral possible values.

Friday, July 16, 2010

Computer Programmer Resume

Computer Programmer Resume 1
Computer Programmer Resume 2



Add following in my resume:
-------------------------------------
Computer skill highlight:


Language:
Proficient in: C/C++, SQL, Matlab, Python, Shell Script, Html, PHP, CSS, Javascript, Fortran, Perl, Visual Basic

Software:
MS Visual Studio, MS Office, Xcode, MatLab, Mathematica, Maple, Latex, R, Boost library, OpenMP, MySQL, Oracle, CVS

Platform: WestGrid, LCG, Linux, Mac, Windows Vista and XP.

Other: system administration, user support, mathematical modeling and data analysis

Wednesday, July 14, 2010

Some varialbes in Visual C++

1.
LPCTSTR stands for Long Pointer Constant String.
Basically consider LPCTSTR a (char*).. theres a little more to it, but basically:
LPCTSTR s = "Hi!"

and

char *s = "Hi!"

are the same


2.
CWnd: to create Window. Header: afxwin.h
You create a child window in two steps. First, call the constructor
CWnd to construct the CWnd object, then call the Create member function to
create the child window and attach it to the CWnd object.

3.
UINT is an unsigned (meaning it doesn't hold negative values) integer.

4. _T(" ") for Unicode, Unicode can be disabled from project property.

5. use delete to prevent memory leakage


#include <iostream>
using namespace std;

int main(){

int *i=new int(1); //*i=1


cout<<"*i="<<*i<<endl;//*i=1
//defines a pointer to an array of 3 ints
int *j=new int[3];

cout<<"*j="<<j[0]<<endl;
delete  i;//delete pointer to prevent memory leakage
delete [] j;//delete pointer to array

return(0);
}


6. CDC class: Defines a class
The CDC object provides member functions for working
with a device context, such as a display or printer, as well as members
for working with a display context associated with the client area of a
window.s of device-context objects.
example using CDC::TextOut() method:
void CExoView::OnDraw(CDC* pDC)
{
CExoDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);

pDC->TextOut(50, 42, "Johnny Carson", 13);

}
Header: afxwin.h


Calling One Dialog Box From Another--VC++

  1. Visual C++ 2010
  2. Create a new MFC Application named Primary1
  3. Create it as Dialog Based
4.Set the Dialog Title to Calling One Dialog Box From Another

  1. Click Finish
  2. To add another dialog box, on the main menu, click Project -> Add Resource...
  3. In the Add Resource dialog box, double-click Dialog
  4. Change the ID of the new dialog to IDD_SECOND_DLG and its Caption to Second
  5. Right-click the dialog box and click Add Class...
  6. Set the Class Name to CSecondDlg and base it on CDialog
  7. Click Finish
  8. From the Class View, double-click the IDD_PRIMARY1_DIALOG
  9. Using the Toolbox, add a Button to the dialog box and change its properties as follows:
    Caption: Second
    ID: IDC_SECOND_BTN
  10. Double-click the new Second button and implement its event as follows:
    // Primary1Dlg.cpp : implementation file
    //
    
    #include "stdafx.h"
    #include "Primary1.h"
    #include "Primary1Dlg.h"
    #include ".\primary1dlg.h"
    #include "SecondDlg.h"
    
    #ifdef _DEBUG
    #define new DEBUG_NEW
    #endif
    
    
    // CPrimary1Dlg dialog
    
    
    . . . No Change
    
    // The system calls this function to obtain
    // the cursor to display while the user drags
    //  the minimized window.
    HCURSOR CPrimary1Dlg::OnQueryDragIcon()
    {
    return static_cast(m_hIcon);
    }
    
    void CPrimary1Dlg::OnBnClickedSecondBtn()
    {
    // TODO: Add your control notification handler code here
    CSecondDlg Dlg;
    
    Dlg.DoModal();
    /*
    
    CDialog::DoModal
    Call this member function to invoke the modal dialog box and return the dialog-box result when done.
    */
    }
  11. Test the application

Saturday, July 10, 2010

Calling a dialog box -VC++ 2010

Practical Learning 2): Calling a Dialog Box From an SDI
(Single Document Interface)

  • Start
    Microsoft Visual C++ 2010
  • Create a new MFC->MC
    Application named SDI1


  • Create it as Single Document
  • To add a dialog box, on the main
    menu, click Project -> Add Resource...
  • In the Add Resource dialog box,
    double-click Dialog
  • Change the ID of the new
    dialog to IDD_GENERIC_DLG
  • Right-click the dialog box and
    click Add Class...


  • Set the Class Name to CDependentDlg and base it on
    CDialog, click Finish
  • From the Class View, double-click the IDR_MAINFRAME menu
  • On the right side of Help, click Type Here and type &Tools
  • Click the box under Tools and type &Dependents... and press Enter
  • Click and drag the Tools menu category to the left to position it between View and Help
  • Right-click the Dependents menu item and click Add Event Handler...
  • Set the Class List to the view class
  • Click Add and Edit
add red part in SD1View.cpp

// SD1View.cpp : implementation of the CSDI1View class
//

#include "stdafx.h"
#include "SDI1.h"

#include "SDI1Doc.h"

#include "SDI1View.h"
#include ".\sdi1view.h"
#include "DependentDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


. . . No Change


// CSDI1View message handlers

void CSDI1View::OnToolsDependents()

{
        // TODO: Add your command handler code here
        CDependentDlg Dlg;

        Dlg.DoModal();
}


Add red part in class CSDI1View in SD1View.h

virtual void OnToolsDependents();
Build Solution, Debug->Starting without debugging


VC++-2010: create a simple window

Using Visual C++-2010 Professional trial version

to create a simple Window:

(Win32 was written in C and had no native support for C++. Therefore, Microsoft created a library, named Microsoft Foundation Classes Library, and abbreviated MFC. This library was originally an “adaptation” or customization of Win32, adding object-orientation (classes and inheritance) to it.)

-----------------------------------------------------------------


  • Create a Win32 Project named MFCSimpleWindow using
    File->Project->new->Win32




  • Create it as an Empty Project and a Windows Application,
    Click Finish



  • On the main menu, click Project -> MFCSimpleWindow
    Properties..

    in Character set:

  • Use Unicode Character Set to use Unicode, or
    select "not set" to not to use Unicode
  • To create a new source file, on the main menu, click
    Project -> Add New Item,
    In the Templates section, click C++
    File (.cpp), Set the Name as Exercise



  • (step 7) in Exercise.cpp: type: (MFC base class start with C)



    #include <afxwin.h>


    struct CMainFrame : public CFrameWnd
    {
    CMainFrame()
    {
    //    Create(NULL, "Windows Application Tester");
    Create(NULL, _T("Windows Application Tester")); // in Unicode
    }
    };
    
    struct CExerciseApp : public CWinApp
    {
    BOOL InitInstance()
    {
    CMainFrame *Frame = new CMainFrame();
    m_pMainWnd = Frame;
    
    Frame->ShowWindow(SW_NORMAL);
    Frame->UpdateWindow();
    
    return TRUE;
    }
    };
    
    CExerciseApp theApp;



  • Build->Build Solution, Run->Run without debugging





  • Build->Build Solution, Run->Run without debugging



    Change only Code in step 7 to create popup window


    #include <afxwin.h>


    struct CFrameTest : public CFrameWnd
    {
    CFrameTest()
    {
    Create(NULL, _T("Windows Application Tester"),
    WS_POPUPWINDOW | WS_CAPTION,
    CRect(400, 280, 580, 520), NULL, NULL,
    WS_EX_TOOLWINDOW);
    }
    };
    
    struct CAppTest : public CWinApp
    {
    BOOL InitInstance()
    {
    CFrameTest *Tester = new CFrameTest();
    m_pMainWnd = Tester;
    Tester->ShowWindow(SW_NORMAL);
    
    return TRUE;
    }
    };
    
    CAppTest theApp;

  • Friday, July 9, 2010

    VC++ 2010-add Start without Debugging.

    When I download Visual C++ 2010 express, I found there is no
    "Start without Debugging." and I can not run executable after building.
    1) short cut: ctrl+F5


    2)The following method is used to add:
    "Start without Debugging."
    -----------------------------------------------
    1) Tool->Customize->Commands Tab
    2) Under the commands Tab, select Toolbar, then select the debug toolbar.
    3)On the right side, you should be able to select click Add Command, the Add command dialog should appear.


    4)Select Debug on the left side, and start without debugging in the right side.

    Thursday, July 8, 2010

    Difference between pointer and reference-C++

    I found that the following video nicely explains the difference between pointer and
    reference in C/C++:


    Monday, July 5, 2010

    VB and Excel (Mac, 2004)

    Mac, Excel 2008, VB not supported
    1. Tools->Macro->Visual Basic Editor
    a) double click sheet1, copy following VB code:
    ------------------------------------
    Sub proFirst()
    Range("A1").Value = 34
    Range("A2").Value = 66
    Range("A3").Formula = "=A1+A2"
    Range("A1").Select
    End Sub
    -------------------------------------
    b) Recording Macro: Click Run-> Run Sub(F5)
    In sheet 1, Column 1, 34,66 and 100 are shown

    2. Tools->New Macro
    In working sheet, type A1->100, B1->1000
    A2->20, B2->15
    stop recording macro
    go to Visual basic editor,
    Module->Module1, the following code can be seen
    -------------------------------
    Sub Macro1()
    '
    ' Macro1 Macro
    ' Macro recorded by Jiansen Lu
    '

    '
    ActiveCell.FormulaR1C1 = "100"
    Range("B1").Select
    ActiveCell.FormulaR1C1 = "1000"
    Range("A2").Select
    ActiveCell.FormulaR1C1 = "20"
    Range("B2").Select
    ActiveCell.FormulaR1C1 = "15"
    End Sub
    -----------------------------------------------

    Friday, July 2, 2010

    perl examples

    Example 1: Input two number, output sum

    ------------------------------------------------
    #!/usr/bin/perl

    $doagain = "yes";

    while
    ($doagain eq "yes") {
    $x = &getnumber;
    $y = &getnumber;

    $z = $x + $y;

    print "$x + $y = $z\n";

    print "$x + $y = $z\n";

    print "Do it again? (yes or no) ";
    $doagain = <STDIN>;

    chop($doagain);

    }

    sub getnumber {

    print "Type in a number: \n";

    $number = <STDIN>;
    chop($number);

    while
    ($number =~ /\D/){ # not non-digit, i.e digit[0-9]

    print "$number is not a number\n";
    print "Enter a number ";
    $number = <STDIN>;

    chop($number);
    }

    $number;
    }


    ----------------------------------------------------------------

    Example 2: find a file in a directory and its sub-directory
    --------------------------------------------------------------

    #!/usr/bin/perl

    #
    # search for a file in all subdirectories
    #
    if ($#ARGV != 1) {
    print "usage: find_file filename directory\n";
    exit;
    }

    $filename = $ARGV[0]; #first argument

    # look in the directory
    $dir = $ARGV[1]; #second argument
    &searchDirectory($dir);

    sub searchDirectory {
    local($dir); #local variable
    local(@lines);
    local($line);
    local($file);
    local($subdir);

    $dir = $_[0];
    # check for permission
    if(-x $dir) {

    # search this directory
    @lines = `cd $dir; ls -l | grep $filename`;
    foreach $line (@lines) {
    #\d # Any digit. The same as [0-9]
    #\D # Any non-digit. The same as [^0-9]
    #\s # Any whitespace character: space,
    #\S # Any non-whitespace character
    # tab, newline, etc

    $line =~ /\s+(\S+)$/; # end of line
    $file = $1;
    print "Found $file in $dir\n";
    }

    # search any sub directories

    @lines = `cd $dir; ls -l`;
    foreach $line (@lines) {
    if($line =~ /^d/) { # beginning of line containing d (directory)
    $line =~ /\s+(\S+)$/;
    $subdir = $dir."/".$1;
    &searchDirectory($subdir);
    }
    }
    }
    }

    ----------------------------------------------------------
    example 3
    -----------------------------------------------

    #!/usr/bin/perl
    #$b and $c as strings
    $b='3';

    $c='2';
    $a = $b . $c; # Concatenate string $b and $c
    print "$a \n";

    $a = $b x $c; # string $b repeated $c times
    print "$a \n";
    @food = ("apples", "pears", "eels");

    print "$food[2] \n"; #array starting from 0
    push(@food, "eggs", "lard");

    print "@food \n";
    foreach $morsel (@food) # Visit each item in turn
    # and call it $morsel
    {

    print "$morsel\n"; # Print the item
    print "Yum yum\n"; # That was nice
    }


    for
    ($i = 0; $i < 10; ++$i) # Start with $i = 1

    # Do it while $i < 10
    # Increment $i before repeating
    {
    print "$i\n";
    }

    print "Password? "; # Ask for input
    $a = <STDIN>; # Get input
    chop $a; # Remove the newline at end

    while
    ($a ne "fred") # While input is wrong...
    {

    print "sorry. Again? "; # Ask again
    $a = <STDIN>; # Get input again
    chop $a; # Chop off newline again

    }


    if
    ($a)
    {

    print "The string is not empty\n";
    }

    else


    {

    print "The string is empty\n";
    }


    read in file to vector arrary --C++

    #include <ctime>
    #include<iomanip>
    
    #include <iostream>
    #include<string>
    using namespace std;
    
    
    
    
    void read_network(vector <vector<int> > &VCMA_network){
    
    //read network from input files
    
    char *file;
    ifstream fin;
    string path,name;
    
    
    path="/global/scratch/jiansen6/network-input/";
    name=path+"stubs.dat1";
    cout <<"input file name "<<name<<endl;
    
    file=new char[name.size()+1];
    strcpy (file, name.c_str());
    
    fin.open(file);
    
    
    if (fin.is_open()){
    
    string line;
    while ( getline(fin, line) ) {
    
    istringstream ss(line);
    vector < int > data;
    int value;
    
    // for data separate by space 
                          while (ss >> value)
    {
    data.push_back(value);
    }
    
    // for data separate by comma
    /*
    char output[30];
    while ( ss.getline(output, sizeof(output),',') ){
    value = atoi(output); //convert char to int
    data.push_back(value);}
    
    */
    VCMA_network.push_back(data);
    
    }//end of while
            } //end of fin.is_open
            else{
    
    cout<<"Problem with opening the file "<<name<<endl;
    exit(1);
    }
    
    fin.close();
    
    }