问:
BlackBerry Alarm Integeration
Below is my application code. i want alarm to ring on my blackberry on every 6 of this month whether this apllication is running or not. please guide me in details i am a beginner.

```import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.system.*;
import net.rim.device.api.util.*;

import java.util.*;

import java.lang.String.*;

public class ListChk extends UiApplication
{
    String getFirstName;
    String getLastName;
    String getEmail;
    String getGender;
    String getStatus;
    String getCompany;

    /*declaring text fields for user input*/
    private AutoTextEditField firstName;

    private AutoTextEditField lastName;
    private AutoTextEditField company;

    private EmailAddressEditField email;

    /*declaring choice field for user input*/

    private ObjectChoiceField gender;

    /*declaring check box field for user input*/
    private CheckboxField status;

    //Declaring button fields
    private ButtonField save;
    private ButtonField close;
    private ButtonField List;
    private ButtonField search;

    /*declaring vector*/
    private static Vector _data;

    /*declaring persistent object*/
    private static PersistentObject store;

    /*creating an entry point*/
    public static void main(String[] args)

    {
        ListChk objListChk = new ListChk();
        objListChk.enterEventDispatcher();

    }//end of main of ListChk

    public ListChk()
    {

        /*Creating an object of the main screen class to use its functionalities*/
        MainScreen mainScreen = new MainScreen();

        //setting title of the main screen
        mainScreen.setTitle(new LabelField("Enter Your Data"));

        //creating text fields for user input
        firstName = new AutoTextEditField("First Name: ", "");
        lastName= new AutoTextEditField("Last Name: ", "");
        email= new EmailAddressEditField("Email:: ", "");
        company = new AutoTextEditField("Company: ", "");

        //creating choice field for user input
        String [] items = {"Male","Female"};
        gender= new ObjectChoiceField("Gender",items);

        //creating Check box field
        status = new CheckboxField("Active",true);

        //creating Button fields and adding functionality using listeners

        // A button that saves the the user data persistently when it is clicked
        save = new ButtonField("Save",ButtonField.CONSUME_CLICK);
        save.setChangeListener(new FieldChangeListener()
        {
            public void fieldChanged(Field field, int context)
            {
                save();

            }
        });

        // a button which closes the entire application when clicked
        close = new ButtonField("Close",ButtonField.CONSUME_CLICK);
        close.setChangeListener(new FieldChangeListener()
        {
            public void fieldChanged(Field field, int context)
            {
                onClose();
            }
        });

        // A button that shows the List of all Data being stored persistently
        List = new ButtonField("List",ButtonField.CONSUME_CLICK);
        List.setChangeListener(new FieldChangeListener()
        {
            public void fieldChanged(Field field, int context){
                // pushing the next screen

                pushScreen(new ListScreen());

            }
        });

        search = new ButtonField("Search",ButtonField.CONSUME_CLICK);
        search.setChangeListener(new FieldChangeListener()
        {
            public void fieldChanged(Field field, int context)
            {
                pushScreen(new SearchScreen());
            }
        });
        //adding the input fields to the main screen
        mainScreen.add(firstName);
        mainScreen.add(lastName);
        mainScreen.add(email);
        mainScreen.add(company);
        mainScreen.add(gender);
        mainScreen.add(status);

        // Addning horizontal field manager
        HorizontalFieldManager horizontal = new HorizontalFieldManager(HorizontalFieldManager.FIELD_HCENTER);

        //adding buttons to the main screen in Horizontal field manager

        horizontal.add(close);
        horizontal.add(save);
        horizontal.add(List);
        horizontal.add(search);

        //Adding the horizontal field manger to the screen
        mainScreen.add(horizontal);

        //adding menu items

        mainScreen.addMenuItem(saveItem);
        mainScreen.addMenuItem(getItem);
        mainScreen.addMenuItem(Deleteall);

        //pushing the main screen
        pushScreen(mainScreen);
    }
    private MenuItem Deleteall = new MenuItem("Delete all",110,10)
    {
        public void run()
        {
            int response = Dialog.ask(Dialog.D_YES_NO,"Are u sure u want to delete entire Database");
            if(Dialog.YES == response){
            PersistentStore.destroyPersistentObject(0xdec6a67096f833cL);
            Dialog.alert("Closing Application");
            onClose();
            }
            else
                Dialog.inform("Thank God");
        }
    };
//adding functionality to menu item "saveItem"
private MenuItem saveItem = new MenuItem("Save", 110, 10)
{

        public void run()
        {
            //Calling save method
            save();
        }
};
//adding functionality to menu item "saveItem"
private MenuItem getItem = new MenuItem("Get", 110, 11)
{
    //running thread for this menu item
    public void run()
    {

            //synchronizing thread
            synchronized (store)
            {
                //getting contents of the persistent object

                _data = (Vector) store.getContents();
                try{

                    for (int i = _data.size()-1; i >-1; i--)
                    {

                        StoreInfo info = (StoreInfo)_data.elementAt(i);
                        //checking for empty object
                        if (!_data.isEmpty())
                        {
                        //if not empty
                        //create a new object of Store Info class

                        //storing information retrieved in strings
                        getFirstName    =   (info.getElement(StoreInfo.NAME));
                        getLastName     =   (info.getElement(StoreInfo.LastNAME));
                        getEmail        =   (info.getElement(StoreInfo.EMail));
                        getGender       =   (info.getElement(StoreInfo.GenDer));
                        getStatus       =   (info.getElement(StoreInfo.setStatus));
                        getCompany      =   (info.getElement(StoreInfo.setCompany));
                            //calling the show method
                        show();
                        }

                    }
                }
                catch(Exception e){}
            }
        }

};
public void save()
{

    //creating an object of inner class StoreInfo
    StoreInfo info = new StoreInfo();
    //getting the test entered in the input fields
    info.setElement(StoreInfo.NAME, firstName.getText());
    info.setElement(StoreInfo.LastNAME,lastName.getText());
    info.setElement(StoreInfo.EMail, email.getText());
    info.setElement(StoreInfo.setCompany, company.getText());
    info.setElement(StoreInfo.GenDer,gender.toString());
    if(status.getChecked())
        info.setElement(StoreInfo.setStatus, "Active");
    else
        info.setElement(StoreInfo.setStatus, "In Active");
    //adding the object to the end of the vector
    _data.addElement(info);
    //synchronizing the thread
    synchronized (store)
    {

        store.setContents(_data);
        store.commit();

    }
    //resetting the input fields

    Dialog.inform("Success!");
    firstName.setText(null);
    lastName.setText(null);
    email.setText("");
    company.setText(null);
    gender.setSelectedIndex("Male");
    status.setChecked(true);

}
//coding for persistent store
static {

store =
PersistentStore.getPersistentObject(0xdec6a67096f833cL);
synchronized (store) {
if (store.getContents() == null) {
store.setContents(new Vector());
store.commit();
}
}
_data = new Vector();
_data = (Vector) store.getContents();

}
//new class store info implementing persistable
private static final class StoreInfo implements Persistable
{
    //declaring variables
    private Vector _elements;
    public static final int NAME = 0;
    public static final int LastNAME = 1;
    public static final int EMail= 2;
    public static final int GenDer = 3;
    public static final int setStatus = 4;
    public static final int setCompany = 5;
    public StoreInfo()
    {
        _elements = new Vector(6);
        for (int i = 0; i < _elements.capacity(); ++i)
        {
            _elements.addElement(new String(""));
        }
    }

    public String getElement(int id)
    {
        return (String) _elements.elementAt(id);
    }
    public void setElement(int id, String value)
    {
        _elements.setElementAt(value, id);
    }
}
//details for show method
public void show()
{
    Dialog.alert("Name is "+getFirstName+" "+getLastName+"\nGender is "+getGender+"\nE-mail: "+getEmail+"\nStatus is "+getStatus);
}
public void list()
{

    Dialog.alert("haha");

}

//creating save method

//overriding onClose method

public boolean onClose()
{

    System.exit(0);
    return true;
}

 class ListScreen extends MainScreen
{
     String getUserFirstName;
     String getUserLastName;
     String getUserEmail;
     String getUserGender;
     String getUserStatus;
     String getUserCompany;
     String[] setData ;
     String getData = new String();
     String collectData = "";
     ObjectListField fldList;
     int counter = 0;

    private ButtonField btnBack;

    public ListScreen()
    {

        setTitle(new LabelField("Showing Data",LabelField.NON_FOCUSABLE));
        //getData = myList();
        //Dialog.alert(getData);

    //  setData = split(getData,"$");
    //  for(int i = 0;i<setData.length;i++)
    //  {
    //      add(new RichTextField(setData[i]+"@@@@@"));
    //  }
        showList();
        btnBack = new ButtonField("Back",ButtonField.CONSUME_CLICK|ButtonField.FIELD_HCENTER);
        btnBack.setChangeListener(new FieldChangeListener()
        {
            public void fieldChanged(Field field,int context)
            {
                UiApplication.getUiApplication().popScreen(getScreen());
            }
        });

        add(btnBack);

    }

    public void showList()
    {
        HorizontalFieldManager hfManager = new HorizontalFieldManager(HorizontalFieldManager.HORIZONTAL_SCROLLBAR|HorizontalFieldManager.HORIZONTAL_SCROLL);
        //SeparatorField spManager = new SeparatorField();
        LabelField lblcheck = new LabelField("check",LabelField.NON_FOCUSABLE);
        getData = myList();
        setData = split(getData,"$");
        fldList = new ObjectListField(ObjectListField.MULTI_SELECT);
        fldList.set(setData);
        //fldList.setEmptyString("heloo", 12);
        //hfManager.add(lblcheck);

        hfManager.add(fldList);
        //hfManager.add(spManager);
        add(hfManager);
        addMenuItem(new MenuItem("Select", 100, 1) {
            public void run() {
                int selectedIndex = fldList.getSelectedIndex();
                String item = (String)fldList.get(fldList, selectedIndex);
               pushScreen(new ShowDataScreen(item));
            }
            });

    }

    public String[] split(String inString, String delimeter) {
        String[] retAr;
        try {
            Vector vec = new Vector();
            int indexA = 0;
            int indexB = inString.indexOf(delimeter);

            while (indexB != -1) {
                vec.addElement(new String(inString.substring(indexA, indexB)));
                indexA = indexB + delimeter.length();
                indexB = inString.indexOf(delimeter, indexA);
            }
            vec.addElement(new String(inString.substring(indexA, inString
                    .length())));
            retAr = new String[vec.size()];
            for (int i = 0; i < vec.size(); i++) {
                retAr[i] = vec.elementAt(i).toString();
            }
        } catch (Exception e) {
            String[] ar = { e.toString() };
            return ar;
        }
        return retAr;
    }//end of Split Method

    public String myList()
    {

        _data = (Vector) store.getContents();
        try
        {
            for (int i = _data.size()-1; i >-1; i--,counter++)
                {

                    StoreInfo info = (StoreInfo)_data.elementAt(i);
                    //checking for empty object
                    if (!_data.isEmpty())
                        {
                            //if not empty
                            //create a new object of Store Info class

                            //storing information retrieved in strings
                            //StoreInfo info = (StoreInfo)_data.lastElement();
                            getUserFirstName    =   (info.getElement(StoreInfo.NAME));
                            getUserLastName     =   (info.getElement(StoreInfo.LastNAME));
                            //getUserEmail      =   (info.getElement(StoreInfo.EMail));
                            //getUserGender         =   (info.getElement(StoreInfo.GenDer));
                            //getUserStatus     =   (info.getElement(StoreInfo.setStatus));
                            getUserCompany      =   (info.getElement(StoreInfo.setCompany));

        collectData = collectData + getUserFirstName+" "+getUserLastName+" "+getUserCompany+ "$";

                    }
                }

        }
            catch(Exception e){}

    return collectData;

    }//end of myList method

    public boolean onClose()
    {
        System.exit(0);
        return true;
    }

}//end of class ListScreen

 class ShowDataScreen extends MainScreen
 {
     String getFirstName;
     String getLastName;
     String getCompany;
     String getEmail;
     String getGender;
     String getStatus;
     String[] getData;
     public ShowDataScreen(String data)
     {
        getData = split(data," ");
        getFirstName = getData[0];
        getLastName = getData[1];
        getCompany = getData[2];
        _data = (Vector) store.getContents();
        try
        {
            for (int i = _data.size()-1; i >-1; i--)
            {
                StoreInfo info = (StoreInfo)_data.elementAt(i);
                if (!_data.isEmpty())
                {
                    if((getFirstName.equalsIgnoreCase(info.getElement(StoreInfo.NAME))) && (getLastName.equalsIgnoreCase(info.getElement(StoreInfo.LastNAME))) && (getCompany.equalsIgnoreCase(info.getElement(StoreInfo.setCompany))))
                    {
                        getEmail = info.getElement(StoreInfo.EMail);
                        getGender = info.getElement(StoreInfo.GenDer);
                        getStatus = info.getElement(StoreInfo.setStatus);

                        HorizontalFieldManager hfManager = new HorizontalFieldManager(HorizontalFieldManager.NON_FOCUSABLE);

                        AutoTextEditField name = new AutoTextEditField("Name: ",getFirstName+" "+getLastName);
                        AutoTextEditField email = new AutoTextEditField("Email: ",getEmail);
                        AutoTextEditField company = new AutoTextEditField("Company: ",getCompany);
                        AutoTextEditField Gender = new AutoTextEditField("Gender: ",getGender);
                        AutoTextEditField status = new AutoTextEditField("Status: ",getStatus);
                        add(name);
                        add(email);
                        add(company);
                        add(Gender);
                        add(status);

                    }
                }

            }//end of for loop
        }//end of try
        catch(Exception e){}

        //Dialog.alert("fname is "+getFirstName+"\nlastname = "+getLastName+" company is "+getCompany);
     }

     public String[] split(String inString, String delimeter) {
            String[] retAr;
            try {
                Vector vec = new Vector();
                int indexA = 0;
                int indexB = inString.indexOf(delimeter);

                while (indexB != -1) {
                    vec.addElement(new String(inString.substring(indexA, indexB)));
                    indexA = indexB + delimeter.length();
                    indexB = inString.indexOf(delimeter, indexA);
                }
                vec.addElement(new String(inString.substring(indexA, inString
                        .length())));
                retAr = new String[vec.size()];
                for (int i = 0; i < vec.size(); i++) {
                    retAr[i] = vec.elementAt(i).toString();
                }
            } catch (Exception e) {
                String[] ar = { e.toString() };
                return ar;
            }
            return retAr;
        }//end of Split Method
 }

 class SearchScreen extends MainScreen
 {
     private ButtonField btnFirstName;
     private ButtonField btnLastName;
     private ButtonField btnSearch;
     private ButtonField btnEmail;
     private SeparatorField sp;
     String userName;
     HorizontalFieldManager hr = new HorizontalFieldManager();

    public AutoTextEditField searchField;

     public SearchScreen()
     {

         sp = new SeparatorField();
         setTitle(new LabelField("your Search Options"));
         add(new RichTextField("Search by : "));

         btnFirstName = new ButtonField("First Name",ButtonField.CONSUME_CLICK);
         hr.add(btnFirstName);

         btnFirstName.setChangeListener(new FieldChangeListener()
                 {
                    public void fieldChanged(Field field, int context)
                    {
                        //HorizontalFieldManager hrs = new HorizontalFieldManager();
                        searchField = new AutoTextEditField("First Name: ","ali");
                        add(searchField);
                        btnSearch = new ButtonField("Search",ButtonField.CONSUME_CLICK);
                        btnSearch.setChangeListener(new FieldChangeListener()
                        {
                            public void fieldChanged(Field field, int context)
                            {
                                //Dialog.alert(searchField.getText());
                                pushScreen(new FirstnameScreen(searchField.getText()));
                                //FirstnameScreen obj = new FirstnameScreen();
                                //obj.name= searchField.getText();

                            }
                        });
                        add(btnSearch);
                        //hrs.add(sp);
                    }
                 });

         btnLastName = new ButtonField("Last Name",ButtonField.CONSUME_CLICK);
         hr.add(btnLastName);
         btnLastName.setChangeListener(new FieldChangeListener()
         {
             public void fieldChanged(Field field, int Context)
             {
                 searchField = new AutoTextEditField("Last Name: ","");
                    add(searchField);
                    btnSearch = new ButtonField("Search",ButtonField.CONSUME_CLICK);
                    btnSearch.setChangeListener(new FieldChangeListener()
                    {
                        public void fieldChanged(Field field, int context)
                        {
                            //Dialog.alert(searchField.getText());
                            pushScreen(new LastnameScreen(searchField.getText()));
                            //FirstnameScreen obj = new FirstnameScreen();
                            //obj.name= searchField.getText();

                        }
                    });
                    add(btnSearch);

             }
         });
         btnEmail = new ButtonField("Email",ButtonField.CONSUME_CLICK);
         hr.add(btnEmail);
         btnEmail.setChangeListener(new FieldChangeListener()
         {
             public void fieldChanged(Field field, int Context)
             {
                 searchField = new AutoTextEditField("Email: ","");
                    add(searchField);
                    btnSearch = new ButtonField("Search",ButtonField.CONSUME_CLICK);
                    btnSearch.setChangeListener(new FieldChangeListener()
                    {
                        public void fieldChanged(Field field, int context)
                        {
                            //Dialog.alert(searchField.getText());
                            pushScreen(new EmailScreen(searchField.getText()));
                            //FirstnameScreen obj = new FirstnameScreen();
                            //obj.name= searchField.getText();

                        }
                    });
                    add(btnSearch);
             }
         });
         add(hr);

     }
     void myShow()
     {
         Dialog.alert(searchField.getText());
     }
 }

 class FirstnameScreen extends MainScreen
 {
     String userName;
     private Manager mGrid;
     String firstUserName;
     String lastUserName;
     String userEmail;
     String userGender;
     String userStatus;
     ButtonField btnBack;
     Font font;

     public FirstnameScreen(String name)
     {
         setTitle(new LabelField("your Search Results"));
         add(new RichTextField("Search results for"+name));
         userName = name;
         searchFirstName();
         btnBack = new ButtonField("Back",ButtonField.CONSUME_CLICK);
         btnBack.setChangeListener(new FieldChangeListener()
         {
             public void fieldChanged(Field field, int context)
             {
                 UiApplication.getUiApplication().popScreen(getScreen());
             }
         });
         add(btnBack);

     }

     public void searchFirstName()
     {

         ButtonField btnDelete;
            if (null != mGrid && null != mGrid.getManager())
                mGrid.getManager().delete(mGrid);
        int colWidth = net.rim.device.api.system.Display.getWidth() / 4;
        mGrid = new GridFieldManager(new int[] { 0, colWidth, colWidth,
                        colWidth, colWidth }, VERTICAL_SCROLL | VERTICAL_SCROLLBAR);
        mGrid.add(new NullField(FOCUSABLE));
        mGrid.add(new LabelField("Name"));
        mGrid.add(new LabelField("E-Mail"));
        mGrid.add(new LabelField("Gender"));
        mGrid.add(new LabelField("Active"));
        //mGrid.add(new ButtonField("Delete"));

        //SeparatorField sps = new SeparatorField();
        //mGrid.add(sps);
        add(mGrid);
        _data = (Vector) store.getContents();
        try {

                for (int i = _data.size() - 1; i > -1; i--) {

                        StoreInfo info = (StoreInfo) _data.elementAt(i);
                        // checking for empty object
                        if (!_data.isEmpty()) {

                            firstUserName = (info.getElement(StoreInfo.NAME));
                            if(firstUserName.equalsIgnoreCase(userName))
                            {
                                // if not empty
                                // create a new object of Store Info class

                                // stored information retrieved in strings

                                lastUserName = (info.getElement(StoreInfo.LastNAME));
                                userEmail = (info.getElement(StoreInfo.EMail));
                                userGender = (info.getElement(StoreInfo.GenDer));
                                userStatus = (info.getElement(StoreInfo.setStatus));
                                final int sn = i;

                                // calling the listAll method
                                mGrid.add(new NullField(FOCUSABLE));
                                mGrid.add(new LabelField(firstUserName + " "
                                                + lastUserName));
                                mGrid.add(new LabelField(userEmail));
                                mGrid.add(new LabelField(userGender));
                                mGrid.add(new LabelField(userStatus));
                                btnDelete = new ButtonField("Delete",ButtonField.CONSUME_CLICK);
                                btnDelete.setChangeListener(new FieldChangeListener()
                                {
                                    public void fieldChanged(Field field, int context)
                                    {
                                        _data.removeElementAt(sn);
                                    }
                                });
                                add(btnDelete);

                               // SeparatorField sps1 = new SeparatorField();
                                //mGrid.add(sps1);

                            }

                        }

                }
        } catch (Exception e) {
        }

     }
 }

 class LastnameScreen extends MainScreen
 {

     String userName;
     private Manager mGrid;
     String firstUserName;
     String lastUserName;
     String userEmail;
     String userGender;
     String userStatus;
     ButtonField btnBack;
     Font font;

     public LastnameScreen(String name)
     {
         setTitle(new LabelField("your Search Results"));

         add(new RichTextField("Search results for"+name));
         userName = name;
         searchLastName();
         btnBack = new ButtonField("Back",ButtonField.CONSUME_CLICK);
         btnBack.setChangeListener(new FieldChangeListener()
         {
             public void fieldChanged(Field field, int context)
             {
                 UiApplication.getUiApplication().popScreen(getScreen());
             }
         });
         add(btnBack);
     }

     public void searchLastName()
     {

         ButtonField btnDelete;
            if (null != mGrid && null != mGrid.getManager())
                mGrid.getManager().delete(mGrid);
        int colWidth = net.rim.device.api.system.Display.getWidth() / 4;
        mGrid = new GridFieldManager(new int[] { 0, colWidth, colWidth,
                        colWidth, colWidth }, VERTICAL_SCROLL | VERTICAL_SCROLLBAR);
        mGrid.add(new NullField(FOCUSABLE));
        mGrid.add(new LabelField("Name"));
        mGrid.add(new LabelField("E-Mail"));
        mGrid.add(new LabelField("Gender"));
        mGrid.add(new LabelField("Active"));
        //mGrid.add(new ButtonField("Delete"));

        //SeparatorField sps = new SeparatorField();
        //mGrid.add(sps);
        add(mGrid);
        _data = (Vector) store.getContents();
        try {

                for (int i = _data.size() - 1; i > -1; i--) {

                        StoreInfo info = (StoreInfo) _data.elementAt(i);
                        // checking for empty object
                        if (!_data.isEmpty()) {

                               lastUserName = (info.getElement(StoreInfo.LastNAME));
                            if(lastUserName.equalsIgnoreCase(userName))
                            {
                                // if not empty
                                // create a new object of Store Info class

                                // stored information retrieved in strings
                                firstUserName = (info.getElement(StoreInfo.NAME));

                                userEmail = (info.getElement(StoreInfo.EMail));
                                userGender = (info.getElement(StoreInfo.GenDer));
                                userStatus = (info.getElement(StoreInfo.setStatus));
                                final int sn = i;

                                // calling the listAll method
                                mGrid.add(new NullField(FOCUSABLE));
                                mGrid.add(new LabelField(firstUserName + " "
                                                + lastUserName));
                                mGrid.add(new LabelField(userEmail));
                                mGrid.add(new LabelField(userGender));
                                mGrid.add(new LabelField(userStatus));
                                btnDelete = new ButtonField("Delete",ButtonField.CONSUME_CLICK);
                                btnDelete.setChangeListener(new FieldChangeListener()
                                {
                                    public void fieldChanged(Field field, int context)
                                    {
                                        _data.removeElementAt(sn);
                                    }
                                });
                                add(btnDelete);

                               // SeparatorField sps1 = new SeparatorField();
                                //mGrid.add(sps1);

                            }

                        }

                }
        } catch (Exception e) {
        }

     }
 }
 class EmailScreen extends MainScreen
 {
     String userName;
     private Manager mGrid;
     String firstUserName;
     String lastUserName;
     String userEmail;
     String userGender;
     String userStatus;
     ButtonField btnBack;
     Font font;

     public EmailScreen(String mail)
     {
         setTitle(new LabelField("your Search Results"));
         add(new RichTextField("Search results for"+mail));
         userName = mail;
         searchEmail();
         btnBack = new ButtonField("Back",ButtonField.CONSUME_CLICK);
         btnBa
```

答:
What are the benefits of integrating with the built-in alarm application? Would it be better for your application to place an event in the device's calendar and make the event show a reminder?

If you have to have a more prominent alarm, why not do it yourself? An alarm is an action the phone does (either make a sound and/or vibrate) that shows on the screen why it is taking that action and the action stops when someone responds to it.

Can you just make an app that starts in the background, checks the day, and makes a sound/vibrates on that day?

The default Alarm app on my phone only supports one time to ring. If I set it to wake me up at 4 a.m., but your app reschedules the alarm on my phone for 8 a.m., you would instantly lose a customer (after I wake up 4 hours too late).

Title: BlackBerry Alarm Integeration

Body:
Below is my application code. i want alarm to ring on my blackberry on every 6 of this month whether this apllication is running or not. please guide me in details i am a beginner.

import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.system.*;
import net.rim.device.api.util.*;

import java.util.*;

import java.lang.String.*;

public class ListChk extends UiApplication
{
    String getFirstName;
    String getLastName;
    String getEmail;
    String getGender;
    String getStatus;
    String getCompany;

    /*declaring text fields for user input*/
    private AutoTextEditField firstName;

    private AutoTextEditField lastName;
    private AutoTextEditField company;

    private EmailAddressEditField email;

    /*declaring choice field for user input*/

    private ObjectChoiceField gender;

    /*declaring check box field for user input*/
    private CheckboxField status;

    //Declaring button fields
    private ButtonField save;
    private ButtonField close;
    private ButtonField List;
    private ButtonField search;

    /*declaring vector*/
    private static Vector _data;

    /*declaring persistent object*/
    private static PersistentObject store;

    /*creating an entry point*/
    public static void main(String[] args)

    {
        ListChk objListChk = new ListChk();
        objListChk.enterEventDispatcher();

    }//end of main of ListChk

    public ListChk()
    {

        /*Creating an object of the main screen class to use its functionalities*/
        MainScreen mainScreen = new MainScreen();

        //setting title of the main screen
        mainScreen.setTitle(new LabelField("Enter Your Data"));

        //creating text fields for user input
        firstName = new AutoTextEditField("First Name: ", "");
        lastName= new AutoTextEditField("Last Name: ", "");
        email= new EmailAddressEditField("Email:: ", "");
        company = new AutoTextEditField("Company: ", "");

        //creating choice field for user input
        String [] items = {"Male","Female"};
        gender= new ObjectChoiceField("Gender",items);

        //creating Check box field
        status = new CheckboxField("Active",true);

        //creating Button fields and adding functionality using listeners

        // A button that saves the the user data persistently when it is clicked
        save = new ButtonField("Save",ButtonField.CONSUME_CLICK);
        save.setChangeListener(new FieldChangeListener()
        {
            public void fieldChanged(Field field, int context)
            {
                save();

            }
        });

        // a button which closes the entire application when clicked
        close = new ButtonField("Close",ButtonField.CONSUME_CLICK);
        close.setChangeListener(new FieldChangeListener()
        {
            public void fieldChanged(Field field, int context)
            {
                onClose();
            }
        });

        // A button that shows the List of all Data being stored persistently
        List = new ButtonField("List",ButtonField.CONSUME_CLICK);
        List.setChangeListener(new FieldChangeListener()
        {
            public void fieldChanged(Field field, int context){
                // pushing the next screen

                pushScreen(new ListScreen());

            }
        });

        search = new ButtonField("Search",ButtonField.CONSUME_CLICK);
        search.setChangeListener(new FieldChangeListener()
        {
            public void fieldChanged(Field field, int context)
            {
                pushScreen(new SearchScreen());
            }
        });
        //adding the input fields to the main screen
        mainScreen.add(firstName);
        mainScreen.add(lastName);
        mainScreen.add(email);
        mainScreen.add(company);
        mainScreen.add(gender);
        mainScreen.add(status);

        // Addning horizontal field manager
        HorizontalFieldManager horizontal = new HorizontalFieldManager(HorizontalFieldManager.FIELD_HCENTER);

        //adding buttons to the main screen in Horizontal field manager

        horizontal.add(close);
        horizontal.add(save);
        horizontal.add(List);
        horizontal.add(search);

        //Adding the horizontal field manger to the screen
        mainScreen.add(horizontal);

        //adding menu items

        mainScreen.addMenuItem(saveItem);
        mainScreen.addMenuItem(getItem);
        mainScreen.addMenuItem(Deleteall);

        //pushing the main screen
        pushScreen(mainScreen);
    }
    private MenuItem Deleteall = new MenuItem("Delete all",110,10)
    {
        public void run()
        {
            int response = Dialog.ask(Dialog.D_YES_NO,"Are u sure u want to delete entire Database");
            if(Dialog.YES == response){
            PersistentStore.destroyPersistentObject(0xdec6a67096f833cL);
            Dialog.alert("Closing Application");
            onClose();
            }
            else
                Dialog.inform("Thank God");
        }
    };
//adding functionality to menu item "saveItem"
private MenuItem saveItem = new MenuItem("Save", 110, 10)
{

        public void run()
        {
            //Calling save method
            save();
        }
};
//adding functionality to menu item "saveItem"
private MenuItem getItem = new MenuItem("Get", 110, 11)
{
    //running thread for this menu item
    public void run()
    {

            //synchronizing thread
            synchronized (store)
            {
                //getting contents of the persistent object

                _data = (Vector) store.getContents();
                try{

                    for (int i = _data.size()-1; i >-1; i--)
                    {

                        StoreInfo info = (StoreInfo)_data.elementAt(i);
                        //checking for empty object
                        if (!_data.isEmpty())
                        {
                        //if not empty
                        //create a new object of Store Info class

                        //storing information retrieved in strings
                        getFirstName    =   (info.getElement(StoreInfo.NAME));
                        getLastName     =   (info.getElement(StoreInfo.LastNAME));
                        getEmail        =   (info.getElement(StoreInfo.EMail));
                        getGender       =   (info.getElement(StoreInfo.GenDer));
                        getStatus       =   (info.getElement(StoreInfo.setStatus));
                        getCompany      =   (info.getElement(StoreInfo.setCompany));
                            //calling the show method
                        show();
                        }

                    }
                }
                catch(Exception e){}
            }
        }

};
public void save()
{

    //creating an object of inner class StoreInfo
    StoreInfo info = new StoreInfo();
    //getting the test entered in the input fields
    info.setElement(StoreInfo.NAME, firstName.getText());
    info.setElement(StoreInfo.LastNAME,lastName.getText());
    info.setElement(StoreInfo.EMail, email.getText());
    info.setElement(StoreInfo.setCompany, company.getText());
    info.setElement(StoreInfo.GenDer,gender.toString());
    if(status.getChecked())
        info.setElement(StoreInfo.setStatus, "Active");
    else
        info.setElement(StoreInfo.setStatus, "In Active");
    //adding the object to the end of the vector
    _data.addElement(info);
    //synchronizing the thread
    synchronized (store)
    {

        store.setContents(_data);
        store.commit();

    }
    //resetting the input fields

    Dialog.inform("Success!");
    firstName.setText(null);
    lastName.setText(null);
    email.setText("");
    company.setText(null);
    gender.setSelectedIndex("Male");
    status.setChecked(true);

}
//coding for persistent store
static {

store =
PersistentStore.getPersistentObject(0xdec6a67096f833cL);
synchronized (store) {
if (store.getContents() == null) {
store.setContents(new Vector());
store.commit();
}
}
_data = new Vector();
_data = (Vector) store.getContents();

}
//new class store info implementing persistable
private static final class StoreInfo implements Persistable
{
    //declaring variables
    private Vector _elements;
    public static final int NAME = 0;
    public static final int LastNAME = 1;
    public static final int EMail= 2;
    public static final int GenDer = 3;
    public static final int setStatus = 4;
    public static final int setCompany = 5;
    public StoreInfo()
    {
        _elements = new Vector(6);
        for (int i = 0; i < _elements.capacity(); ++i)
        {
            _elements.addElement(new String(""));
        }
    }

    public String getElement(int id)
    {
        return (String) _elements.elementAt(id);
    }
    public void setElement(int id, String value)
    {
        _elements.setElementAt(value, id);
    }
}
//details for show method
public void show()
{
    Dialog.alert("Name is "+getFirstName+" "+getLastName+"\nGender is "+getGender+"\nE-mail: "+getEmail+"\nStatus is "+getStatus);
}
public void list()
{

    Dialog.alert("haha");

}

//creating save method

//overriding onClose method

public boolean onClose()
{

    System.exit(0);
    return true;
}

 class ListScreen extends MainScreen
{
     String getUserFirstName;
     String getUserLastName;
     String getUserEmail;
     String getUserGender;
     String getUserStatus;
     String getUserCompany;
     String[] setData ;
     String getData = new String();
     String collectData = "";
     ObjectListField fldList;
     int counter = 0;

    private ButtonField btnBack;

    public ListScreen()
    {

        setTitle(new LabelField("Showing Data",LabelField.NON_FOCUSABLE));
        //getData = myList();
        //Dialog.alert(getData);

    //  setData = split(getData,"$");
    //  for(int i = 0;i<setData.length;i++)
    //  {
    //      add(new RichTextField(setData[i]+"@@@@@"));
    //  }
        showList();
        btnBack = new ButtonField("Back",ButtonField.CONSUME_CLICK|ButtonField.FIELD_HCENTER);
        btnBack.setChangeListener(new FieldChangeListener()
        {
            public void fieldChanged(Field field,int context)
            {
                UiApplication.getUiApplication().popScreen(getScreen());
            }
        });

        add(btnBack);

    }

    public void showList()
    {
        HorizontalFieldManager hfManager = new HorizontalFieldManager(HorizontalFieldManager.HORIZONTAL_SCROLLBAR|HorizontalFieldManager.HORIZONTAL_SCROLL);
        //SeparatorField spManager = new SeparatorField();
        LabelField lblcheck = new LabelField("check",LabelField.NON_FOCUSABLE);
        getData = myList();
        setData = split(getData,"$");
        fldList = new ObjectListField(ObjectListField.MULTI_SELECT);
        fldList.set(setData);
        //fldList.setEmptyString("heloo", 12);
        //hfManager.add(lblcheck);

        hfManager.add(fldList);
        //hfManager.add(spManager);
        add(hfManager);
        addMenuItem(new MenuItem("Select", 100, 1) {
            public void run() {
                int selectedIndex = fldList.getSelectedIndex();
                String item = (String)fldList.get(fldList, selectedIndex);
               pushScreen(new ShowDataScreen(item));
            }
            });

    }

    public String[] split(String inString, String delimeter) {
        String[] retAr;
        try {
            Vector vec = new Vector();
            int indexA = 0;
            int indexB = inString.indexOf(delimeter);

            while (indexB != -1) {
                vec.addElement(new String(inString.substring(indexA, indexB)));
                indexA = indexB + delimeter.length();
                indexB = inString.indexOf(delimeter, indexA);
            }
            vec.addElement(new String(inString.substring(indexA, inString
                    .length())));
            retAr = new String[vec.size()];
            for (int i = 0; i < vec.size(); i++) {
                retAr[i] = vec.elementAt(i).toString();
            }
        } catch (Exception e) {
            String[] ar = { e.toString() };
            return ar;
        }
        return retAr;
    }//end of Split Method

    public String myList()
    {

        _data = (Vector) store.getContents();
        try
        {
            for (int i = _data.size()-1; i >-1; i--,counter++)
                {

                    StoreInfo info = (StoreInfo)_data.elementAt(i);
                    //checking for empty object
                    if (!_data.isEmpty())
                        {
                            //if not empty
                            //create a new object of Store Info class

                            //storing information retrieved in strings
                            //StoreInfo info = (StoreInfo)_data.lastElement();
                            getUserFirstName    =   (info.getElement(StoreInfo.NAME));
                            getUserLastName     =   (info.getElement(StoreInfo.LastNAME));
                            //getUserEmail      =   (info.getElement(StoreInfo.EMail));
                            //getUserGender         =   (info.getElement(StoreInfo.GenDer));
                            //getUserStatus     =   (info.getElement(StoreInfo.setStatus));
                            getUserCompany      =   (info.getElement(StoreInfo.setCompany));

        collectData = collectData + getUserFirstName+" "+getUserLastName+" "+getUserCompany+ "$";

                    }
                }

        }
            catch(Exception e){}

    return collectData;

    }//end of myList method

    public boolean onClose()
    {
        System.exit(0);
        return true;
    }

}//end of class ListScreen

 class ShowDataScreen extends MainScreen
 {
     String getFirstName;
     String getLastName;
     String getCompany;
     String getEmail;
     String getGender;
     String getStatus;
     String[] getData;
     public ShowDataScreen(String data)
     {
        getData = split(data," ");
        getFirstName = getData[0];
        getLastName = getData[1];
        getCompany = getData[2];
        _data = (Vector) store.getContents();
        try
        {
            for (int i = _data.size()-1; i >-1; i--)
            {
                StoreInfo info = (StoreInfo)_data.elementAt(i);
                if (!_data.isEmpty())
                {
                    if((getFirstName.equalsIgnoreCase(info.getElement(StoreInfo.NAME))) && (getLastName.equalsIgnoreCase(info.getElement(StoreInfo.LastNAME))) && (getCompany.equalsIgnoreCase(info.getElement(StoreInfo.setCompany))))
                    {
                        getEmail = info.getElement(StoreInfo.EMail);
                        getGender = info.getElement(StoreInfo.GenDer);
                        getStatus = info.getElement(StoreInfo.setStatus);

                        HorizontalFieldManager hfManager = new HorizontalFieldManager(HorizontalFieldManager.NON_FOCUSABLE);

                        AutoTextEditField name = new AutoTextEditField("Name: ",getFirstName+" "+getLastName);
                        AutoTextEditField email = new AutoTextEditField("Email: ",getEmail);
                        AutoTextEditField company = new AutoTextEditField("Company: ",getCompany);
                        AutoTextEditField Gender = new AutoTextEditField("Gender: ",getGender);
                        AutoTextEditField status = new AutoTextEditField("Status: ",getStatus);
                        add(name);
                        add(email);
                        add(company);
                        add(Gender);
                        add(status);

                    }
                }

            }//end of for loop
        }//end of try
        catch(Exception e){}

        //Dialog.alert("fname is "+getFirstName+"\nlastname = "+getLastName+" company is "+getCompany);
     }

     public String[] split(String inString, String delimeter) {
            String[] retAr;
            try {
                Vector vec = new Vector();
                int indexA = 0;
                int indexB = inString.indexOf(delimeter);

                while (indexB != -1) {
                    vec.addElement(new String(inString.substring(indexA, indexB)));
                    indexA = indexB + delimeter.length();
                    indexB = inString.indexOf(delimeter, indexA);
                }
                vec.addElement(new String(inString.substring(indexA, inString
                        .length())));
                retAr = new String[vec.size()];
                for (int i = 0; i < vec.size(); i++) {
                    retAr[i] = vec.elementAt(i).toString();
                }
            } catch (Exception e) {
                String[] ar = { e.toString() };
                return ar;
            }
            return retAr;
        }//end of Split Method
 }

 class SearchScreen extends MainScreen
 {
     private ButtonField btnFirstName;
     private ButtonField btnLastName;
     private ButtonField btnSearch;
     private ButtonField btnEmail;
     private SeparatorField sp;
     String userName;
     HorizontalFieldManager hr = new HorizontalFieldManager();

    public AutoTextEditField searchField;

     public SearchScreen()
     {

         sp = new SeparatorField();
         setTitle(new LabelField("your Search Options"));
         add(new RichTextField("Search by : "));

         btnFirstName = new ButtonField("First Name",ButtonField.CONSUME_CLICK);
         hr.add(btnFirstName);

         btnFirstName.setChangeListener(new FieldChangeListener()
                 {
                    public void fieldChanged(Field field, int context)
                    {
                        //HorizontalFieldManager hrs = new HorizontalFieldManager();
                        searchField = new AutoTextEditField("First Name: ","ali");
                        add(searchField);
                        btnSearch = new ButtonField("Search",ButtonField.CONSUME_CLICK);
                        btnSearch.setChangeListener(new FieldChangeListener()
                        {
                            public void fieldChanged(Field field, int context)
                            {
                                //Dialog.alert(searchField.getText());
                                pushScreen(new FirstnameScreen(searchField.getText()));
                                //FirstnameScreen obj = new FirstnameScreen();
                                //obj.name= searchField.getText();

                            }
                        });
                        add(btnSearch);
                        //hrs.add(sp);
                    }
                 });

         btnLastName = new ButtonField("Last Name",ButtonField.CONSUME_CLICK);
         hr.add(btnLastName);
         btnLastName.setChangeListener(new FieldChangeListener()
         {
             public void fieldChanged(Field field, int Context)
             {
                 searchField = new AutoTextEditField("Last Name: ","");
                    add(searchField);
                    btnSearch = new ButtonField("Search",ButtonField.CONSUME_CLICK);
                    btnSearch.setChangeListener(new FieldChangeListener()
                    {
                        public void fieldChanged(Field field, int context)
                        {
                            //Dialog.alert(searchField.getText());
                            pushScreen(new LastnameScreen(searchField.getText()));
                            //FirstnameScreen obj = new FirstnameScreen();
                            //obj.name= searchField.getText();

                        }
                    });
                    add(btnSearch);

             }
         });
         btnEmail = new ButtonField("Email",ButtonField.CONSUME_CLICK);
         hr.add(btnEmail);
         btnEmail.setChangeListener(new FieldChangeListener()
         {
             public void fieldChanged(Field field, int Context)
             {
                 searchField = new AutoTextEditField("Email: ","");
                    add(searchField);
                    btnSearch = new ButtonField("Search",ButtonField.CONSUME_CLICK);
                    btnSearch.setChangeListener(new FieldChangeListener()
                    {
                        public void fieldChanged(Field field, int context)
                        {
                            //Dialog.alert(searchField.getText());
                            pushScreen(new EmailScreen(searchField.getText()));
                            //FirstnameScreen obj = new FirstnameScreen();
                            //obj.name= searchField.getText();

                        }
                    });
                    add(btnSearch);
             }
         });
         add(hr);

     }
     void myShow()
     {
         Dialog.alert(searchField.getText());
     }
 }

 class FirstnameScreen extends MainScreen
 {
     String userName;
     private Manager mGrid;
     String firstUserName;
     String lastUserName;
     String userEmail;
     String userGender;
     String userStatus;
     ButtonField btnBack;
     Font font;

     public FirstnameScreen(String name)
     {
         setTitle(new LabelField("your Search Results"));
         add(new RichTextField("Search results for"+name));
         userName = name;
         searchFirstName();
         btnBack = new ButtonField("Back",ButtonField.CONSUME_CLICK);
         btnBack.setChangeListener(new FieldChangeListener()
         {
             public void fieldChanged(Field field, int context)
             {
                 UiApplication.getUiApplication().popScreen(getScreen());
             }
         });
         add(btnBack);

     }

     public void searchFirstName()
     {

         ButtonField btnDelete;
            if (null != mGrid && null != mGrid.getManager())
                mGrid.getManager().delete(mGrid);
        int colWidth = net.rim.device.api.system.Display.getWidth() / 4;
        mGrid = new GridFieldManager(new int[] { 0, colWidth, colWidth,
                        colWidth, colWidth }, VERTICAL_SCROLL | VERTICAL_SCROLLBAR);
        mGrid.add(new NullField(FOCUSABLE));
        mGrid.add(new LabelField("Name"));
        mGrid.add(new LabelField("E-Mail"));
        mGrid.add(new LabelField("Gender"));
        mGrid.add(new LabelField("Active"));
        //mGrid.add(new ButtonField("Delete"));

        //SeparatorField sps = new SeparatorField();
        //mGrid.add(sps);
        add(mGrid);
        _data = (Vector) store.getContents();
        try {

                for (int i = _data.size() - 1; i > -1; i--) {

                        StoreInfo info = (StoreInfo) _data.elementAt(i);
                        // checking for empty object
                        if (!_data.isEmpty()) {

                            firstUserName = (info.getElement(StoreInfo.NAME));
                            if(firstUserName.equalsIgnoreCase(userName))
                            {
                                // if not empty
                                // create a new object of Store Info class

                                // stored information retrieved in strings

                                lastUserName = (info.getElement(StoreInfo.LastNAME));
                                userEmail = (info.getElement(StoreInfo.EMail));
                                userGender = (info.getElement(StoreInfo.GenDer));
                                userStatus = (info.getElement(StoreInfo.setStatus));
                                final int sn = i;

                                // calling the listAll method
                                mGrid.add(new NullField(FOCUSABLE));
                                mGrid.add(new LabelField(firstUserName + " "
                                                + lastUserName));
                                mGrid.add(new LabelField(userEmail));
                                mGrid.add(new LabelField(userGender));
                                mGrid.add(new LabelField(userStatus));
                                btnDelete = new ButtonField("Delete",ButtonField.CONSUME_CLICK);
                                btnDelete.setChangeListener(new FieldChangeListener()
                                {
                                    public void fieldChanged(Field field, int context)
                                    {
                                        _data.removeElementAt(sn);
                                    }
                                });
                                add(btnDelete);

                               // SeparatorField sps1 = new SeparatorField();
                                //mGrid.add(sps1);

                            }

                        }

                }
        } catch (Exception e) {
        }

     }
 }

 class LastnameScreen extends MainScreen
 {

     String userName;
     private Manager mGrid;
     String firstUserName;
     String lastUserName;
     String userEmail;
     String userGender;
     String userStatus;
     ButtonField btnBack;
     Font font;

     public LastnameScreen(String name)
     {
         setTitle(new LabelField("your Search Results"));

         add(new RichTextField("Search results for"+name));
         userName = name;
         searchLastName();
         btnBack = new ButtonField("Back",ButtonField.CONSUME_CLICK);
         btnBack.setChangeListener(new FieldChangeListener()
         {
             public void fieldChanged(Field field, int context)
             {
                 UiApplication.getUiApplication().popScreen(getScreen());
             }
         });
         add(btnBack);
     }

     public void searchLastName()
     {

         ButtonField btnDelete;
            if (null != mGrid && null != mGrid.getManager())
                mGrid.getManager().delete(mGrid);
        int colWidth = net.rim.device.api.system.Display.getWidth() / 4;
        mGrid = new GridFieldManager(new int[] { 0, colWidth, colWidth,
                        colWidth, colWidth }, VERTICAL_SCROLL | VERTICAL_SCROLLBAR);
        mGrid.add(new NullField(FOCUSABLE));
        mGrid.add(new LabelField("Name"));
        mGrid.add(new LabelField("E-Mail"));
        mGrid.add(new LabelField("Gender"));
        mGrid.add(new LabelField("Active"));
        //mGrid.add(new ButtonField("Delete"));

        //SeparatorField sps = new SeparatorField();
        //mGrid.add(sps);
        add(mGrid);
        _data = (Vector) store.getContents();
        try {

                for (int i = _data.size() - 1; i > -1; i--) {

                        StoreInfo info = (StoreInfo) _data.elementAt(i);
                        // checking for empty object
                        if (!_data.isEmpty()) {

                               lastUserName = (info.getElement(StoreInfo.LastNAME));
                            if(lastUserName.equalsIgnoreCase(userName))
                            {
                                // if not empty
                                // create a new object of Store Info class

                                // stored information retrieved in strings
                                firstUserName = (info.getElement(StoreInfo.NAME));

                                userEmail = (info.getElement(StoreInfo.EMail));
                                userGender = (info.getElement(StoreInfo.GenDer));
                                userStatus = (info.getElement(StoreInfo.setStatus));
                                final int sn = i;

                                // calling the listAll method
                                mGrid.add(new NullField(FOCUSABLE));
                                mGrid.add(new LabelField(firstUserName + " "
                                                + lastUserName));
                                mGrid.add(new LabelField(userEmail));
                                mGrid.add(new LabelField(userGender));
                                mGrid.add(new LabelField(userStatus));
                                btnDelete = new ButtonField("Delete",ButtonField.CONSUME_CLICK);
                                btnDelete.setChangeListener(new FieldChangeListener()
                                {
                                    public void fieldChanged(Field field, int context)
                                    {
                                        _data.removeElementAt(sn);
                                    }
                                });
                                add(btnDelete);

                               // SeparatorField sps1 = new SeparatorField();
                                //mGrid.add(sps1);

                            }

                        }

                }
        } catch (Exception e) {
        }

     }
 }
 class EmailScreen extends MainScreen
 {
     String userName;
     private Manager mGrid;
     String firstUserName;
     String lastUserName;
     String userEmail;
     String userGender;
     String userStatus;
     ButtonField btnBack;
     Font font;

     public EmailScreen(String mail)
     {
         setTitle(new LabelField("your Search Results"));
         add(new RichTextField("Search results for"+mail));
         userName = mail;
         searchEmail();
         btnBack = new ButtonField("Back",ButtonField.CONSUME_CLICK);
         btnBa


来源: stackexchange

问:
Select from multiple table with knex.js
How to run this query:

```<code>select * from table1, table2;
</code>```

with knex.js?

I've tried this:

```<code>const knex = require('knex')({
  client: 'sqlite3',
  connection: { filename: ':memory:' },
})

async function main() {
  await knex.schema.createTable('table1', table => table.string('field1'))
  await knex.schema.createTable('table2', table => table.string('field2'))
  await knex.insert({ field1: 'value' }).into('table1')
  await knex.insert({ field2: 'value' }).into('table2')
  await knex.from('table1', 'table2')   // first attempt
  await knex.from(['table1', 'table2']) // second attempt
}

main().catch(err => {
  console.error(err)
})
</code>```

I run that code with env DEBUG='knex:query' and got this output:

```<code>create table `table1` (`field1` varchar(255))
create table `table2` (`field2` varchar(255))
insert into `table1` (`field1`) values (?)
insert into `table2` (`field2`) values (?)
select * from `table1`
select * from `table1` as `0`, `table2` as `1`
</code>```

clearly, the select statement is not what I expected.

PS:

in case you mark this question is a duplicate of this one, it is not.
the main point of question is different and the answer in that question
doesn't answer my question.

答:
One can always use knex.raw for database-specific and any other complicated custom logic.

Try this one (it produces desired output):

```<code>knex
    .select('*')
    .from(knex.raw('table1, table2'))
</code>```

ContentLicense: CC BY-SA 3.0

Title: Select from multiple table with knex.js

Body:
How to run this query:

select * from table1, table2;

with knex.js?

I've tried this:

const knex = require('knex')({
  client: 'sqlite3',
  connection: { filename: ':memory:' },
})

async function main() {
  await knex.schema.createTable('table1', table => table.string('field1'))
  await knex.schema.createTable('table2', table => table.string('field2'))
  await knex.insert({ field1: 'value' }).into('table1')
  await knex.insert({ field2: 'value' }).into('table2')
  await knex.from('table1', 'table2')   // first attempt
  await knex.from(['table1', 'table2']) // second attempt
}

main().catch(err => {
  console.error(err)
})

I run that code with env DEBUG='knex:query' and got this output:

create table `table1` (`field1` varchar(255))
create table `table2` (`field2` varchar(255))
insert into `table1` (`field1`) values (?)
insert into `table2` (`field2`) values (?)
select * from `table1`
select * from `table1` as `0`, `table2` as `1`

clearly, the select statement is not what I expected.

PS:

in case you mark this question is a duplicate of this one, it is not.
the main point of question is different and the answer in that question
doesn't answer my question.

Body:
One can always use knex.raw for database-specific and any other complicated custom logic.

Try this one (it produces desired output):

knex
    .select('*')
    .from(knex.raw('table1, table2'))


问:
In which ways is TestCafe better than Selenium?
What problems does TestCafe overcome that justify its adoption over Selenium? Is it worth to port over older test suits to TestCafe?</p>

答:
There are numerous reasons why we at the TestCafe team decided against building TestCafe on top of Selenium.

First, we wanted to simplify setting up the test environment. To start with Selenium, you need to install the WebDriver client for the desired programming language and the appropriate drivers for each browser you're going to test in.

While it sounds rather easy, practically it's quite a hassle to just get started with testing. This hassle becomes even greater if you need to configure your test environment at scale, e.g. for your local CI server.

There are numerous node.js testing solutions based on top of Selenium in npm. You can see that they require some significant amount of setup and configuration work just to get started. This is far from the simplicity of the npm install setup we got used to in other tools from modern web developer’s tool belt.

TestCafe also has some features that wouldn’t be possible if TestCafe used Selenium as an underlying platform. For instance, TestCafe can run tests on remote devices including mobile. This means that you can run tests on a machine that doesn't have TestCafe installed. You only need to open a link in its browser and the testing starts (if the host and target devices see each other in the network). This feature can be used to quickly demonstrate a bug to an engineer that doesn’t have TestCafe or node.js installed at all.

Other features that would be hard to implement on top of Selenium include:

Isolated test environment. Each TestCafe test runs as if it was started in a new incognito tab. You will have all cookies and storages clean. This helps avoid a lot of boilerplate test code and allows you to work in the same browser without the risk of state interference. This also enables us to implement such mechanisms as the upcoming Roles feature with which you’ll be able to interact with the page from different users’ perspective or easily perform form authentication across tests.

Implicit auto-waits mechanism. TestCafe automatically waits for XHR requests, page loads and page animations, so you don’t need to take care of it in your code.

ContentLicense: CC BY-SA 4.0


问:
In C, how can i read data from a text file and insert them an linked list that organised in an ascending order according to the first names?
The text file "mh.txt" includes the following names, surnames, gender and birth
 date of 3 people separated by semicolons.

which look like this:

Tiffany;Evans Smith;F;22/01/1989;

Alex;Williams;M;23/06/1988;

Clay;Bristol;F;30/12/1989;

I want to store every person's details in a node so we'd have 3 nodes in total. All connected in a linked list. Then I want to print the linked list using a print function.

The problem is that my compiler displays the message "fix.exe has stopped working" every time I compile and run!
my c file is called fix.c

This is my attempt:

```<code>#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define FALSE 0
#define TRUE 1

#define SIZE 100

struct Node{

    char  fname[SIZE];
    char sname[SIZE];
    char gender;
    char Byear[SIZE];
    struct Node *next;
};

struct ListRecord
{
    struct Node *head;
    struct Node *tail;
    int size;
};
typedef struct ListRecord List;

List* CreateList(void);
void MakeEmptyList(List *);
void printFriends(List *);
List * initialiseFL(List *);

int main(){

    List *myList;
    int option;
    int exit=FALSE;
    char fname[SIZE];

    myList = CreateList();

    myList=initialiseFL(myList);//reads data from text file and adds nodes
to linked list

    while(!exit){

        fflush(stdin);
        printf("C:>FriendBook friends.txt\n");
        printf("Your FriendBook has been created.\n");
        printf("(1) Insert a new friend\n");
        printf("(2) Print your friends\n");
        printf("(3) Search for your friend\n");
        printf("(4) Block your friend\n");
        printf("(5) Print your blocked friend\n");
        printf("(6) Exit\n");
        printf("Enter your option:");
        printf("\n\n");
        scanf("%d",&option);
        fflush(stdin);

        switch(option){

            case 2:
                printFriends(myList);
                break;

            default:
                printf("Command not recognised!!\n");
                break;

        }
    }

    return 0;
}

List* CreateList(){

    List *l;

    l = (struct ListRecord *) malloc(sizeof(struct ListRecord));
    if (l == NULL)
        printf("Out of memory!\n");

    MakeEmptyList(l);

    return l;
 }

void MakeEmptyList(List *l)
{
    l->head = (struct Node *) malloc(sizeof(struct Node));
    if (l->head == NULL)
        printf("Out of memory!\n");

    l->head->next = NULL;
    l->tail = l->head;
    l->size = 0;
}
List* initialiseFL(List *l){

    FILE *IN;

    IN =fopen("mh.txt", "r");

    if (IN == NULL){
        printf("Could not open text file!!\n");
    }

    while((fgetc(IN))!=EOF){

        struct Node *p;
        p=(struct Node*) malloc(sizeof(struct Node));

        char temp;
        temp=fgetc(IN);

        int i=0;

        //read first name a char at a time until ;
        while(temp!=';'){

            p->fname[i]=temp;
            i++;
            temp=fgetc(IN);
         }
         p->fname[i]='\0';

         //read second name a char at a time until ;
         temp=fgetc(IN);
         i=0;
         while(temp!=';'){

             p->sname[i]=temp;
             i++;
             temp=fgetc(IN);
         }
         p->sname[i]='\0';

         //read gender from text file
         temp=fgetc(IN);
         p->gender=temp;

         //read birth year from text file
         temp=fgetc(IN);
         temp=fgetc(IN);
         i=0;
         while(temp!=';'){

            p->Byear[i]=temp;
            i++;
            temp=fgetc(IN);
        }
        p->Byear[i]='\0';

        //if list is empty, add node right after the dummy
        if (l->size==0){
            l->head->next=p;
            l->tail=p;
            l->size++;
        }

         //if the list contanins one node after the dummy
         struct Node *first;
         first=l->head->next;
         if(l->size==1){
            if(strcmp(p->fname[0],first->fname[0])>0 && first->next==NULL){
                p->next=NULL;
                first->next=p;
                l->tail=p;
                l->size++;
            }
            else{
                 p->next=first;
                 l->head->next=p;
                 l->size++;
                 first=l->head->next;//reset "first" to point to the 1st
node in the list
            }
         }

         struct Node *second;
         second=first->next;

         //if it is to be added at the beginning
        if(l->size>=2){
            if(strcmp(p->fname[0],first->fname[0])<0){
                p->next=first;
                l->head->next=p;
                l->size++;
                first=l->head->next;//reset "first" to point to the 1st node
in the list
             }

             else{
                while(!(strcmp(p->fname,first->fname)>0 && strcmp(p-
>fname,second->fname)<0 )){
                    first=first->next;
                    second=second->next;
                }
                if(second->next==NULL){
                    p->next=NULL;
                    first->next=p;
                }
                else{
                    p->next=second;
                    first->next=p;
                }

                first=l->head->next;//reset "first" to point to the 1st node
in the list
                second=first->next;//reset "second" to point to the 2st node
in the list
                }

        }

        }
    fclose(IN);

    return l;
}

 void printFriends(List *l){

    //make a temp head that points to the dummy
    struct Node *temp;
    temp=(struct Node*) malloc(sizeof(struct Node));
    temp=l->head->next;

    printf("Your friends are listed below.\n");
    printf("Name\tSurname\tGender\tBirth Year\n");

     while(temp!=NULL){
         printf("%s\t%s\t%c\t%s\n",temp->fname,temp->sname,temp-
>gender,temp->Byear);
        temp=temp->next;
    }

}
</code>```

答:
You can use the code below for your requirement.

What is char Byear[SIZE]; this field? As per your data file, it should be a date field and as forth field in data file is a date.

```<code>#include<stdio.h>
#include<stdlib.h>
#include<string.h>

    struct Friend
    {
            char  *name;
            char  *sur;
            char  *gen;
            char  *date;
            struct Friend *next;
    };

    struct Friend * initializeFL(char *);
    void printFriends(struct Friend *);

    int main()
    {
            printf("\nsdasda\n");
            struct Friend *head;
            char fname[100];
            printf("Enter the name of file .txt:  \t");
            gets(fname);
            head=initializeFL(fname);
            printFriends(head);
    }

    struct Friend * initializeFL(char *fname)
    {
            FILE* fpointer;
            char ch;
            fpointer = fopen(fname,"r");
            if(fpointer == NULL)
            {

                do
                {
                    printf("\nFile not found, please enter the name of file again: \t");
                    gets(fname);
                    fpointer = fopen(fname,"r");
                }while(fpointer == NULL);
            }

            //FILE IS OPENED
            struct Friend *head=NULL;
            struct Friend *t, *p, *q;
            char line[255];
            char sent[2]=";";

            while(!feof(fpointer) && fgets(line,sizeof line,fpointer))
            {
                char *name=strtok(line,sent);
                char *sur=strtok(NULL,sent);
                char *gen=strtok(NULL,sent);
                char *date=strtok(NULL,sent);
                    if(head == NULL)
                    {
                              head=(struct Friend*)malloc(sizeof(struct Friend));
                              t = head;
                              t->name = (char *)malloc(strlen(name));
                              t->sur = (char *)malloc(strlen(sur));
                              t->gen = (char *)malloc(strlen(gen));
                              t->date = (char *)malloc(strlen(date));
                              strcpy(t->name,name);
                              strcpy(t->sur,sur);
                              strcpy(t->gen,gen);
                              strcpy(t->date,date);
                              t->next=NULL;
                    }
                    else
                    {
                            p=(struct Friend*)malloc(sizeof(struct Friend));
                            p->name = (char *)malloc(strlen(name));
                            p->sur = (char *)malloc(strlen(sur));
                            p->gen = (char *)malloc(strlen(gen));
                            p->date = (char *)malloc(strlen(date));
                            strcpy(p->name,name);
                            strcpy(p->sur,sur);
                            strcpy(p->gen,gen);
                            strcpy(p->date,date);
                            p->next=NULL;
                            q = t = head;
                            int i = strcmp(p->name,t->name);
                            printf("i = %d\n",i);
                            while(t!=NULL && strcmp(p->name,t->name)> 0)
                            {
                              q = t;
                              t=t->next;
                            }
                            if(t == head)
                            {
                              p->next=head;
                              head=p;
                            }
                            else
                            {
                              q->next = p;
                              p->next = t;
                            }
                     }
            }
            return head;
    }

    void printFriends(struct Friend *head)
    {
            while(head!=NULL)
            {
                    printf("Name :%s\n",head->name);
                    printf("Surname :%s\n",head->sur);
                    printf("Name :%s\n",head->gen);
                    printf("Name :%s\n",head->date);
                    head=head->next;
            }
    }
</code>```

Body:
The text file "mh.txt" includes the following names, surnames, gender and birth
 date of 3 people separated by semicolons.

which look like this:

Tiffany;Evans Smith;F;22/01/1989;

Alex;Williams;M;23/06/1988;

Clay;Bristol;F;30/12/1989;

I want to store every person's details in a node so we'd have 3 nodes in total. All connected in a linked list. Then I want to print the linked list using a print function.

The problem is that my compiler displays the message "fix.exe has stopped working" every time I compile and run!
my c file is called fix.c

This is my attempt:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define FALSE 0
#define TRUE 1

#define SIZE 100

struct Node{

    char  fname[SIZE];
    char sname[SIZE];
    char gender;
    char Byear[SIZE];
    struct Node *next;
};

struct ListRecord
{
    struct Node *head;
    struct Node *tail;
    int size;
};
typedef struct ListRecord List;

List* CreateList(void);
void MakeEmptyList(List *);
void printFriends(List *);
List * initialiseFL(List *);

int main(){

    List *myList;
    int option;
    int exit=FALSE;
    char fname[SIZE];

    myList = CreateList();

    myList=initialiseFL(myList);//reads data from text file and adds nodes
to linked list

    while(!exit){

        fflush(stdin);
        printf("C:>FriendBook friends.txt\n");
        printf("Your FriendBook has been created.\n");
        printf("(1) Insert a new friend\n");
        printf("(2) Print your friends\n");
        printf("(3) Search for your friend\n");
        printf("(4) Block your friend\n");
        printf("(5) Print your blocked friend\n");
        printf("(6) Exit\n");
        printf("Enter your option:");
        printf("\n\n");
        scanf("%d",&option);
        fflush(stdin);

        switch(option){

            case 2:
                printFriends(myList);
                break;

            default:
                printf("Command not recognised!!\n");
                break;

        }
    }

    return 0;
}

List* CreateList(){

    List *l;

    l = (struct ListRecord *) malloc(sizeof(struct ListRecord));
    if (l == NULL)
        printf("Out of memory!\n");

    MakeEmptyList(l);

    return l;
 }

void MakeEmptyList(List *l)
{
    l->head = (struct Node *) malloc(sizeof(struct Node));
    if (l->head == NULL)
        printf("Out of memory!\n");

    l->head->next = NULL;
    l->tail = l->head;
    l->size = 0;
}
List* initialiseFL(List *l){

    FILE *IN;

    IN =fopen("mh.txt", "r");

    if (IN == NULL){
        printf("Could not open text file!!\n");
    }

    while((fgetc(IN))!=EOF){

        struct Node *p;
        p=(struct Node*) malloc(sizeof(struct Node));

        char temp;
        temp=fgetc(IN);

        int i=0;

        //read first name a char at a time until ;
        while(temp!=';'){

            p->fname[i]=temp;
            i++;
            temp=fgetc(IN);
         }
         p->fname[i]='\0';

         //read second name a char at a time until ;
         temp=fgetc(IN);
         i=0;
         while(temp!=';'){

             p->sname[i]=temp;
             i++;
             temp=fgetc(IN);
         }
         p->sname[i]='\0';

         //read gender from text file
         temp=fgetc(IN);
         p->gender=temp;

         //read birth year from text file
         temp=fgetc(IN);
         temp=fgetc(IN);
         i=0;
         while(temp!=';'){

            p->Byear[i]=temp;
            i++;
            temp=fgetc(IN);
        }
        p->Byear[i]='\0';

        //if list is empty, add node right after the dummy
        if (l->size==0){
            l->head->next=p;
            l->tail=p;
            l->size++;
        }

         //if the list contanins one node after the dummy
         struct Node *first;
         first=l->head->next;
         if(l->size==1){
            if(strcmp(p->fname[0],first->fname[0])>0 && first->next==NULL){
                p->next=NULL;
                first->next=p;
                l->tail=p;
                l->size++;
            }
            else{
                 p->next=first;
                 l->head->next=p;
                 l->size++;
                 first=l->head->next;//reset "first" to point to the 1st
node in the list
            }
         }

         struct Node *second;
         second=first->next;

         //if it is to be added at the beginning
        if(l->size>=2){
            if(strcmp(p->fname[0],first->fname[0])<0){
                p->next=first;
                l->head->next=p;
                l->size++;
                first=l->head->next;//reset "first" to point to the 1st node
in the list
             }

             else{
                while(!(strcmp(p->fname,first->fname)>0 && strcmp(p-
>fname,second->fname)<0 )){
                    first=first->next;
                    second=second->next;
                }
                if(second->next==NULL){
                    p->next=NULL;
                    first->next=p;
                }
                else{
                    p->next=second;
                    first->next=p;
                }

                first=l->head->next;//reset "first" to point to the 1st node
in the list
                second=first->next;//reset "second" to point to the 2st node
in the list
                }

        }

        }
    fclose(IN);

    return l;
}

 void printFriends(List *l){

    //make a temp head that points to the dummy
    struct Node *temp;
    temp=(struct Node*) malloc(sizeof(struct Node));
    temp=l->head->next;

    printf("Your friends are listed below.\n");
    printf("Name\tSurname\tGender\tBirth Year\n");

     while(temp!=NULL){
         printf("%s\t%s\t%c\t%s\n",temp->fname,temp->sname,temp-
>gender,temp->Byear);
        temp=temp->next;
    }

}

Body:
You can use the code below for your requirement.

What is char Byear[SIZE]; this field? As per your data file, it should be a date field and as forth field in data file is a date.

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

    struct Friend
    {
            char  *name;
            char  *sur;
            char  *gen;
            char  *date;
            struct Friend *next;
    };

    struct Friend * initializeFL(char *);
    void printFriends(struct Friend *);

    int main()
    {
            printf("\nsdasda\n");
            struct Friend *head;
            char fname[100];
            printf("Enter the name of file .txt:  \t");
            gets(fname);
            head=initializeFL(fname);
            printFriends(head);
    }

    struct Friend * initializeFL(char *fname)
    {
            FILE* fpointer;
            char ch;
            fpointer = fopen(fname,"r");
            if(fpointer == NULL)
            {

                do
                {
                    printf("\nFile not found, please enter the name of file again: \t");
                    gets(fname);
                    fpointer = fopen(fname,"r");
                }while(fpointer == NULL);
            }

            //FILE IS OPENED
            struct Friend *head=NULL;
            struct Friend *t, *p, *q;
            char line[255];
            char sent[2]=";";

            while(!feof(fpointer) && fgets(line,sizeof line,fpointer))
            {
                char *name=strtok(line,sent);
                char *sur=strtok(NULL,sent);
                char *gen=strtok(NULL,sent);
                char *date=strtok(NULL,sent);
                    if(head == NULL)
                    {
                              head=(struct Friend*)malloc(sizeof(struct Friend));
                              t = head;
                              t->name = (char *)malloc(strlen(name));
                              t->sur = (char *)malloc(strlen(sur));
                              t->gen = (char *)malloc(strlen(gen));
                              t->date = (char *)malloc(strlen(date));
                              strcpy(t->name,name);
                              strcpy(t->sur,sur);
                              strcpy(t->gen,gen);
                              strcpy(t->date,date);
                              t->next=NULL;
                    }
                    else
                    {
                            p=(struct Friend*)malloc(sizeof(struct Friend));
                            p->name = (char *)malloc(strlen(name));
                            p->sur = (char *)malloc(strlen(sur));
                            p->gen = (char *)malloc(strlen(gen));
                            p->date = (char *)malloc(strlen(date));
                            strcpy(p->name,name);
                            strcpy(p->sur,sur);
                            strcpy(p->gen,gen);
                            strcpy(p->date,date);
                            p->next=NULL;
                            q = t = head;
                            int i = strcmp(p->name,t->name);
                            printf("i = %d\n",i);
                            while(t!=NULL && strcmp(p->name,t->name)> 0)
                            {
                              q = t;
                              t=t->next;
                            }
                            if(t == head)
                            {
                              p->next=head;
                              head=p;
                            }
                            else
                            {
                              q->next = p;
                              p->next = t;
                            }
                     }
            }
            return head;
    }

    void printFriends(struct Friend *head)
    {
            while(head!=NULL)
            {
                    printf("Name :%s\n",head->name);
                    printf("Surname :%s\n",head->sur);
                    printf("Name :%s\n",head->gen);
                    printf("Name :%s\n",head->date);
                    head=head->next;
            }
    }


问:
getattr(object, 'name', False) v.s. hasattr(object,'name')
I am learning to compose professional codes through exploring Django source code.

In django.urls.resolvers | Django documentation | Django, it reads:

```<code>class LocaleRegexProvider(object):
    def describe(self):
        description = "'{}'".format(self.regex.pattern)
        if getattr(self, 'name', False):
            description += " [name='{}']".format(self.name)
        return description
</code>```

I assume that getattr(self, 'name', False): can be substituted by more readable code hasattr(self, 'name')

For exmaple

```<code>In [22]: if getattr(str,'split',False):
    ...:     print("Str has 'split' attribute")
    ...: else:
    ...:     print("Str has not 'split' attribute")
    ...:
Str has 'split' attribute
In [25]: if getattr(str,'sp',False):
...:     print("Str has 'sp' attribute")
...: else:
...:     print("Str has not 'sp' attribute")
...:
Str has not 'sp' attribute
</code>```

As for hasattr

```<code>In [23]: if hasattr(str,'split'):
    ...:     print("Str has 'split' attribute")
    ...: else:
    ...:     print("Str has not 'split' attribute")
    ...:
Str has 'split' attribute
In [24]: if hasattr(str,'sp'):
...:     print("Str has 'sp' attribute")
...: else:
...:     print("Str has not 'sp' attribute")
...:
Str has not 'sp' attribute
</code>```

It seems hasattrshort and readable.

There's a question about their comparison which do not cover this point. Python hasattr vs getattr - Stack Overflow

Is it a better practice to apply getattr() in this context?

答:
hasattr and getattr do different things and are not interchangeable in this case.

Consider the case where the name value is set to be an empty string. hasattr(self, 'name') will return True, while getattr(self, 'name', False) will return that empty string - which is evaluated as False in a boolean context.

To replace the getattr call, you'd need something like if hasattr(self, 'name') and self.name:, which does two attribute lookups rather than one.

Body:
I am learning to compose professional codes through exploring Django source code.

In django.urls.resolvers | Django documentation | Django, it reads:

class LocaleRegexProvider(object):
    def describe(self):
        description = "'{}'".format(self.regex.pattern)
        if getattr(self, 'name', False):
            description += " [name='{}']".format(self.name)
        return description

I assume that getattr(self, 'name', False): can be substituted by more readable code hasattr(self, 'name')

For exmaple

In [22]: if getattr(str,'split',False):
    ...:     print("Str has 'split' attribute")
    ...: else:
    ...:     print("Str has not 'split' attribute")
    ...:
Str has 'split' attribute
In [25]: if getattr(str,'sp',False):
...:     print("Str has 'sp' attribute")
...: else:
...:     print("Str has not 'sp' attribute")
...:
Str has not 'sp' attribute

As for hasattr

In [23]: if hasattr(str,'split'):
    ...:     print("Str has 'split' attribute")
    ...: else:
    ...:     print("Str has not 'split' attribute")
    ...:
Str has 'split' attribute
In [24]: if hasattr(str,'sp'):
...:     print("Str has 'sp' attribute")
...: else:
...:     print("Str has not 'sp' attribute")
...:
Str has not 'sp' attribute

It seems hasattrshort and readable.

There's a question about their comparison which do not cover this point. Python hasattr vs getattr - Stack Overflow

Is it a better practice to apply getattr() in this context?


问:
Python currency codes into a list
Does anyone have a nifty way to get all the three letter alphabetic currency codes (an example of the ones I mean is at  http://www.iso.org/iso/support/faqs/faqs_widely_used_standards/widely_used_standards_other/currency_codes/currency_codes_list-1.htm) into a list in Python 2.5? Note I don't want to do a screen scraping version as the code has to work offline - the website is just an example of the codes.

It looks like there should be a way using the locale library but it's not clear to me from reading the documentation and there must be a better way than copy pasting those into a file!

To clear the question up more, in C# for the same problem, the following code did it very neatly using the internal locale libraries:

```<code>CultureInfo.GetCultures(CultureTypes.SpecificCultures)
          .Select(c => new RegionInfo(c.LCID).CurrencySymbol)
          .Distinct()
</code>```

I was hoping there might be an equivalent in python. And thanks to everyone who has provided an answer so far.

答:
You can get currency codes (and other) data from geonames. Here's some code that downloads the data (save the file locally to achieve the same result offline) and populates a list:</p>

```<code>import urllib2

data = urllib2.urlopen('http://download.geonames.org/export/dump/countryInfo.txt')
ccodes = []
for line in data.read().split('\n'):
  if not line.startswith('#'):
    line = line.split('\t')
    try:
      if line[10]:
        ccodes.append(line[10])
    except IndexError:
      pass
ccodes = list(set(ccodes))
ccodes.sort()
</code>```

ContentLicense: CC BY-SA 2.5

Title: Python currency codes into a list

Body:
Does anyone have a nifty way to get all the three letter alphabetic currency codes (an example of the ones I mean is at  http://www.iso.org/iso/support/faqs/faqs_widely_used_standards/widely_used_standards_other/currency_codes/currency_codes_list-1.htm) into a list in Python 2.5? Note I don't want to do a screen scraping version as the code has to work offline - the website is just an example of the codes.

It looks like there should be a way using the locale library but it's not clear to me from reading the documentation and there must be a better way than copy pasting those into a file!

To clear the question up more, in C# for the same problem, the following code did it very neatly using the internal locale libraries:

CultureInfo.GetCultures(CultureTypes.SpecificCultures)
          .Select(c => new RegionInfo(c.LCID).CurrencySymbol)
          .Distinct()

I was hoping there might be an equivalent in python. And thanks to everyone who has provided an answer so far.

Body:
You can get currency codes (and other) data from geonames. Here's some code that downloads the data (save the file locally to achieve the same result offline) and populates a list:

import urllib2

data = urllib2.urlopen('http://download.geonames.org/export/dump/countryInfo.txt')
ccodes = []
for line in data.read().split('\n'):
  if not line.startswith('#'):
    line = line.split('\t')
    try:
      if line[10]:
        ccodes.append(line[10])
    except IndexError:
      pass
ccodes = list(set(ccodes))
ccodes.sort()


问:
Classify a sentence into multiple categories
A beginner in NLTK and Scikit-learn here. I want to be able to classify a given sentence(or even a paragraph) into a group of categories. By categories, I don't mean only two categories like spam and not spam or good sentiment and bad sentiment, meaning its multiple(more than two) categories to choose from. Please help me in choosing the simplest algorithm for solving this problem. Thanks in advance.</p>

答:
By the tag you used in the post I see that you know about machine learning... This is a good way for doing this project.

What you are going to need is a decent amount of sample data, that is, a table of text (sample sentences, paragraphs, whatever...) and then a column that states the category it is in.

What you do is train the program, to look for patterns in the sample text, and if you have enough sample data, you can then analyze text, and have the program output what category it is.

You could use TensorFlow as your machine learning framework.

I suggest you start with a few simpler projects to get an idea for how machine learning works and what works best.


问:
Display data from mysql row separated with comma as a link to an image
I have a row['cities'] in my table. There are different city's name in that row separated with comma and spaces (London, New York,   Tokyo,    Miami, ...). The goal is to create a link for each city name like img/london.png
I need to get the names from row['cities'], remove comma and whatever space is after comma and before the city's name, and then add img/ before that city's name and add .png after the city's name.

I did the following but because the empty space after comma is not one space for all cities and sometimes is more than one empty space, then the code didn't work for all city's name and it just works for those city's name that has one empty space after comma!

```<code>    $data = array($row['cities']);
    $city = explode(', ', $data[0]);
    $cities = $city[ rand(0, count($city)-1) ];
    $citylink = "img/".$cities.".png";
</code>```

What is the best way to do this and be able to remove all empty space between comma and city's name or perhaps there is a better way to solve this problem?
Thanks,

答:
If you want to create a link for each city, explode the string with comma as delimiter and loop it to generate image src.

```<code>$data = array('London, New York,   Tokyo, Miami  ');
$cities = explode(', ', $data[0]);
// loop the cities
foreach($cities as $city){
    $trimmed_city = preg_replace('/\s+/', '', $city); //trim city for white spaces
    echo "img/".$trimmed_city.".png"; // create image src
    echo "\n";  // new line
}
</code>```

Out put:

```<code>img/London.png
img/NewYork.png
img/Tokyo.png
img/Miami.png
</code>```

Body:
I have a row['cities'] in my table. There are different city's name in that row separated with comma and spaces (London, New York,   Tokyo,    Miami, ...). The goal is to create a link for each city name like img/london.png
I need to get the names from row['cities'], remove comma and whatever space is after comma and before the city's name, and then add img/ before that city's name and add .png after the city's name.

I did the following but because the empty space after comma is not one space for all cities and sometimes is more than one empty space, then the code didn't work for all city's name and it just works for those city's name that has one empty space after comma!

    $data = array($row['cities']);
    $city = explode(', ', $data[0]);
    $cities = $city[ rand(0, count($city)-1) ];
    $citylink = "img/".$cities.".png";

What is the best way to do this and be able to remove all empty space between comma and city's name or perhaps there is a better way to solve this problem?
Thanks,

Body:
If you want to create a link for each city, explode the string with comma as delimiter and loop it to generate image src.

$data = array('London, New York,   Tokyo, Miami  ');
$cities = explode(', ', $data[0]);
// loop the cities
foreach($cities as $city){
    $trimmed_city = preg_replace('/\s+/', '', $city); //trim city for white spaces
    echo "img/".$trimmed_city.".png"; // create image src
    echo "\n";  // new line
}

Out put:

img/London.png
img/NewYork.png
img/Tokyo.png
img/Miami.png


问:
2 and 3 node Cassandra cluster setup
I have 2 issues.

1- I need 2 node cluster. I must write & read if 1 node is gone.

I think I need= Replication Factor:2 Consistency:1

But it certainly should not be the loss of any data.

2- I need 3 node cluster and nodes may increase over time. I should be able to add more nodes with this setup.

I think I need= Replication Factor:3 Consistency:2

The question is: Am i right on this configurations?

Thank you for answers.

答:
You should keep in mind that each of your servers will hold 100% of your data. So in terms of speed you probably won't gain too much. Otherwise, having a CL of 1 for both read and writes won't lead to data loss. Also, don't forget about the hints, if 1 node is down and bring it up.

For this one you could use also QUORUM. This one implies that half of the replicas plus 1 should respond to the operation.

Also, I would suggest some reading Configuring data consistency and Replication, High Availability and Consistency in Cassandra

Title: 2 and 3 node Cassandra cluster setup


问:
Elegant Solution avoiding Global Variable
I am trying to find an elegant and still readable Way of getting rid of that global Var. But cannot find a way to do it. no jQuery please it should work without any imports.

```

答:
Others have changed your code dramatically and they are good solutions but I thought I'd introduce closures and how to use them in your situation.

```

I also updated your onload handler to be wrapped in a function instead of assigning the return value to window.onload.

Body:
Others have changed your code dramatically and they are good solutions but I thought I'd introduce closures and how to use them in your situation.

<script>
  function ajax(f) {
    var xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = function() {
      if (this.readyState == 4 && this.status == 200) {
        f(this.responseText);
      }
    };
    xhttp.open("POST", "ajax1.php", true); // SELECT COUNT(*)
    xhttp.send();
  }

  function cachedPoll() {
    var anzahlErg = 0;
    return {
      anfang: function anfang(response) {
        anzahlErg = response;
      },
      nachher: function nachher(response) {
        if (anzahlErg != 0 && response != anzahlErg) {
          location.reload();
        }
      }
    };
  }

  var pollers = cachedPoll();
  window.onload = function() {
    ajax(pollers.anfang);
  };
  setInterval(function() {
    return ajax(pollers.nachher)
  }, 250); //Polling Interval
</script>

I also updated your onload handler to be wrapped in a function instead of assigning the return value to window.onload.