Friday, May 6, 2011

How to add list in ListBox?

Hello again; i need to show X,Y,Risk in ListBoxes. But i can not do it.

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            List<TrainigSet> listtraining = new List<TrainigSet>();
            TrainigSet tr = new TrainigSet();
            double[] X = { 2, 3, 3, 4, 5, 6, 7, 9, 11, 10 };
            double[] Y = { 4, 6, 4, 10, 8, 3, 9, 7, 7, 2 };
            string[] Risk = { "Kötü", "iyi", "iyi", "kötü", "kötü", "iyi", "iyi", "kötü", "kötü", "kötü" };
            for (int i = 0; i < X.Length; i++)
            {
                tr.X = X[i];
                tr.Y = Y[i];
                tr.Risk = Risk[i];
                listtraining.Add(tr);
            }
            for (int i = 0; i < listtraining.Count; i++)
            {
                ListBox1.Items.Add(listtraining[i].X.ToString());
                ListBox2.Items.Add(listtraining[i].Y.ToString());
                ListBox3.Items.Add(listtraining[i].Risk.ToString());
            }
        }
    }
}

public class TrainigSet
{
    public double X { get; set; }
    public double Y { get; set; }
    public string Risk { get; set; }
}
From stackoverflow
  • You have to move the instantiation/creation of the TrainingSet into the for loop (you want to create a new instance for every item you add to listtraining):

    double[] X = { ... };
    double[] Y = { ... };
    string[] Risk = { ... };
    
    for (int i = 0; i > X.Length; i++)
    {
        TrainigSet tr = new TrainigSet(); // create a new TrainingSet
        ...
        listtraining.Add(tr);
    }
    

    Otherwise you will modify the same TrainingSet instance over and over again.

  • You could also use a TrainingResult class with a public X,Y, and Risk like this

    public class TrainingResult
    {
       public double X{get;set;}
       public double Y{get;set;}
       public string Risk {get;set};
    }
    

    And create a list of those. Next you could bind to it like this:

    ListBoxX.DataSource = List<TrainingResult>
    ListBoxX.DataMember = "X";
    ListBoxX.DataBind();
    
    ListBoxX.DataSource = List<TrainingResult>
    ListBoxY.DataMember = "Y";
    ListBoxY.DataBind();
    
    ListBoxRisk.DataSource = List<TrainingResult>
    ListBoxRisk.DataMember = "Risk";
    ListBoxRisk.DataBind();
    

    The advantage of this being that you have a more clear relation between x,y and risk and get more readable (to me) code. Disadvantage is offcourse the DataMember being a string value.

How do I create a custom Outlook Item?

I understand that Outlook has set items, i.e. Mail, Task, Calendar, Notes, etcetera. How can you create a custom Item that Outlook will recognize as the others? I know that when you add the Business Contact Manager it creates Items like "Opportunities"

Can you override an Item, or inherit an Item and alter/add properties and methods?

examples:

olAppointmentItem           1         Represents an AppointmentItem 
olContactItem               2         Represents a ContactItem 
olDistributionListItem      7         Represents an DistListItem 
olJournalItem               4         Represents a JournalItem 
olMailItem                  0         Represents a MailItem 
olNoteItem                  5         Represents a NoteItem 
olPostItem                  6         Represents a PostItem 
olTaskItem                  3         Represents a TaskItem
From stackoverflow
  • Outlook has the ability to create custom forms. You use the forms designer bultin to outlook, there is one built all versions of Outlook. You can launch a design session with the Tools | Forms | Design a Form command. Alternatively, open any Outlook item in Outlook 2003 or earlier and choose Tools | Forms | Design This Form.

    When you design a form you start based on on of the exiting form such a appointment, task etc.. The closest thing to a blank form is the post form.

    Forms can have VBScript code behind them to react to user actions -- validating data, synchronizing it with databases, creating new Outlook items, etc. To add code, once you're in form design mode, click the View Code command on the toolbar or ribbon.

    You can then publish you form into the Organization Forms library, so that everyone has access to them. They can also be published directly to a folder. Personal forms are published either to a folder or to your Personal Forms library.

    There is quite a lot of help documentation for this kind of thing in Outlook Help, also google will return loads of sites that show you how.

    : this question seems to come up a lot... doesn't it?
  • You cannot create new "types"; but you can certainly re-use the existing types by adding your own properties.

  • You cannot create new "types"; but you can certainly re-use the existing types by adding your own properties.

    That comment is not correct. you can certainly use custom forms, you just need to publish them first to a forms library, and make them accesible to users. generally they are based on the design of one of the default item types, and can also be associated with a folder as the default item type.

    Edit: (updating post as per comment request)

    A.Create and publish a custom form - http://office.microsoft.com/en-au/outlook/HA012106101033.aspx

    B. programmatically create an instance of the custom form.

    Outlook.Application olApp = new Outlook.Application();
        //mapifolder for earlier versions (such as ol 2003)
        Outlook.Folder contacts = olApp.Session.GetDefaultFolder(Outlook.olDefaultFolders.olFolderContacts);
        //must start with IPM.   & must be derived from a base item type, in this case contactItem.
        Outlook.ContactItem itm = (Outlook.ContactItem)contacts.Items.Add(@"IPM.Contact.CustomMessageClass");
        itm.Display(false);
    
    John Saunders : Could you show an example, please?
    tecmo : I guess it depends on what you mean by type. You can create new forms but it must be based on one of the existing built in Outlook types.

What's all the binary stuff I get from Perl's Image::Info::image_info()?

I get the following output after running the code for a picture

[1459]./image_info.pl lah.png 
$VAR1 = {
          'width' => 206,          'file_media_type' => 'image/png',
          'file_ext' => 'png',
          'PNG_Chunks' => [
                            'IHDR',
?V?????O?H??^#?C&?fu?M?5V??m6???M?s',
                            'IEND' 9   :˺??:?E??(;t??[/????o?4?4?O??TܲD
#PJ?EHͨ??ƥ8???#u   ?t??1?I/=?!w"???)?,??????X?|?{                                              M?N??A?  V``?&?
{8.?"???I)?W?_??|k?.c??l??s?8?~^Z??????_;?,,+,/?4~]ů?ZìU?+???i?s`C}??/?_??>?d~?lrn?n^???2???z?-???B??n?D;??aXHoeh?3???
DA5?N?Aw??? ???J?-????P?> 'RGB',
C?~&?1?cd 'heiga~H.`ha162,         H2?I???P?p?HsZ?&?P? Y`??;?q4Kov??3?Z???L???? ?F??&???aq?H???????"Ri?F? ??ٵ???L  B??r??H%??@??٩qiLJ?pres??on' => 'Deflate',
        ??/?Z?w,?k???g?=> '2835 dpm',
          'Compression' ? ((~??_^A ?c?vV??w????m,7????Eb???0J5?? ??? ????9????:?,24m[1460]

I do not understand the last bit of the file.

How can you change the encoding to be readable?

From stackoverflow
  • You're displaying a binary chunk as text. That's not gonna be readable in any encoding.

  • Redirect the output of your script to a file:

    ./image_info.pl lah.png >log.txt 2>&1
    

    Then open log.txt in your favorite GUI text editor (e.g. kate, gedit, notepad++), specifying ISO-8859-1 or UTF-8 in the open dialog. Try both encodings.

    Masi : Your command does not work.
    pts : It does work for me on Linux. Could you please copy-paste the error message you get?
  • The Perl Image::Info module shouldn't be displaying all of that encoded data at all. My own tests of that module have never done that, e.g:

    $VAR1 = {
              'width' => 58,
              'file_media_type' => 'image/png',
              'file_ext' => 'png',
              'PNG_Chunks' => [
                                'IHDR',
                                'IDAT',
                                'IEND'
                              ],
              'PNG_Filter' => 'Adaptive',
              'color_type' => 'Gray',
              'height' => 56,
              'SampleFormat' => 'U8',
              'Compression' => 'Deflate',
              'resolution' => '1/1'
            };
    

    Try it on another PNG file, this one looks like it might be corrupted.

    Masi : @Alnitak: I run the script on Google's logo. I get a long list of different colors. Is the list a complete list of the colors in Google's logo?

PostgreSQL trouble on windows PHP

I'm using WAMP on windows, which installs PHP, Apache and MySQL.

I'm now working on something new that requires PostgreSQL. The current install won't do it for me, as I keep getting these errors:

Call to undefined function pg_query()

Always

undefined function

I've installed PostgreSQL 8.3.7-1 for windows, added php_pgsql.dll,php_pdo_pgsql.dll and even libpq.dll, which a note on the PHP page for postgreSQL says Windows users need starting from PHP 5.2.6

Still, I keep getting these errors...

Can someone advise the best course of action? Or should I just uninstall apache and everything else, and do a fresh install of each component seperatly?

From stackoverflow
  • Did you enable it in the php ini file?

    What does a call to phpinfo() say is installed for extensions?

    WebDevHobo : the phpinfo page show nothing on postegre. Yet when I check inside my php.ini file, it's enabled...
  • xampp doesn't "tell" apache/php which php.ini to use. Therefore php uses its default lookup strategy to find the .ini file. If you haven't changed anything this will be the one in the directory where the apache binary is located, xampp/apache/bin/php.ini. Did you edit this file and removed the semicolon before extension=php_pgsql.dll ? When in doubt ask

    echo 'php.ini: ', get_cfg_var('cfg_file_path');
    which file you have to edit.
    xampp installs php as a module by default and you have to restart the apache in order to get php to read the php.ini again. After that
    echo extension_loaded('pgsql') ? 'yes':'no';
    should print yes. If it doesn't stop the apache service, open a command shell, go to your xampp directory and enter
    apache_start.bat
    This will start the apache as a console application and you can see startup errors in this console (instead of windows' event manager). If a dll is missing you will get a message box.

    WebDevHobo : thanks, but I'm not using XAMPP, I'm using WAMP.
    WebDevHobo : As for the semicolon, yes, I removed it.
  • Depending on what kind of errors you see in the Apache's error.log the answers on this question might be helpful.

What does .h and .m stand for?

Exact duplicate:

Why do Objective C files use the .m extension?

I'm thinking .h stands for header. I suppose .m could stand for main, but I don't know. Do any of you actually know this?

Just to clarify, I know what goes in which file, i.e. I know the purpose of each filetype, I'm just curious if the filetype symbol has a meaning.

From stackoverflow
  • right, .h stands for the header file. .m is for your code like .cpp in c++

    regards, buk

  • Look at this other question:

    http://stackoverflow.com/questions/652186/why-do-objective-c-files-use-the-m-extension

    tmadsen : Thanks :) should have done a more extensive search on this site.
    Sergio Acosta : StackOverflow is amazing. Honestly, I was about to answer your question and was googling for sources to cite. But in the top search results I found the link to the already answered question. =)
    • h - header
    • m - method
    Kris : hmm, i thought it was "H"eader and i"M"plementation
  • .h stands for header while .m stands for implementation

MySQL MyISAM table performance... painfully, painfully slow

I've got a table structure that can be summarized as follows:

pagegroup
* pagegroupid
* name

has 3600 rows

page
* pageid
* pagegroupid
* data

references pagegroup; has 10000 rows; can have anything between 1-700 rows per pagegroup; the data column is of type mediumtext and the column contains 100k - 200kbytes data per row

userdata
* userdataid
* pageid
* column1
* column2
* column9

references page; has about 300,000 rows; can have about 1-50 rows per page

The above structure is pretty straight forwad, the problem is that that a join from userdata to page group is terribly, terribly slow even though I have indexed all columns that should be indexed. The time needed to run a query for such a join (userdata inner_join page inner_join pagegroup) exceeds 3 minutes. This is terribly slow considering the fact that I am not selecting the data column at all. Example of the query that takes too long:

SELECT userdata.column1, pagegroup.name
FROM userdata
INNER JOIN page USING( pageid )
INNER JOIN pagegroup USING( pagegroupid )

Please help by explaining why does it take so long and what can i do to make it faster.

Edit #1

Explain returns following gibberish:

id  select_type  table      type    possible_keys        key      key_len  ref                         rows    Extra
1   SIMPLE       userdata   ALL     pageid                                                             372420
1   SIMPLE       page       eq_ref  PRIMARY,pagegroupid  PRIMARY  4        topsecret.userdata.pageid   1
1   SIMPLE       pagegroup  eq_ref  PRIMARY              PRIMARY  4        topsecret.page.pagegroupid  1

Edit #2

SELECT
u.field2, p.pageid
FROM
userdata u
INNER JOIN page p ON u.pageid = p.pageid;
/*
0.07 sec execution, 6.05 sec fecth
*/

id  select_type  table  type    possible_keys  key      key_len  ref                rows     Extra
1   SIMPLE       u      ALL     pageid                                              372420
1   SIMPLE       p      eq_ref  PRIMARY        PRIMARY  4        topsecret.u.pageid 1        Using index

SELECT
p.pageid, g.pagegroupid
FROM
page p
INNER JOIN pagegroup g ON p.pagegroupid = g.pagegroupid;
/*
9.37 sec execution, 60.0 sec fetch
*/

id  select_type  table  type   possible_keys  key          key_len  ref                      rows  Extra
1   SIMPLE       g      index  PRIMARY        PRIMARY      4                                 3646  Using index
1   SIMPLE       p      ref    pagegroupid    pagegroupid  5        topsecret.g.pagegroupid  3     Using where

Moral of the story

Keep medium/long text columns in a separate table if you run into performance problems such as this one.

From stackoverflow
  • One possible issue is that MySQL uses only one index per query and maybe you don't have a single index with those columns -- or MySQL's query optimizer isn't picking it. What does EXPLAIN SELECT &c tell you here?

  • The easy way to figure out what MySQL is doing with your query is to have it explain the query to you. Run this and have a look at the output:

    EXPLAIN SELECT userdata.column1, pagegroup.name
    FROM userdata
    INNER JOIN page USING( pageid )
    INNER JOIN pagegroup USING( pagegroupid )
    

    MySQL will tell you in which order it processes the queries and what indexes it uses. The fact that you created indexes does not mean that MySQL actually uses them.

    See also Optimizing queries with EXPLAIN

    EDIT

    The output of your EXPLAIN looks fine. It does a full table scan on the userdata table, but that is normal since you want to return all rows in it. The best way to optimize this is to rethink your application. Do you really need to return all 372K rows?

    Salman A : I've revised my question and added the result from explain command. Appears to be using correct indices but still 128 seconds just to execute.
    Sander Marechal : I have updated my response as well.
  • I would start with breaking the query up, to figure out if there is one slow and one fast part, or if both are slow (sorry, I'm no fan of the USING syntax, so I'm going to use ON):

    SELECT 
      u.userdata, p.pageid
    FROM
      userdata u
      INNER JOIN page p ON u.pageid = p.pageid
    
    SELECT 
      p.pageid, g.pagegroupid
    FROM
      page 
      INNER JOIN pagegroup g ON p.pagegroupid = g.pagegroupid
    

    What does that give you? Running these with EXPLAIN EXTENDED will provide additional hints.

    Salman A : I've posted the output of the two queries. Explain extended returns similar queries in different syntax.
    Tomalak : Looks like the second query is the trouble maker. Please include the info what indexes you have in place.
    Salman A : primary keys + all keys used in joins are indexed. For the three tables I have indexes on pagegroup.pagegroupid (PK), page.pageid (PK), page.pagegroupid (INDEX), userdata.userdataid (PK), userdata.pageid (INDEX), userdata.column1 (INDEX)
  • Looks like you're doing a join on all rows on userdata and then trying to select everything. That is every page in a pagegroup with userdata. Where's the WHERE clause? There's no LIMIT, how many results did you want? Why don't you get your row count down on userdata row in your explain result, that should speed up the query. Heh.

    Salman A : I need a dump of selected columns from userdata along with pagegroup.name for cross reference. I believe it should work fast enough if there was no "mediumtext" column in the page table.
    apphacker : Maybe you want to start recording this information in a log as it comes in instead of using SQL, maybe think about something other than SQL for this data, like non-normalized berkeley db or something.
  • What's the data type and purpose of columnX in the userdata table? It should be noted that any text data type (i.e excluding char, varchar) forces any temporary tables to be created on disk. Now since you're doing a straight join without conditions, grouping or ordering, it probably won't need any temporary tables, except for aggregating the final result.

    I think it would also be very helpful if you show us how your indexes are created. One thing to remember is that while InnoDB concatenates the primary key of the table to each index, MyISAM does not. This means that if you index column name and search for it with LIKE, but still want to get the id of the page group; Then the query would still need to visit the table to get the id instead of being able to retrieve it from the index.

    What this means, in your case, if I understand your comment to apphacker correctly, is to get the name of each users pagegroups. The query optimizer would want to use the index for the join, but for each result it would also need to visit the table to retrieve the page group name. If your datatype on name is not bigger than a moderate varchar, i.e. no text, you could also create an index (id, name) which would enable the query to fetch the name directly from the index.

    As a final try, you point out that the whole query would probably be faster if the mediumtext was not in the page table.

    1. This column is excluded from the query you are running I presume?
    2. You could also try to separate the page data from the page "configuration", i.e. which group it belongs to. You'd then probably have something like:
      • Pages
        • pageId
        • pageGroupId
      • PageData
        • pageId
        • data

    This would hopefully enable you to join quicker since no column in Pages take up much space. Then, when you needed to display a certain page, you join with the PageData table on the pageId-column to fetch the data needed to display a particular page.

    Salman A : Answer: #1 - Yes, i am not SELECTing the data column; #2 - Yes thats a workaround which "should" work, another possibility is to de-normalize the table a tad bit and add pagegroupid into userdata but the question is if there is something wrong in the table structure or the query.
    Salman A : most of the columns are varchar 100s including pagesource.name and userdata.field2
    Salman A : It worked after I moved the "data" column into a separate table "pagetemp" that relates 1-to-1 with the page table. None of the indexes work otherwise.
  • I'm assuming the userdata table is very large and does not fit in memory. MySQL would have to read the entire table from harddisk, even if it needs only two small columns.

    You can try to eliminate the need for scanning the entire table by defining an index that contains everything the query needs. That way, the index is not a way to facilitate a search into the main table, but it's a shorthand version of the table itself. MySQL only has to read the shorthand table from disk.

    The index could look like this:

    column1, pageid
    

    This has to be non-clustered, or it would be part of the big table, defeating its purpose. See this page for an idea on how MySQL decides which index to cluster. The easiest way seems to make sure you have a primary key on pageid, which will be clustered, so the secondary column1+pageid index will be non-clustered.

    Salman A : I tried creating a two column index (pageid-sourceid) on the page table in order to create a short-circuit between userdata and pagesource which reduced execution time but not much.
    Andomar : Your comment above says performance got better with a 1:1 table. That really seems to suggest the index on (pageid,sourceid) was clustered in some way. Oh well... problem solved I guess.

javaFX as a webservice client?

I need to make calls to a webservice from a javaFX client. is there some sort of wsimport type tool that I can use to generate javaFX client stubs from a deployed WSDL.

From stackoverflow
  • You could make Java class stubs and call them from javaFX.

  • thank you for your response, i'm not familiar with javafx, i'm just trying to help a javaFX team integrate with my web service. javaFX can instantiate/call java classes?

    Yishai : Absolutely. The other way around is a little hard (have Java call javaFX code) but still doable. For the simple case of calling Java from JavaFX, start here: http://jfx.wikia.com/wiki/FAQ#How_do_I_refer_to_a_fully-qualified_java_class.3F
  • Yes,

    Suppose you have a "MyJavaClass.java"

    import somePackadge.MyJavaClass
    ...
    
    var myObject:MyJavaClass = new MyJavaClass();
    
    myObject.setSomething("this is something");
    
    println("{myObject.getSomething()}");
    
    ...
    

    Refer to "http://java.sun.com/developer/technicalArticles/scripting/javafx/javafx_and_java/" for more information

  • JavaFX Supports only RESTfull webservices out of the box. You can however use existing Java tools for generating WSDL stubs and use the generated classes from your JavaFX Script classes.

  • Working JavaFX examples for JSON, RSS, Google API, Yahoo API - http://jfxstudio.wordpress.com/2009/07/24/javafx-web-services/