2009-01-20

Remembering to update include settings for AutoIT when upgrading versions

When I updated AutoIT it wiped my include path settings. So here is the script I used to show and update them (I used the great Koda gui builder tool):

#include <GUIConstants.au3>

#Region ### START Koda GUI section ### Form=O:\Automation\Include\AutoitIncludeSettings.kxf
$Form2 = GUICreate("Dialog", 329, 238, 347, 263)
GUISetIcon("D:\003.ico")
$GroupBox1 = GUICtrlCreateGroup("", 8, 1, 297, 193)
$Label1 = GUICtrlCreateLabel("Registry key for AutoIt searching for include files. (seperate with ;)", 24, 20, 230, 30)

$Edit1 = GUICtrlCreateEdit(RegRead( "HKEY_CURRENT_USER\Software\AutoIt v3\AutoIt","Include"), 16, 48, 281, 137)
;GUICtrlSetData(-1, "AEdit1")

GUICtrlCreateGroup("", -99, -99, 1, 1)
$Button1 = GUICtrlCreateButton("&OK", 65, 203, 75, 25, 0)
$Button2 = GUICtrlCreateButton("&Cancel", 162, 203, 75, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
$DoAction = False
Exit
Case $Button1
$DoAction = True
ExitLoop
Case $Button2
$DoAction = False
ExitLoop
EndSwitch
WEnd

If $DoAction Then
RegWrite("HKEY_CURRENT_USER\Software\AutoIt v3\AutoIt","Include", "REG_SZ", GUICtrlRead($Edit1))
EndIf

2009-01-19

Getting Python to work

I have been investigating Python as I thought it might have a slightly simpler syntax from Ruby (I am finding it takes time to switch syntax from Mathematica, C#, VB etc) , be more better supported on .NET eg IronPython ahead of IronRuby and better scientific support and some work done on creating an interactive platform like Mathematica/Matlab. Enthought has a prepackaged Scientific distribution.

Anyway just to say not quite as good as I hoped in that Python is the middle of a big change in syntax from 2.x to 3.x, IronPython wont install on my server and it seems to work slightly differently on different computers when driving Excel.

After playing and buying a number of tools the free ActiveState Python distribution seems to work ok. The only snag I have found so far is that the PythonWin debugger really needs to be killed and restarted to work well if you are debugging.

2009-01-08

Great installation tool

Just wanted to mark down a great down installation tool, Inno Setup that I have used for years and written by Jordan Russell in Delphi.

http://www.innosetup.com/isinfo.php

2009-01-07

Moving Outlook messages with one click

This web post has great instructions (However last time I clicked it had disappeared (I wanted the macro instructions) so I have pasted it on the bottom)

http://www.fiftyfoureleven.com/weblog/general/outlook-email-shortcuts

but the first link was broken:

http://verychewy.com/archive/2006/04/12/outlook-macro-to-move-an-email-to-folder.aspx

 

Outlook Keyboard Shortcuts to Move a Message to a Folder

Published in General on Tuesday, June 6th, 2006

Ever wished that you could click alt+1 on your keyboard and have a hilighted message sorted into the correct folder in Outlook? Me too. I've been looking for an easy solution for this for a while but never really dug in to figure it out. Now I have the answer!

Inbox Zero

So I've been following Merlin Mann's Inbox Zero series from the fringes, interested in the concepts and envious of the many mac only solutions that he provides.

I've wanted a one click solution for organizing my inbox for some time, and looked but not found the answer. Well, spurred on by my new blog (plug), and the fact that I am waaay behind on a lot of e-mail (sorry to those still waiting for a reply) I've found a solution.

Three steps to two button Outlook e-mail sorting

What I am talking about here is having the ability to use a keyboard shortcut that shunts a selected/hilighted message in your Outlook inbox into a determined folder. In this manner, you can quickly sort a busy inbox into action/response/received messages, for example.

Note that I am using Microsoft Outlook 2003 on a Windows XP setup to do this. Your mileage may vary.

The process involves three relatively simple steps:

  1. Create a macro to move the e-mail to a specified folder.
  2. Create a digital certificate for the macro.
  3. Create a toolbar and keyboard shortcut to fire the macro with ease.

So, lets look at these in details...

1. Create a macro to move the e-mail to a specified folder

A little bit of googling brought me to Outlook Macro to Move an Email to Folder. This really made things easy.

You are going to want to take the code from that example and use the instructions found at Create a macro.

Keep in mind that you need to replace _Reviewed in the following line of code with the folder where you are moving your mail to: Set objFolder = objInbox.Folders("_Reviewed"). Also, the target folder has to be in the inbox.

2. Create a digital certificate for the macro

Once you've made your macro, Outlook (or winXP) will block the macro from running if your security settings are higher than low, which most people's are. To get around this you need to add a digital signature to the macro.

Fine, so where do you get the digital signature file?

I found the answer at OFF2000: Using SelfCert to Create a Digital Certificate for VBA Projects. Follow those instructions (it's quite simple) and then come back here for the next part.

Next we need to add the signature to the macro. Also quite easy, following the instructions at Add a digital signature to a macro project.

3. Create a toolbar and keyboard shortcut to fire the macro with ease

Here I refer you to the Outlook 2003 tip o' the day which teaches one how to add a new button to the toolbar and give it a keyboard shortcut. For our purposes, on step 3 of that article you will want to choose macros from the left hand pane and then the macro you wrote from step 1 from the right hand pane.

And that's it!!

In the end it was quite simple. I have no idea why it took me so long to find the answers to doing this (this has been on the wish list for awhile). I suspect I had some luck somewhere along the line this morning with some fortuitous googling finding me the right answers :).

2008-11-25

Microsoft SQL linked servers - a couple of gotcha's

These are very easy to set so that one instance of SQL server can access another however there were a couple of traps that caught me out:

1) You need to set up a ODBC connection for the server (for my simplicity I have used the name for the server as the data source name)

2) You need to do both a linked server stored procedure and a linked server login

3) You need to use a fully 4 part qualified name to get a result e.g. select count(*) from tiger1...all  will fail whereas select count(*) from tiger1.funds.dbo.all will work.

Here is my test code for setting them up - the sql server name is tiger1.  I haven't shown the ODBC setup.

EXEC master.dbo.sp_droplinkedsrvlogin @rmtsrvname=N'tiger1',@locallogin=NULL
EXEC sp_dropserver   @server='tiger1'
EXEC sp_addlinkedserver  
   @server='tiger1',
   @srvproduct='',
   @provider='SQLNCLI',
   @datasrc='tiger1',
   @catalog='Funds'

EXEC master.dbo.sp_addlinkedsrvlogin
    @rmtsrvname=N'tiger1',
    @useself=N'False',
    @locallogin=NULL,
    @rmtuser=N'sa',
    @rmtpassword=''
exec sp_linkedservers

select count(*) from all
select count(*) from arundel01.Funds.dbo.all

2008-07-08

Service is now reliable

(2008-07-17) The service is now running well.  The code crashes or timesout every few days but the error handling below handles the exception and it just keeps on going. My Windows service is still not reliable.  After a few days it seems to just stop in a normal fashion.  I suppose the only thing to do is to keep monitoring.  It currently looks like this (today I have added an error message to exception handling and moved the sleep to be inside the exception handler):

#
# This is the file to run as a daemon.

LOG_FILE = 'C:\\daemon_error.log'

begin
  require 'win32/daemon'
  require 'process_files'

  include Win32

  class DemoDaemon < Daemon
    def service_main
      File.open(LOG_FILE, "a"){ |f| f.puts "Service 2008-07-07 is running #{Time.now}" }
      s = ProcessFiles.new()
      while running?
        begin
         s.getAndProcessOnce
         sleep 10

        rescue Exception => ex
           File.open(LOG_FILE, "a"){ |f| f.puts "Service had an exception #{Time.now} #{ex.class}:#{ex.message}" } 
        end
        #File.open(LOG_FILE, "a"){ |f| f.puts "Service is running #{Time.now}" }
      end
    end

    def service_stop
      File.open(LOG_FILE, "a"){ |f| f.puts "***Service responded to stop and stopped #{Time.now}" }
      exit!
    end
  end

  DemoDaemon.mainloop

rescue Exception => err
  File.open(LOG_FILE,'a+'){ |f| f.puts "***Service Failed #{Time.now} due to #{err.class}:#{err.message}" }
end

I will just have to wait and see if this works more reliably. I have waited and it is looking good! I have some plans to put in a drb client and then allow me to have a local ruby shoes interface to see how it is working.

2008-07-02

Scripting Mathematica

Update 2008-07-02
i have been trying to script a mathematica notebook that I have created that creates documents.  I found it not as straightforward as it seems.
 
I started with at test notebook:
image
My method of getting this scriptable was to save as a .m file.
Then edit it with notepad by removing some of the comments (* to this:

(* ::Package:: *)

(* ::Input:: *)
(*This is a comment.*)

(* ::Input:: *)
(*a = {1,2,3}*)

(* ::Input:: *)
Export[NotebookDirectory[] <> "test.gif",Plot[Sin[x],{x,0,10}]]

(* ::Input:: *)
Exit[]
(**)

Then run it from a batch file like this:

F:
CD "\2008\Mathematica Auto"
"C:\Program Files\Wolfram Research\Mathematica\6.0\math"  <"F:\2008\Mathematica Auto\test.m"

When I ran this didn't work as I couldn't use NotebookDirectory so I had to make the directory explicit:

(* ::Package:: *)

(* ::Input:: *)
(*This is a comment.*)

(* ::Input:: *)
(*a = {1,2,3}*)

(* ::Input:: *)
Export["F:\2008\Mathematica Auto\test.gif",Plot[Sin[x],{x,0,10}]]

(* ::Input:: *)
Exit[]
(**)

And this did run although not very elegant and I don't have a solution for running complex notebooks yet.  When you try and load a notebook Mathematica says it wants a front end.  It may be easier to script this inside Mathematica front end.