Showing posts with label Open Source. Show all posts
Showing posts with label Open Source. Show all posts

Monday, April 21, 2008

Links for 2008-04-21

Articles:
  1. Simplify Ajax development with jQuery - jQuery allows us to do DOM scripting, event handling, HTML animation, Ajax and more.
  2. Don't burn your Bridges - "It is not good to leave in anger. I advise that you don't burn your bridges"?? I think the point is don't express your anger when you leave.

Sample Chapter

  1. jQuery in Action

Monday, April 7, 2008

First Taste of SubSonic

Having heard about SubSonic for almost a year, I finally decided to give it a try. I used SubSonic 2.1 Beta 2 and connected to Oracle9i database. Here were the two errors I encountered in the process, mostly related to stored procedures, and how I worked around the troubles. For the first error, I can use the precompiled SubSonic.dll directly. But to fix the second error, I had to modify the SubSonic source code.

The first error was related to the parameters I pass to a stored procedure. I got the following error after executing the stored procedure. Checking the source code, I found SubSonic add ':' as a prefix for each parameter name of stored procedures. Removing the colon before calling the Execute method solve the problem.Publish Post
System.Data.OracleClient.OracleException: ORA-06550: line 1, column 44:
PLS-00103: Encountered the symbol ":" when expecting one of the following:

( - + case mod new not null <an identifier>
<a double-quoted delimited-identifier> <a bind variable> avg
count current exists max min prior sql stddev sum variance
execute forall merge time timestamp interval date
<a string literal with character set specification>
<a number> <a single-quoted SQL string> pipe
The symbol "( was inserted before ":" to continue.
The second error was related to the output parameter of a stored procedure. The output parameter I expected was a DateTime but I kept getting the following error.
System.Data.OracleClient.OracleException: ORA-06502: PL/SQL: numeric or value error
Checking the source code, I found the AddParams method in OracleDataProvider class didn't set the parameter direction. I checked MySqlDataProvider.cs and made a modification to OracleDataProvider.cs in the same manner. The error was gone. Also, I found the CheckoutOutputParams method in MySqlDataProvider.cs didn't exist in OracleDataProvider. So I also added the same logic to OracleDataProvider.

69 private static void AddParams(OracleCommand cmd, QueryCommand qry)

70 {

71 if(qry.Parameters != null)

72 {

73 foreach(QueryParameter param in qry.Parameters)

74 {

75 OracleParameter sqlParam = new OracleParameter();

76 sqlParam.DbType = param.DataType;

77 sqlParam.OracleType = GetOracleType(param.DataType);

78 sqlParam.ParameterName = param.ParameterName;

79 sqlParam.Value = param.ParameterValue;

80 if (qry.CommandType == CommandType.StoredProcedure)

81 {

82 switch (param.Mode)

83 {

84 case ParameterDirection.InputOutput:

85 sqlParam.Direction = ParameterDirection.InputOutput;

86 break;

87 case ParameterDirection.Output:

88 sqlParam.Direction = ParameterDirection.Output;

89 break;

90 case ParameterDirection.ReturnValue:

91 sqlParam.Direction = ParameterDirection.ReturnValue;

92 break;

93 case ParameterDirection.Input:

94 sqlParam.Direction = ParameterDirection.Input;

95 break;

96 }

97 }

98 cmd.Parameters.Add(sqlParam);

99 }

100 }

101 }

Sunday, March 16, 2008

Open Source Rule Engines

  1. Implement business logic with the Drools rules engine - The author used Drools rule engine to demonstrate how business logic could be externalized in an application and possibly maintained by end users. Rules are stored in xml format and loaded into a rule engine at runtime. A rule is composed of 3 parts, parameter, condition and consequence. Parameters are passed in by the engine. If condition is met, then the instructions in consequence are executed. The instructions are defined in java language.
  2. Getting Started With the Java Rule Engine API (JSR 94): Toward Rule-Based Applications - Java Rule Engine API is composed of rules administrator API and runtime client API. Users call the administrator API to register and unregister RuleExecutionSet and call client API to apply the RuleExecutionSet. Several open source rule engines were mentioned in the article as well, including Jess, Drools, FairIssac Blaze Advisor, ILog JRules, etc.

Monday, March 10, 2008

Free Icons

I found the websites via here and here. Great stuff!
  1. 35 (Really) Incredible Free Icon Sets
  2. 90 Free High Quality Icon Sets
  3. Free Icons Download

Managed ThreadId

Managed Stack Explorer allows one to trace stacks for .NET 2.0 applications at run time. This is handy for tracing deadlock problems. But the project I worked on was based on .NET 1.1. What a pity! After a second thought, I realized that I just need to keep track of the resources locked by threads. When deadlock happened, that is, when a thread issued lock request over some resource but failed after a predefined period of time, I dumped the stack frame of the threads locking the resource. Then the problem boiled down to how to identify the resource locking threads. Originally, I used System.AppDomain.GetCurrentThreadId to identify a thread. But according to the documentation, this id is not stable.
Note An operating-system ThreadId has no fixed relationship to a managed thread, because an unmanaged host can control the relationship between managed and unmanaged threads. Specifically, a sophisticated host can use the Fiber API to schedule many managed threads against the same operating system thread, or to move a managed thread among different operating system threads.
Instead, to identify a thread in .NET 1.1, use Thread.GetHashCode. For applications in .NET 2.0 and later, use Thread.ManagedThreadId.

Wednesday, February 27, 2008

ORA-01460 in SOCI

I mentioned before about the SOCI project. Recently, I was planning to adopt the library(version 2.2.0) into my project. However, while using the library to connect to Oracle 9i, I encountered a weird exception. The trouble I had was if I use soci::use(std::string) for more than one time in a sql query, then I get ORA-01460 error. For example, I used the following code to reproduce the error.
std::string prodid1("2330"), prodid2("2885");
SOCI::Row r;
SOCI::Statement st = (sql.prepare <<
"select * from product where prodid in (:prodid1, :prodid2)",
SOCI::use(prodid1), SOCI::use(prodid2),
SOCI::into(r));
It seemed related to the binding process in the function soci::StandardUseType::bind. After tweaking the source code for a while, I found by modifying the fuction definition as follows, the error was gone.
void OracleStandardUseTypeBackEnd::prepareForBind(
void *&data, sb4 &size, ub2 &oracleType)
{
...
case eXStdString:
oracleType = SQLT_STR;
// 4000 is Oracle max VARCHAR2 size; 32768 is max LONG size
//size = 32769;
size =sizeof(static_cast<std::string *>(data)->c_str());
...
}

Tuesday, February 19, 2008

WinUnit: A Unit Testing Tool for Native C++ Applications

In this MSDN article, the author introduced WinUnit, a unit testing tool for Native C++ applications on Windows platform.

To use this tool, users need to call a set of macros the author provided to write test programs, compile test programs into Dlls and run test programs against WinUnit, a DOS program. Because there is no reflection capability built in C++ language, the author took advantage of DLL exports to invoke test functions in WinUnit program.

Several references were mentioned in the article.

Sunday, February 10, 2008

SOCI (Cont'd)

This article explained how SOCI can be extended to support user-defined types. The author applied traits technique of generic programming in c++, and showed that by making use of template specialization via TypeConversion<T>, SOCI provided a noninvasive mechanism for extending SOCI.

Since std:tm is supported natively by SOCI, to work with boost::gregorian::date, a user only needs to provide the following template specialization and the compiler will make the right conversion for us.
#include <iostream>
#include <soci.h>
#include <boost/date_time/gregorian/gregorian.hpp>

using boost::gregorian::months_of_year;
using boost::gregorian::date;

namespace SOCI
{
template<> struct TypeConversion<date>
{
typedef std::tm base_type;
static date from(std::tm& t)
{
date d( t.tm_year + 1900,
static_cast<months_of_year>(t.tm_mon + 1),
t.tm_mday );
return d;
}

static std::tm to(date& d)
{
std::tm t;
t.tm_isdst = -1;
t.tm_year = d.year() - 1900;
t.tm_mon = d.month() - 1;
t.tm_mday = d.day();
t.tm_hour = 0;
t.tm_min = 0;
t.tm_sec = 0;
std::mktime(&t);
return t;
}
};
};
#endif

Friday, February 8, 2008

SOCI: Simple Oracle Call Interface

This article introduced a simple C++ database library, SOCI. According to the author, users only need to know two classes, Session and Statement, to complete most of interactions between client programs and database servers.

The following sample, excerpted from the article, demonstrated the simplicity of the library.
  • Session and Statement classes hide OCI calls from the users.
  • Free function use() binds variables to placeholders in the SQL statements.
  • Free function into() populates the variables with the values returned by select statements.
  • Shift operator in the Session enables storing a query and starts creating a temporary object that handles the rest of the expression.
  • Comma operator stores parameter information returned by use and into functions into the temporary object for later use.
  • The temporary object executes the sql statements in its destructor.
#include "soci.h"
#include <iostream>

using namespace std;
using namespace SOCI;

int main()
{
try
{
Session sql("DBNAME", "user", "password");
// example 1. - basic query with one variable used
int count;
sql << "select count(*) from some_table", into(count);
// example 2. - basic query with parameter
int id = 7;
string name;
sql << "select name from person where id = " << id, into(name);
// example 3. - the same, but with input variable
sql << "select name from person where id = :id", into(name), use(id);
// example 4. - statement with no output
id = 8;
name = "John";
sql << "insert into person(id, name) values(:id, :name)", use(id), use(name);
// example 5. - statement used multiple (three) times
Statement st1 = (sql.prepare <<
"insert into country(id, name) values(:id, :name)",
use(id), use(name));
id = 1; name = "France"; st1.execute(1);
id = 2; name = "Germany"; st1.execute(1);
id = 3; name = "Poland"; st1.execute(1);
// example 6. - statement used for fetching many rows
Statement st2 = (sql.prepare << "select name from country", into(name));
st2.execute();
while (st2.fetch())
{
cout << name << '\n';
}
}
catch (exception const &e)
{
cerr << "Error: " << e.what() << '\n';
}
}

Esper: Event Stream Processing and Correlation

I mentioned about Esper before(here). Esper allows users to submit continuous queries to its engine and sends out alerts whenever conditions match user-defined queries. In this article, the authors showed code snippets to demonstrate Esper's usage.
  1. Configure the engine using API or an XML file.
  2. Register continuous queries.
  3. Attach listeners to the queries.
For the engine to tap into event streams, according to the document, it is accomplished by sending events to the engine via the runtime interface.

Esper seems easy to use and, I think, it looks promising to gain popularity.

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.

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.

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.

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.