C++ compiler

http://nuwen.net/mingw.html#install

I am not a C++ developer, but recently I have to set up a C++ development environment, here is the notes:

1. download Eclipse CDT here

There is preference: automatically build, save....
CTRL + B: build

2. Download C++ compiler here

3. Extract it to C:\

put C:\MinGW\bin in your windows PATH.

4. how to include a header

<#>include C:\includes\myHeader.h

5. how to use cout

#include
using namespace std;

Portable Evernotes

http://dl.dbank.com/c09t63uqld

Copy Files from Remote Machine

Quickly setup a AspectJ project

1. download AJDT for eclipse

Eclipse 3.6 Update Site URL:http://download.eclipse.org/tools/ajdt/36/update
Eclipse 3.5 Update Site URL:http://download.eclipse.org/tools/ajdt/35/update

2. Create a AspectJ project, and you are all set.

You might find some syntax error in aspect class, ignore it.

AspectJ, Spring, and Guice

Recently, I have some time to take a look at these 3 things, mainly on AOP part.

Spring has a very good support for AOP, but the main problem is, all the beans need to be managed by Spring's container, otherwise, AOP won't work. This is ideal if you have a completely Spring-powered project. But it won't do you any good if you are not.

[Not exactly: Spring could inject values into non-Spring bean]

1. define bean in config as abstract plus the configurations, the id, let's see, is "testBean1"
2. add @configurable("testBean1") before the class in .java file.
3. add in config file.

It seems behind the scene, it's still AspectJ is doing all the work.

Guice has the same problem, the Java classes have to be binded by Guice's injector to have AOP work.

That leaves only one choice, AspectJ.
With AspectJ, we could have a very powerful tool to work on big project.

Imagine your boss gives you this task: log the result whenever a method named getMyMoneyBack() gets called. Sound easy? Not so fast, the problem is getMyMoneyBack() exists in thousands of classes, and they are called by millions of times. You really don't want to go to millions of places to put your log code there, do you?

With AspectJ, life is much easier.

You define a point cut like:

pointcut logGetMyMoneyBack() : call (* *.getMyMoneyBack(..))

String around() : logGetMyMoneyBack
{
String result = proceed();
System.out.println(result );
return result;
}
return proceed();

Guice


Here is the idea:

You have a class A, which depends on class B and class C.
First step, you want to create interface iB for class B and interface iC for class C, why? won't you rather depend on an interface than an concrete class? This will give a flexibility to use whatever classes you like to use, as long as they implement the interface. For example, B is concrete class for credit card processing, when you do the test, you don't want to call B to do a real credit card processing, right? Ok, so are we good to depend on interface?

Second step, in the run time, which concrete class to use? Guice provides a simple way, called Module, what Module does is binding interface with concrete class. So you could have many Modules, for example, in Module1, you bind iB to class B1, and iC to C1, while in Module2, you could bind iB to class B2, and iC to C2. In runtime, you could decide to use which Module as you like.

Ok, all these are just theories, now let's dive into the bolts and nolts.

Class A have 2 dependencies in iB and iC, in its constructor, you need add an annotation, @Inject, this signal Guice that we want to do Dependency Injection.

In the codes where you want to use class A, you don't need call A's constructor, instead, you use Guice injector

Injector injector = Guice.createInjector(new Module1());
Class A = injector.getInstance(A.class);

That's it.
Let's calm down to understand what's we have just done, it's a lot.

1. We create a Class A instance without calling its constructor.
2. We have binded its 2 dependencies into class A. not just interfaces, but real concrete classes: B1 and C1.

Now you see, A doesn't even know anything about B1 and C1, they are completely decoupled. Their only glue is interface iB and iC. And Guice injector makes it super easy to bind them together in run time. aHa....

Also, you Module1 is also decoupled from Class A, if A doesn't have the annotation, Module1 will just leave it alone.

todoist



SQLite Data Types

In Version 3:

Null:
INTEGER:
REAL:
TEXT:
BLOB:

No Boolean type.
No Date and Time type, but the build-in Date and Time function could store Date and Time as TEXT, REAL or Integer.

TEXT as ISO8601 Strings (YYYY-MM-DD HH:MM:SS.SSS)
REAL
INTEGER

Flex XML

Here is what I have

xml  
      Date   
    2010-10-15 
 /Date  
Number
       1000 
 /Number
 xml

The question is how can I get the vale of Date and Number?

if myXML is used to refer to the above XML

var strDate:String = myXML.Date[0].toString();
var strNumber:String = myXML.Number[0].toString();

Flex eventhandler mode

This weekend, I have a problem with Flex, to say specifically, with Flex's Event Handle mode.

Here is my situation, I need loop through SP500 symbols, and send the url to Yahoo web site to get some data.

When I sent a query, it will take some time to get the data back, the way Flex handles this is using Event Handler. It will add a listener to URLStream object, which will listen to complete event. When the stream is done loading, URLStream will be notified, and will proceed to do something else, like put the stream into database.

Now I got problems at the hand. You see, sending query and loading stream is separated, they are not in liner relationship. What will happen is you will send 500 queries to Yahoo server, then you wait for the data coming back to you one by one, not necessarily in the sending order.

First problem is, because I send the 500 queries together, Yahoo decides not like it, and I will get some timeout error.

Second problem is, when the data comes back, I need know the data is for which symbol, so I need pass the symbol to the complete event handler, fortunately, I found some solution:

urlStream.addEventListener(Event.COMPLETE, function(e:Event):void{loadedEventHandler(e, symbol);});

You see, that let me pass symbol to complete event handler.

addEventLister's signiture is (Event.COMPLETE, eventHandlerFunctionName:String)

But the eventHandlerFunction has to be like functionName(e:Event), so my own's event handler doesn't qualify the signature.

what this does, add a more standard event handler above my own event handler, then call my own event handler.

This resolve the problem, but the first problem is hard to resolve, eventually, I have to use Java to do what I want to do.

SQLite vs MySQL

Here is a list of well-known Users of SQLite:


Here is a debate regarding SQLite vs MySQL


It seems to me, in 99% case, SQLite is good for production use.

SQLiteJDBC

SQLiteJDBC is a Java JDBC driver for SQLite. Link

Sample code:

It will create the test.db file in the root directory of the project.

Connection conn = DriverManager.getConnection("jdbc:sqlite:test.db");
Statement stat = conn.createStatement();
stat.executeUpdate("drop table if exists people;");
stat.executeUpdate("create table people (name, occupation);");
PreparedStatement prep = conn.prepareStatement( "insert into people values (?, ?);");
prep.setString(1, "Gandhi");
prep.setString(2, "politics");
prep.addBatch();
prep.setString(1, "Turing");
prep.setString(2, "computers");
prep.addBatch();
prep.setString(1, "Wittgenstein");
prep.setString(2, "smartypants");
prep.addBatch();
conn.setAutoCommit(false);
prep.executeBatch();
conn.setAutoCommit(true);
ResultSet rs = stat.executeQuery("select * from people;");
while (rs.next()) 
{
      System.out.println("name = " + rs.getString("name"));
      System.out.println("job = " + rs.getString("occupation"));
}
rs.close();
conn.close();

Some Java Stuff

Int vs Long vs Double vs REAL

string to int
Integer.parseInt(myString);

int to string
String.valueOf(myInt);

String to java.util.Date

SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
java.util.Date tradeDate = formatter.parse(dateString);

String strFormatDate = formatter.format(tradeDate);

java.util.Date to long
tradeDate.getTime();

java.util.Date to long to java.sql.Date
java.sql.Date sqlDate = new java.sql.Date(tradeDate.getTime());

StringTokenNizer vs split
String[] dateValues = value.split("-")

SQLite

I didn't realize that Adobe Air is actually using SQLite engine until this morning.

Then I found SQLite Browser

It's a powerful tool to manage SQLite DataBase, you could create/update/delete tables/columns, and you could also issue SQL commands against table.

Now this solves a problem for me:

I could use Flex Air to build fancy UI against local DataBase without worrying about DataBase driver....you know, these complicated stuff. For me, I just need a simple relational database, I don't care security, I don't care users....just simple database that I could store data persistently.

SQLite Browser allows to import .CSV file into Table directly, it could even extract the first row as the column name if you choose.

Regarding the limits: see here but here is the recap:

Bear in minds, all these limits are configurable, just to avoid making things complicated, let's just take whatever default comes.

Maximum number of Columns: 2000
Maximum length of a string or BLOB: 1 Billion bytes -- about 954 MB

Now, the sky is just open....