Monday, December 24, 2007

Kill Remote Desktop Sessions

"Terminal server has exceeded the maximum number of connections" occurs when sessions were taken by others and were forgotten to log off to release the session. I encounter this problem very often and, to my surprise, there is more than one way to solve this easily.

Sunday, December 23, 2007

Links for 2007-12-23

Articles:
  • Swarm Intelligence: A Whole New Way to Think About Business
    • Swarm intelligence, I think, is a synonym to crowd wisdom.
    • The reasons social insets are almost everywhere on earth may due to three characteristics:
      • Flexibility - the group can quickly adapt to a changing environment.
      • Robustness - even when on or more individuals fail, the group can still perform its tasks.
      • Self-organization - the group needs relatively little supervision or top-down control.
    • The foraging principles of social insects, like ants and honeybees, have been applied to solve routing problems, packaging problems, even some business problems.
  • Artificial Neural Networks: A Tutorial
    • The architectures of neural networks were grouped in two categories:
      • Feed-forward networks
        • Single-layer perception
        • Multilayer perceptron
        • Radial basis function nets
      • Feedback/Recurrent networks
        • Competitive networks
        • Kohonen's SOM
        • Hopfield network
        • ART models
    • The learning process of neural networks were grouped in three paradigms:
      • Supervised
        • Error-correction
        • Boltzmann
        • Hebbian
        • Competitive
      • Unsupervised
        • Error-correction
        • Hebbian
        • Competitive
      • Hybrid
        • Error-correction and competitive
    • Among the various neural networks, not every method was suitable to all kinds of problems. Certain types of problems were best solved by some methods. Thus, the choice of the best techniquest should be driven by the given applications' nature.

Friday, December 21, 2007

Disable IE 6 Remember My Password

Under Tools Menu
-> Select Options Item
-> Select Content Tab
-> Click input completion Button
-> Unselect form user name and passwords
-> Click erase passwords Button

Monday, December 17, 2007

Google's BigTable

I just read Google's BigTable paper. From the title, "Bigtable: A Distributed Storage System for Structured Data", you can tell this paper is not about PageRank algorithm. Instead, it reports how Google manages their structured data in a distributed way. So it talks about the infrastructure behind various services Google provides, such as webpage indexing, Google Finance, Google Earth, etc..

It's a interesting paper. Many databased-related issues are addressed in the paper. Some topics I found interesting are listed below.
  1. Data are modeled as a sorted map. Key is a combination of a row key, column key and a timestamp, while value is an uninterpreted array of bytes.
  2. Action is coordinated via Chubby lock service and Paxos algorithm.
  3. Data are located via one active master server and many tablet servers.
  4. Data are summarized via a parallel computation method, MapReduce.
A brief introduction to BigTable is here, and I just found that chapter 23 in Beautiful Code describes MapReduce method. I think it should be useful and/or important for practioners, i.e., programmers, as computer is moving toward a multi-core system. I should give it a read.

Monday, December 10, 2007

Machine Learning Journals and Conferences

  • ICML(International Conference on Machine Learning)
  • ECML(European Conference on Machine Learning)
  • UAI(Uncertainty in Artificial Intelligence)
  • NIPS(Neural Information Processing Systems)
  • COLT(Computational Learning Theory)
  • IJCAI(International Joint Conference on Artificial Intelligence)
  • JMLR(Journal of Machine Learning Research)
  • http://videolectures.net (Machine Learning Online Video Lectures)

Saturday, December 8, 2007

Links for 2007-12-08

Blog:
  • Measure twice, average once - Measurement is all about estimation and there is a theory behind it. The blog sheds some light on what the theory is about.

Article:

  • Gödel, Escher, Bach: an Eternal Golden Braid - a pholosophical book by Douglas Hofstadter, with many subjects covered, including what i'm interested, such as artificial intelligence.
  • How Many Ways Can You Spell V1@gra?
    • Brian Hayes analyzed that an legible variation of Viagra has 1,843,200 possible spellings, by varying Viagra and separating the six letters by five copies of space characters. However, studying the 88,324 emails received, the author identified 113 distinct spellings. Based on the information, the author suspected that the spam scheme was not very sophisticated. It seemed a spelling once has been incorporated into a message, it is mailed out repeatedly over a period of a few months, then gave a rest.
    • The techniques used to combat spam are must better known thant the methods of spam senders. Three spam-filtering approaches have been used to train a spam-ham classifier, that is, Bayesian, SVM, and HMM. However, a possible attack to Bayesian filtering, Bayesian poisoning, was discussed but could be defended by frequently retraining the filter.
  • Introduction to Estimation Theory - The choice of error criterion and optimization heavily influences the form of estimation procedure. The estimation performance can be considered from three aspects.
    • Bias - An estimate is said to be unbiased if the expected value of the estimate equals the true value of the parameter.
    • Consistency - An estimate is said to be consistent if the mean-squared estimation error tends to zero as the number of observations becomes large.
    • Efficiency - An estimate is said to be efficient if its mean-squared error achieves Cramér–Rao bound.

Sunday, December 2, 2007

Concurrency is the Next Revolution

According to the article by Herb Sutter in 2005, we are not going to experience performance boost by running application on computers with latest CPU chips. Traditionally, CPU designers have achieved performance gains in three main areas,
  1. clock speed
  2. execution optimization
  3. cache
However, due to physical limits, the near-term future CPU performance growth drivers are:
  1. hyperthreading
  2. multicore
  3. cache
As object-oriented programming was dominant in the mainstream in the 90's, concurrency programming is going to be the next. So what does the sea change mean to software developers? Here are the consequences.
  1. Applications will inreasingly need to be concurrent if they want to fully exploit CPU throughput gains.
  2. Applications are likely to become increasingly CPU-bound, moving away from I/O-bound.
  3. Efficiency and performance optimization will get more, not less, important.
  4. Programming languages and systems will increasingly be forced to deal well with concurrency.
This week, Microsoft responded to Herb Sutter's call for a higher-level programming model for concurrency that languages offer: Microsoft Parallel Extensions to .Net Framework 3.5.

Thursday, November 29, 2007

Installation of SQL Server 2005 Report Designer

For a project I recently work on, we use SQL Server 2005 Reporting Services. I don't want to install the whole SQL Server 2005 but only SQL Server 2005 Report Designer on my working machine. According to the source, SQL Server 2005 Report Designer has been integrated into Business Intelligence Development Studio. The studio allows developers to build Analysis Services, Integration Services, and Reporting Services projects. Also, a copy of Visual Studio 2005 is not necessary. If Visual Studio 2005 is not installed, SQL Server Setup installs the shell so that Report Designer can be run.

To install Business Intelligence Development Studio, I ran the setup.exe under the Tools folder in the installation CD, then chose the respective item under Client Components. That's it.



BTW, during the installation process, I encountered "Performance Monitor Counter Check Failed" error message. But the problem was solved after I followed the steps suggested in the readme file(ReadmeSQL2005.htm).

Monday, November 26, 2007

References for Linear Classifiers

I take Machine Learning this semester. Linear model was covered recently, that is, linear regression and linear classification. In linear regression, a connection was established between least-squared-error and MLE under Gaussian assumption in errors. In linear classification, two models were introduced. In Generative model, conditional-independence was assumed and join probability was derived by applying Naive Bayes. In Discriminative model, a linear form was assumed, and posterior probability was derived by combining linear regression with logistic function. Here is the information which is helpful for learning the subject.

Sample chapter:
Machine Learning Course Materials:
Article:
Paper:

Sunday, November 25, 2007

Links for 2007-11-25

News:
  1. Following Benford's Law, or Looking Out for No. 1: According to the article, it's very likely at at some point in a series of 200 tosses, either heads or tails will come up six or more times in a row. And a formula discovered by Dr. Frank Benford stated that the probability of any number 'd' from 1 through 9 being the first digit is log10(1+1/d) . A detailed explanation of Benford's Law can be found here.
  2. As the Calendar Turns, So Do Many Stocks’ Fortunes: According to a study reported in the article, "some stocks tended to perform particularly well or poorly each January, while others tended to regularly beat or lag the market in February, and so forth for each month of the year. They found that these patterns were remarkably persistent, lasting as long as two decades".
Web site:
Open Source RSS & RDF Tools in C#: A collection of open source tools for RSS feeds.

Article:
Market Neutral Strategy :

Saturday, November 24, 2007

Links for 2007-11-24

Web site:
  1. A Windows Forms FAQ site - A good place to start with for Windows Forms questions.
  2. Open Flash Chart(via Larkware News) - An open source google-style charting tool for web pages.

Blog:
10 Absolute "Nos!" for Freelancers - Informative for anyone who wants to be a freelancer but I agreed with some of the responses in the post, that you don't have to reject these requests directly. Instead, charge a price so high that it's meaningless for clients to ask.

Articles:
  1. Algorithms are a human’s best friend - An article published in 2005. Five algorithmic trading strategies were mentioned. And strategies could be hybridized by combining other constraints or varying parameters.
  2. Volume Weighted Average Price (VWAP) - An implementation of Volume Weighted Moving Average, but not a trading strategy as mentioned above.

Embedded HTTP server

I came across this article about building a customizable embedded HTTP server in C#. An idea just struck me that a server like this could help me monitor systems. For example, besides reading log files to check system status, I could use a web browser to query a HTTP server embedded in a production system for system information. Furthermore, the system information could be published in RSS format and be subscribed by an RSS reader.

Apparently, as shown here, other than monitoring systems, there have already existed many applications of an embedded HTTP server on the Internet. And not restricted to an HTTP server, many components are embeddable in .NET applications, such as this(IronPyton), and this(SQL Server Express). Interesting!

Saturday, November 17, 2007

Machine Learning Tools

  1. MLC++ - Written in C++. A paper introducing this tool is here. If I'm going to study this toolset, I will start from MLC++ utilities.
  2. WEKA - Written in Java. An introduction of the command line interface to the tool is here. Basically, the model in WEKA can be summarized as follows.

    • Filters - Filters are responsible for transforming datasets. Two kinds of filters are available. Supervised filtering would take class information into consideration, while unsupervised filtering is the non-stratified version of resampling the dataset.
    • Instances - Dataset is implemented by Instances class.
    • Classifier - All the learning algorithms are derived from the abstract Classifier.

    WEKA expresses data as a collection of instances. A user applies filters to transform dataset and then feed the output to classifiers for training and testing. To learn how to call WEKA from Java, check out the sample.

Links for 2007-11-17

Blogs:
  1. 7 of the Hardest Things I Learned About Writing Software:
    • Make choices - Don't make program too complicated. Make it work first.
    • Delete code
    • NIH (not invented here) - Reminds me things, such as Reinventing the wheel, Standing on the shoulders of giants, etc.
    • UI is more important than code
    • Solve Problems - Users don't care how you write your code. (That doesn't mean nobody care. Think about maintainability. But solving problems always come first.)
    • You Are Different - Reminds me of this book.
    • Documentation - If your program is so complex as that users have to read your manual to figure out, something is wrong with your program.
  2. 1000 Lines Of Code - A rule of thumb following "Make choices" in the above post.
Sample chapter:
  1. The Berkeley DB Book

Monday, November 12, 2007

Links for 2007-11-12

Blog:
Be not afraid of the Visitor, the big, bad Composite, or their little friend Double Dispatch - The author used StoryTeller project as an example to demonstrate the use of Composite, Double Dispatch, and Visitor pattern. ILeaf interface, implementing Composite pattern, was used in a tree structure. A tree was composed of nodes which were composed of leaves. HTMLWriter class, implementing Visitor pattern, was used in traversing the tree. IHTMLBuilder interface, implementing Double Dispatch pattern, was used in performing action on tree nodes. According to the author,
If you have a need to process an object hierarchy and/or a mixed list of objects, the Visitor and Composite patterns can do a lot for you to control the complexity of dealing with the data structure.

MSDN Article:
Microsoft Sync Framework - I have mentioned about a redundency mechanism before. Recently, MS published its own version. I'm not sure if I can adapt the framework to my system, but the model and the diagram in the introduction are already very helpful to create one oneself.

Monday, October 29, 2007

Links for 2007-10-29

MSDN Articles:
  1. Handling Data - Winforms data binding architecture is discussed and MVC pattern is recommended in designing Winfrom applications. Also, how DataSet contents can be merged is introduced.
  2. Occasionally Connected Smart Clients - Issues associated with data reconciliation in an occasionally connected environment are discussed.

Saturday, October 27, 2007

Links for 2007-10-27

Articles:
  1. AI: It's OK Again! - two camps in AI, symbolism, such as expert systems, and connectionism, such as neural networks, are discussed in the article.
  2. Algorithmic Trading
    • Most trading algorithms can be divided into two parts, i.e., when to trade and how to trade. An approach, Complex Event Processing(CEP), is suggested to simplify the development of trading algorithms. Thus, trading algorithms can be structured as a set of CEP rules and hosted inside a CEP engine.
    • Event Stream Intelligence with Esper and NEsper - an open source tool for developing CEP applications on .NET platform.

References for Multi-Threaded .Net WinForm Programming

MSDN Articles:
  1. Using Multiple Threads(ch.6 in Smart Client Architecture and Design Guide) - details why, when and how to call Control.Invoke in the UI thread.
  2. Creating a Simplified Asynchronous Call Pattern for Windows Forms Applications - proposes a ServiceAgent class to encapsulate the interaction between background threads and the UI thread.
  3. Creating Asynchronous Business Objects for Use in .NET Windows Forms Clients - proposes some helper classes and events to simplify the asynchronous invocation process.
Blogs:
  1. WinForms UI Thread Invokes: An In-Depth Review of Invoke/BeginInvoke/InvokeRequred - describes how Control.Invoke works underneath
  2. The Daemon Inside - suggests one try Control.BeginInvoke when Control.Invoke does not work because deadlock might happen.
Podcast:
  1. Thread-Safe Asynchronous Smart Clients

Friday, October 12, 2007

SQL joins

I came across a great post about SQL joins. Below is the example I tried out on Oracle9i.

SQL> create table TableA (id integer, name varchar(20));
SQL> insert into TableA values (1, 'Pirate');
SQL> insert into TableA values (2, 'Monkey');
SQL> insert into TableA values (3, 'Ninja');
SQL> insert into TableA values (4, 'Spaghetti');
SQL>
SQL> create table TableB (id integer, name varchar(20));
SQL> insert into TableB values (1, 'Rutabaga');
SQL> insert into TableB values (2, 'Pirate');
SQL> insert into TableB values (3, 'Darth Vader');
SQL> insert into TableB values (4, 'Ninja');
SQL>
SQL> SELECT * FROM TableA
2 INNER JOIN TableB
3 ON TableA.name = TableB.name
4 order by TableA.id, TableB.id;
     ID NAME                         ID NAME                          
---------- -------------------- ---------- --------------------
1 Pirate 2 Pirate
3 Ninja 4 Ninja
SQL>
SQL> SELECT * FROM TableA
2 FULL OUTER JOIN TableB
3 ON TableA.name = TableB.name
4 order by TableA.id, TableB.id;
       ID NAME                         ID NAME                            
---------- -------------------- ---------- --------------------
1 Pirate 2 Pirate
2 Monkey
3 Ninja 4 Ninja
4 Spaghetti
1 Rutabaga
3 Darth Vader
SQL>
SQL> SELECT * FROM TableA
2 LEFT OUTER JOIN TableB
3 ON TableA.name = TableB.name
4 order by TableA.id, TableB.id;
       ID NAME                         ID NAME                            
---------- -------------------- ---------- --------------------
1 Pirate 2 Pirate
2 Monkey
3 Ninja 4 Ninja
4 Spaghetti
SQL>
SQL> SELECT * FROM TableA
2 LEFT OUTER JOIN TableB
3 ON TableA.name = TableB.name
4 WHERE TableB.id IS null
5 order by TableA.id, TableB.id;
        ID NAME                         ID NAME                             
---------- -------------------- ---------- --------------------
2 Monkey
4 Spaghetti
SQL>
SQL> SELECT * FROM TableA
2 FULL OUTER JOIN TableB
3 ON TableA.name = TableB.name
4 WHERE TableA.id is null
5 OR TableB.id is null
6 order by TableA.id, TableB.id;
       ID NAME                         ID NAME                             
---------- -------------------- ---------- --------------------
2 Monkey
4 Spaghetti
1 Rutabaga
3 Darth Vader
SQL>
SQL> SELECT * FROM TableA
2 CROSS JOIN TableB;
       ID NAME                         ID NAME                             
---------- -------------------- ---------- --------------------
1 Pirate 1 Rutabaga
2 Monkey 1
3 Ninja 1
4 Spaghetti 1
1 Pirate 2 Pirate
2 Monkey 2
3 Ninja 2
4 Spaghetti 2
1 Pirate 3 Darth Vader
2 Monkey 3
3 Ninja 3

ID NAME ID NAME
---------- -------------------- ---------- --------------------
4 Spaghetti 3 Darth Vader
1 Pirate 4 Ninja
2 Monkey 4
3 Ninja 4
4 Spaghetti 4
SQL>
SQL> drop table TableA;
SQL> drop table TableB;

Thursday, October 11, 2007

Secret of Successful People

I came across a good post from here. The seven basic disciplines of a happy and successful life are as follows,
  • Take a new perspective and keep on learning new skills.
  • Assume responsibility - If you see a problem, do something about it.
  • Reach out - The most important working relationships are the personal ones.
  • Stay flexible and learn to thrive with changes and challenges.
  • Follow your heart and live your life with passion.
  • Take risks.
  • Set goals and never give up on them.
And it reminds me the book, The Seven Habits of Highly Effective People also has 7 rules,
  • Be Pro-active.
  • Begin with the End In Mind.
  • Put First Things First.
  • Think Win/Win.
  • Seek First to Understand, Then to be Understood.
  • Synergize describes a way of working in teams.
  • Sharpen the saw.
What a coincidence! And there are some similarity between them. Anyway, it's good to have something like these to remind me from time to time.

Tuesday, September 18, 2007

Links for 2007-09-18

Blog:

  1. Beautiful Code: Leading Programmers Explain How They Think: A list of pointers to the information about the authors of Beautiful Code. It's kind of who's who for me.
Sample Chapter:
  1. Hacker's Delight

Count Bits in Words

How do we count the number of 1-bit in a 32-bit unsigned integer, x? A naive approach is like this.
pop = 0;
for (i = 0; i < pop =" pop" x =" x">> 1;
}
Can we do better? Yes, according to Henry S. Warren, Jr., who wrote "The Quest for an Accelerated Population Count" of Beautiful Code. There are many ways to improve the loop. For example, if x is a small number, then the loop can be improved as followed.
pop = 0;
while (x) {
pop = pop + (x & 1);
x = x >> 1;
}
The following is looped as many times as the number of 1-bit in x.
pop = 0;
while (x) {
pop = pop + 1;
x = x & (x - 1); //turn off the rightmost bit
}
Or we can trade space for time. Look up the number of 1-bit in a table.
static char table[256] = {0, 1, 1, 2, 1, 2, 2, 3, ...,
pop = table[x & 0xFF] + table[(x >> 8) & 0xFF] + table[(x >> 16) & 0xFF] + table[x>> 24];
And several non-trivial approaches are discussed in the article. The author further applied the 'population count' functions to other problems, such as comparing population counts of two words, calculating Hamming distance, computing the number of trailing 0s in a word and allowing fast direct indexed access to a sparse array. Someone even posted performance analysis of the population count functions on the Internet. It seems Google would ask this kind of questions in an interview. Though I am not sure where I can apply the population count functions in my projects, Mr. Warren's article is definitely very informative.

Sunday, September 16, 2007

Links for 2007-09-16

Article:
  1. Cross-platform graphics with cairo - As the title suggested, Cairo is a free software vector darwing library suitable for cross-platform drawings. Thought written in C, it has bindings for other languages, such as C++, Ruby, Python, and .Net/mono, among others. Cairo looks straightforwards and the current release version is 1.4.10.
  2. Guide to Oracle Berkeley DB for SQL Developers - The author took a step-by-step approach to show you how you would create a database, insert/update/delete/query data in Berkeley DB, in contract with how you would do the same things in SQL.

Monday, September 10, 2007

Links for 2007-09-10

Sample Chapter:
  1. How I Became a Quant
    • Chapter 1 - David Leinweber - The author talked about how he started in the military industry in 70's and entered into the finance industry in the 80's. AI played an important role for him to make the switch. Thought he didn't say much about how he applied AI to the stock market, it's a fun read.
Article:
  1. A Little AI Goes a Long Way on Wall Street
    • Written by David Leinweber and Yossi Beinart and published in 1994.
    • According to the article, their product, MarketMind seems to be a rule-based system. It monitored the market according to the rules users specified and alerted users when conditions match. A rule editing tool was provided as well. Another system, Quantex, was integrated with MarketMind to provide automatic order generation and execution capability.
    • The article read like a white paper, talking what their systems did, but not how. However, 2 techniques were mentioned, 'Rete matching' and 'Earley Algorithm'. I think I need to dig deeper.

Sunday, September 9, 2007

Links for 2007-09-09

Article:
  1. Driven to ... Discovering Your Design Values(via this blog) - A good start to learn what RDD, TDD, BDD, DbC, DDD, and MDD is. According to the author, 'whenther "driven" or not, these approaches all emphasize a core set of values and principles ... A thoughtful designer should be able to pick and choose among practices without losing their essence.' Well said.
Blog:
  1. News from the Front - Paul has his point, but I don't agree. What a good degree can give you besides knowledge? I think it's the opportunity. In Paul's shoes, he might not care about people's education. If Paul were in the applicants' position, trying to raise funds from those 'angels', Paul might wish he has a good degree. The angels who don't know Paul but know the university he graduated from would give him the fund he needs.

Thursday, September 6, 2007

Links for 2007-09-06

Articles:
  1. Implementing a Publisher/Subscriber model for .NET Remoting
    • I adopted the method in the article to handcraft redundancy capability in a risk-monitoring system I developed.
  2. Memcached (Distributed Cache) ASP.net Provider
    • Recently, I came across this article and hoped Memcached would be a better solution for my system. But according to this introduction, this tool seems to be suitable is for load balance, not for redundancy. Still, it's good to know.
    • A windows implemention is available as well.
  3. ASP.NET Charting with NPlot
Blog:
  1. Calling a Windows Service from ASP.NET via Remoting & IpcChannel
    • Other than IpcChannel is not available in .Net Framework 1.1, the idea looks good.

Monday, September 3, 2007

DataRow.BeginEdit Method

This is the sample code copied from MSDN.

1 private void DemonstrateRowBeginEdit()

2 {

3 DataTable table = new DataTable("table1");

4 DataColumn column = new

5 DataColumn("col1",Type.GetType("System.Int32"));

6 table.RowChanged+=new

7 DataRowChangeEventHandler(Row_Changed);

8 table.Columns.Add(column);

9

10 // Add a UniqueConstraint to the table.

11 table.Constraints.Add(new UniqueConstraint(column));

12

13 // Add five rows.

14 DataRow newRow;

15

16 for(int i = 0;i<5; i++)

17 {

18 // RowChanged event will occur for every addition.

19 newRow= table.NewRow();

20 newRow[0]= i;

21 table.Rows.Add(newRow);

22 }

23 // AcceptChanges.

24 table.AcceptChanges();

25

26 // Invoke BeginEdit on each.

27 Console.WriteLine(

28 "\n Begin Edit and print original and proposed values \n");

29 foreach(DataRow row in table.Rows)

30 {

31

32 row.BeginEdit();

33 row[0]=(int) row[0]+10;

34 Console.Write("\table Original \table" +

35 row[0, DataRowVersion.Original]);

36 Console.Write("\table Proposed \table" +

37 row[0,DataRowVersion.Proposed] + "\n");

38 }

39 Console.WriteLine("\n");

40 // Accept changes

41 table.AcceptChanges();

42 // Change two rows to identical values after invoking BeginEdit.

43 table.Rows[0].BeginEdit();

44 table.Rows[1].BeginEdit();

45 table.Rows[0][0]= 100;

46 table.Rows[1][0]=100;

47 try

48 {

49 /* Now invoke EndEdit. This will cause the UniqueConstraint

50 to be enforced.*/

51 table.Rows[0].EndEdit();

52 table.Rows[1].EndEdit();

53 }

54 catch(Exception e)

55 {

56 // Process exception and return.

57 Console.WriteLine("Exception of type {0} occurred.",

58 e.GetType());

59 }

60 }

61

62 private void Row_Changed(object sender,

63 System.Data.DataRowChangeEventArgs e)

64 {

65 DataTable table = (DataTable) sender;

66 Console.WriteLine("RowChanged " + e.Action.ToString()

67 + "\table" + e.Row.ItemArray[0]);

68 }

The followings are the event sequences I have observed when executing DemonstrateRowBeginEdit method.
  • When line 21 is executed, for each row added, 1 RowChanged event is fired and 'Change' is passed as DataRowChangeEventArgs.Action argument.
  • When line 24 is executed, for each row added, 1 RowChanged event is fired and 'Commit' is passed as DataRowChangeEventArgs.Action argument.
  • When line 41 is executed, for each row modified, 2 RowChanged events are fired and 'Change' and 'Commit' are passed as DataRowChangeEventArgs.Action argument separately.
  • When line 51 is executed, 1 RowChanged event is fired and 'Change' is passed as DataRowChangeEventArgs.Action argument.
  • When line 52 is executed, System.Data.ConstraintException is thrown.
Some other behaviors are observed after the code is modified.
  • If line 32 is commented out, System.Data.VersionNotFoundException is thrown at line 36 for 'There is no Proposed data to access'.
  • If line 32 and line 36 are commented out, when line 33 is executed, 1 RowChanged event is fired and 'Change' is passed as DataRowChangeEventArgs.Action argument. And when line 41 is executed, for each row modified, 1 RowChanged event is fired and 'Commit' is passed as DataRowChangeEventArgs.Action argument.
  • If "Console.WriteLine(table.Rows[0][0]);" is inserted before line 51, default version of the data is accessed(via Reflector) and "100" is printed.
  • If "Console.WriteLine(table.Rows[0][0, DataRowVersion.Current]);" is inserted before line 51, "10" is printed.
  • If "Console.WriteLine(table.Rows[0][0, DataRowVersion.Current]);" is inserted after line 51, "100" is printed.
  • If "Console.WriteLine(table.Rows[0][0, DataRowVersion.Original]);" is inserted after line 51, "10" is printed.
  • If "table.Rows[0].AcceptChanges(); Console.WriteLine(table.Rows[0][0, DataRowVersion.Original]);" is inserted after line 51, "100" is printed.
The experiment confirms the following DataRow behaviors:
  1. DataRow.BeginEdit method temporarily suspends events.
  2. DataRow.EndEdit method invokes 1 RowChanged event.
  3. DataTable.AcceptChanges method invokes 2 RowChanged events for each row modified.
  4. The default version of DataRow is updated after DataRow.EndEdit method is called.
  5. The original version of DataRow is updated after DataRow.AcceptChanges method is called.
So why should I care about BeginEdit method? Without calling BeginEdit method, for each column in a row I modify, one RowChanged event is fired. If 10 columns per row are modified, 10 RowChanged events are fired for every modified row. If the DataTable is updated by a background thread, and is attached to a data-bound control, say, DataGridView, which is controlled by a UI thread. Those updates would cause too many events fired and might result in some weird behaviors of that data-bound control. DataRow.BeginEdit method allows us to suspend events temporarily. After completing modification, we call EndEdit or AcceptChanges method to notify that data-bound control to update changes.

Note: To update a data object bounded to a UI control from a background thread, be sure to read the article first.

Wednesday, August 29, 2007

Links for 2007-08-29

Article
  1. Using Updater Block
    • This step-by-step guide could save me a lot of time and be sure to read the 'Addendum' section under step 8 to know how and when Updater Block kicks in.
    • Though this guide gives a quick introduction, I followed the sample code, 'SimpleAppStart', accompanied with the Microsoft.ApplicationBlocks.Updater.
    • Here is how I use the block. Main program calls System.Diagnostics.Process.Start() to pass control to the updater program. In the updater program, Singleton is enforced via Mutex object before update process begins. After the process is over, the updater program calls System.Diagnostics.Process.Start() again to pass control back to main program.

Tuesday, August 14, 2007

"Why Not?" Book Review


I finished the book over the weekend. Compared with other creativity books I've read, this one has many examples in the public sector, like how to be innovative in the legislation or in managing a library. The authors propose 2 sets of tools for generating ideas.
  • Thinking outside the box
    1. What would Croesus do? - Assumed you have unlimited resources, what would you do?
    2. Why don't you feel my pain? - Internalize the external effects in problem solving.
    3. Where else would it work? - Apply solutions in one context to other contexts.
    4. Would flipping it work? - Look for symmetry and/or asymmetry in the problems.
  • Thinking inside the box - Identify the boundary of the box, that is, look for principles or properties of problems or solutions as guides while searching for the solutions.
Another area which differentiates the book from other creativity books I've read is the emphasis on implementation. The authors talked about how to pitch ideas in the last chapter. However, not every new idea can create new business. So following the spirit of open-source movement in the software industry, the authors built a website for readers to share ideas. Publishing your ideas might bring in big rewards as people might ask you to help them implement your ideas.

Saturday, August 11, 2007

Links for 2007-08-11

Web Site:
  1. Read This!
Blog:
  1. CruiseControl.NET Demo
    • See how continuous integration works.
Article:
  1. Windows Debuggers: Part 1: A WinDbg Tutorial
    • It seems that only Part 1 is published.

Thursday, August 9, 2007

Links for 2007-08-09

Blogs:
  1. Two Things I Regret
    • One thing I regret in my current job is I should have asked for a higher pay, considering the works I have done for my employer. Sigh...
  2. Catalogs of Data Visualization

Monday, August 6, 2007

A 'feature' of System.Windows.Forms.ComboBox

In a program I maintain, I found a strange behavior of System.Windows.Forms.ComboBox in .Net 1.1. That is, when I dynamically change Combox.SelectedIndex, Combox.SelectedValue returns null. To retrieve 'SelectedValue', I have to use the following code, ComboBox.Items[ComboBox.SelectedIndex][ ComboBox.ValueMember]. Is it a feature or a bug?

Links for 2007-08-05

Articles
  1. A Custom Message Box Part1, Part2
  2. A Pure .NET Single Application Instance/Instancing Solution
    • I didn't realize the value of this article until recently I fixed a bug which can be reproduced only when 2 instances of a program are running at the same time. Prevention is the best solution.

Wednesday, August 1, 2007

.NET 2.0 Interoperability Recipes - Chapter 1

I just finished the first chapter of .NET 2.0 Interoperability Recipes. Several points mentioned in the chapter are written down here for my reference.
  • To find the entry point of a function in a dll, use dumpbin.exe to check the exact function name.
  • One solution to the memory allocation problem in unmanaged functions is to write a c++ wrapper to convert the unmanaged data structures to managed ones, (check out Marshal methods) and free the unmanaged memory allocation before returning from the c++ wrapper.

Sunday, July 22, 2007

Links for 2007-07-22

News
  1. True random number generator goes online
    • "the 'Quantum Random Bit Generator' (QRBG121), which is the engine for QRBGS, is a fast non-deterministic random bit (number) generator whose randomness relies on intrinsic randomness of the quantum physical process of photonic emission in semiconductors and subsequent detection by photoelectric effect".
Sample Chapter
  1. Foundations of F#

Wednesday, July 18, 2007

Links for 2007-07-18

Article
  1. 10 Rules for IT Job Success
    • The key to success is 'positive thinking'.

Tuesday, July 17, 2007

Links for 2007-07-17

Blogs
  1. Internal Code Reuse Considered Dangerous
  2. Is your code worthless?
    • Don't reinvent the wheel but is "Microsoft Data Application Blocks" reinventing the wheel?

Sunday, July 15, 2007

Links for 2007-07-15

Articles:

Monday, July 9, 2007

Links for 2007-07-09

MSDN Articles
  • System.AddIn namespace in Visual Studio Orcas
    • CLR Inside Out: .NET Application Extensibility
    • CLR Inside Out: .NET Application Extensibility, Part 2
      • I think the key to understand the mechanism is to understand the interaction between the components, as described in the following paragraph,
        ..., it first creates the AppDomain that the add-in is going to run in and then loads the add-in, add-in view, add-in side adapter, and contract assembly into the newly created domain. ... Next, the system instantiates the add-in with its default constructor and the add-in adapter and passes the add-in, typed as the add-in base, to the adapter's constructor. Then it passes the add-in adapter across the AppDomain boundary typed as its contract, loads the host-side-adapter assembly, and instantiates an instance of the host adapter, passing the add-in adapter, typed as the contract, to its constructor. Finally, it returns the host-side-adapter to the host, typed as the host add-in view.
Sample Chapter
  • Beautiful Code
    • Chapter 4 - Finding Things : The author demonstrated text searching technique using regular expression in Ruby and binary search algorithm in Java.

Saturday, June 2, 2007

A Presentation for AI course

I am taking Artificial Intelligence at NTUST. For the final presentation in this course, I chose the paper published at ICML 20006, "Reinforcement Learning for Optimized Trade Execution". The problem studied in this paper can be defined as follows, "to sell ( or buy) V shares of a given stock within a fixed time period H, in a manner that maximizes the revenue received ( respectively, minimizes the capital spent)." An RL approach by modifying Q-Learning algorithm is applied to try solving the problem. There are several questions I have while reading the paper. Hope someday I can find out the answers.
  1. To compare the performance, the authors assume an idealized policy which can execute all V shares immediately at the mid-spread. Why the authors 'always' expect to do worse than this idealized policy? If the price moves to the advantage of a trader within the time period H, the idealized policy can't do better.
  2. Following question 1, the authors define as the measurement, "the trading cost of a policy as the underperformance compared to the mid-spread baseline". Does the authors mean the outperformance of their policies is excluded from the trading costs?
  3. In the paper, it is stated, "our reward function captures the most important aspects of execution - bid-ask spread, market impact, opportunity cost, etc." I don't see how it's been done in the paper.

Thursday, April 12, 2007

Setting up Informix ODBC Connection

  1. Install Informix Client SDK

  2. Launch SetNet32 which was just installed and configure locale variables. Then click "Confirm" button to save the setting, ignoring the alert message, as shown in the first picture below.

  3. Setting up Informix ODBC connection as shown in the second and third picture.


Monday, March 5, 2007

A Failover Solution in .NET

Recently, I am developing a windows service for monitoring stock position in the company. During the testing phase, my boss asked me to add a failover mechanism to the application. That means I have to change a stand-alone program to a distributed one at the final stage! After reviewing the architecture of the program, I concluded the only area I need to synchronizeamong the services is an Order DataTable, while the rest data can be retrieved from the samedata source and should be synchronized automatically. So I need a way to synchronize the Order DataTableand it is best to be a free .Net solotion.

I have found the following failover solutions/products:
  1. Distributed Hashtable(DHT)
  2. GigaSpaces
  3. Oracle Berkeley DB
  4. P2P architecture (P2P may not be applicable to the program, but i think it looks interesting.)

These solutions either cost money or not a .NET solution. That means either I have to ask for money which is difficult, if not possible, or I have to change many parts of my code to adopt the solutions. Then I came across the article, "Implementing a Publisher/Subscriber model for .NET Remoting". Looks like .NET Remoting is exactly what I need. That is, I will make my windows service publish and subscribe to the same remote object. Whenever one service processes an order, it passes the order to another service to be processed. Then, the state of the two window services remains consistant. Whenever one service is down or generates no response, another service is ready to process orders instantly.

Monday, January 8, 2007

Compute Subtotals Using RunningValue Function

I was working on a report last week. The report looked simple, but I was stuck when I needed to sum a subtotal of some column for the first N records and another for the rest in each group after grouping all the records by some columns. It caused me trouble because I wanted to access the database only once and let SQL Server Reporting Services take care of the presentation.

I found the function, RunningValue(Expression, Function, Scope) handy and it solved my problem. For the subtotal of the First N records, the RunningValue function was called as follows,
= RunningValue(IIF( Fields!RowNum.Value <= N, Fields!SomeCol.Value , Nothing), SUM, "Group1")

Notes:

  1. One needs to have the row number ready before passing it to SQL Server Reporting Services, because RunningValue can't access the row numbers computed using RowNumber function.
  2. One has to use the 'Nothing' parameter in the IIF function. It can not be zero, or Reporting Services would throw an error at run time. That took me a while to find the solution here.
  3. The SQL Server Reporting Services forum is really helpful.