Archive for 2008

Moving Windows remotely with .NET

A colleague of mine has a dual-monitor windows system.

Unfortunatly he has a different monitor setup for home and work (work – 2nd monitor on the left; home – 2nd monitor on the right). Now when you work with certain Java applications which save their position on their own you come to the point where an window pops up out of the viewing range.

Now you hav nearly now way to move that window, because you can’t click it. Moving over the task bar doesn’t work either. So I wrote a simple Application which can move the lost window back into the viewing range.

Here a bit out of the c# code:

[ DllImport("user32.dll") ]
static extern IntPtr GetForegroundWindow(); 

[DllImportAttribute("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);

[DllImport("user32.dll", ExactSpelling = true, CharSet = System.Runtime.InteropServices.CharSet.Auto)]
private static extern bool MoveWindow(IntPtr hWnd, int x, int y, int cx, int cy, bool repaint);

...
private void timer1_Tick(object sender, System.EventArgs e)
{
	IntPtr temp  = GetForegroundWindow();
	if( me != temp)
	{
		window = temp;
		label1.Text = window.ToString();
			RECT t = new RECT();
		bool r = GetWindowRect(window, out t);

		posx = t.Location.X;
		posy = t.Location.Y;
		sizex = t.Width;
		sizey = t.Height;
		label1.Text = label1.Text + "\nx: "  + t.Location.X+ "\ny: " + t.Location.Y
				+"\nwidth: "+sizex + "\nheight: " + sizey;
		}
	}

private void button2_Click(object sender, System.EventArgs e)
{
	//right
	posx = posx +10;
	MoveWindow((IntPtr)window, posx, posy , sizex, sizey, true);
}

This is just to get a basic idea what I’ve done here. You can also look at the complete source code yourself (vs2003 project is attached) or just use the application as is (although it is pretty ugly – more like a proof of concept.

downloads:

follow-up here

    , ,

    No Comments

    use yahoo finance streaming api

    In the past I used this ruby script to poll for the current stock data and put it into a database to create a little history.

    Recently I saw a new feature on the yahoo finance homepage. Now it is possible to enable a streaming option and then you get a live update on certain values via AJAX. So I thought why not get this feature and let yahoo stream the content to the client instead of polling the server from time to time.

    So I tried to capture the javascript request with wireshark, so that I could reproduce it. This is what it looks like:

    GET /streamer/1.0?s=^GDAXI,USD=X&o=^N225,LHS.F,JI4.F,EEX.F,HEI.F,CBK.F,PRE.F,NDX1.F&k=c10,g00,h00,l10,p20,t10&j=c10,l10,p20,t10&r=0&marketid=us_market&callback=parent.yfs_u1f&mktmcb=parent.yfs_mktmcb&gencallback=parent.yfs_gencb HTTP/1.1
    Host: streamerapi.finance.yahoo.com

    Here is what I got on this request so far:

    parameter ‘s’ -> symbol on the main site (what you currently looking at)

    parameter ‘o’ -> that is the ticker on the top

    parameter ‘k’ and ‘j’ -> that are the values that are transfered

    c10 -> unknown

    g00 -> day low

    h00 -> day high

    l10 -> current price

    p20 -> unknown

    t10 -> timstamp

    a00 -> ask

    b00 -> bid

    With that data you can build a Push-Client with your own custom data. Here is a sample Request for what I needed.

    wget -Obla 'http://streamerapi.finance.yahoo.com/streamer/1.0?s=^GDAXI,USD=X&o=BEI.F,SIE.F,PRA.F&k=l10,a00,b00,g00,h00&j=l10,a00,b00,g00,h00&r=0&marketid=us_market&callback=parent.yfs_u1f&mktmcb=parent.yfs_mktmcb&gencallback=parent.yfs_gencb'

    (Streaming the current ‘ask’, ‘bid’ and ‘price’ values for the stocks ‘BEI.F’,'SIE.F’ and ‘PRA.F’.)

    The response for that looks like that:

    <html>
    <head>
    <script type='text/javascript'> document.domain='finance.yahoo.com';</script>
    </head>
    <body></body>
    <script>try{parent.yfs_mktmcb({"unixtime":1228213139,"open":1228228200,"close":1228251600});}catch(e){}</script>
    <script>try{parent.yfs_u1f({"USD=X":{l10:"1.00",a00:"1.00",b00:"1.00",g00:"0.00",h00:"0.00"}});}catch(e){}</script>
    <script>try{parent.yfs_u1f({"BEI.F":{l10:"42.31",a00:"41.70",b00:"41.53",g00:"42.31",h00:"43.95"}});}catch(e){}</script>
    <script>try{parent.yfs_u1f({"SIE.F":{l10:"44.46",a00:"44.26",b00:"44.20",g00:"44.40",h00:"47.55"}});}catch(e){}</script>

    No you can parse that document for the requested Data. But be carefull because the html structure is never closing (at least not as lang as the streaming goes on).

    , , ,

    10 Comments

    Tibco EMS with database backend (postgresql)

    I recently tried to build a JMS Server with database backend. The chosen product was the TIBCO EMS Server. The Server brings its own database support over hibernate.

    Unfortunately TIBCO supports only Oracle,Mysql and DB2 by default. Lucky me, I needed an installation for Postgres but this shouldn’t be a big deal, because hibernate supports postgres as well. You just have to modify the hibernate config.

    First you should install the EMS server and hibernate (version provided by Tibco). After that let’s start configuring.

    To have everthing in the database you need 3 databases (3 separate EMS stores). For me I used the following 3 stores:

    1. emsmeta -> for metadata content
    2. emsnf -> for nonfailsafe data
    3. emsf -> for failsafe data

    I used the same account for all 3 databases (just easier for testing purposes).

    Setup the stores in the stores.conf in the EMS folder:

    [$sys.meta]
    type=dbstore
    dbstore_driver_url=jdbc:postgresql://localhost/emsmeta
    dbstore_driver_username=ems
    dbstore_driver_password=ems
    
    [$sys.nonfailsafe]
    type=dbstore
    dbstore_driver_url=jdbc:postgresql://localhost/emsnf
    dbstore_driver_username=ems
    dbstore_driver_password=ems
    
    [$sys.failsafe]
    type=dbstore
    dbstore_driver_url=jdbc:postgresql://localhost/emsf
    dbstore_driver_username=ems
    dbstore_driver_password=ems

    After that you have to change you tibemsd.conf file.The following line is a sample what you should add. Additionally you should add tha path to your jdbc driver (in this sample the last parameter – change it to your config). You also have to add the path to your JVM (here it is the debian lenny default).

    dbstore_classpath       = ../../../components/eclipse/plugins/com.tibco.tpcl.org.hibernate_3.2.5.001/hibernate3.jar:../../../components/eclipse/plugins/com.tibco.tpcl.org.com.mchange.c3p0_0.9.1.001/c3p0-0.9.1.jar:antlr-2.7.6.jar:asm-attrs.jar:asm.jar:cglib-2.1.3.jar:commons-collections-2.1.1.jar:commons-logging-1.0.4.jar:dom4j-1.6.1.jar:ehcache-1.2.3.jar:jta.jar:/usr/local/bin/oracledrivers/lib/ojdbc5.jar:/home/jens/tibco/tpcl/5.6/jdbc/postgresql-8.3-603.jdbc3.jar
    
    ## db section
    #dbstore_driver_name     = oracle.jdbc.driver.OracleDriver
    #dbstore_driver_dialect  = org.hibernate.dialect.Oracle10gDialect
    dbstore_driver_name     = org.postgresql.Driver
    dbstore_driver_dialect  = org.hibernate.dialect.PostgreSQLDialect
    jre_library             = /usr/lib/jvm/java-6-sun/jre/lib/i386/server/libjvm.so

    As you can see changing databases is easy. You just have to change the driver_name and driver_dialect of hibernate.

    After that you have the basic configuration ready. Next thing to do is to initialize the dabases. For that task Tibco provides a tool which generates the proper sql-statements.

    You can run the following command in your shell and get the sql as output.

    java -jar tibemsd_util.jar -tibemsdconf tibemsd.conf -createall

    For some reason the create sql-statements had no ‘;’ at the end of every command. So you can’t just pipe the output to psql. You have to do it old school.

    After that you can start the EMS Server and it stores all data to the selected database.

    , , ,

    7 Comments