Saturday, December 29, 2012

quartz笔记

The main Quartz library is named quartz-all-xxx.jar (where xxx is a version number).
In order to use any of Quartz's features, this jar must be located on your application's classpath.
Quartz depends on a number of third-party libraries (in the form of jars) which are included in the distribution .zip file in the
'lib' directory. To use all the features of Quartz, all of these jars must also exist on your classpath.
Quartz uses a properties file called (kudos on the originality) quartz.properties. This isn't necessary at first, but to use anything but
the most basic configuration it must be located on your classpath.

org.quartz.threadPool.threadCount
Can be any positive integer, although you should realize that only numbers between 1 and 100 are very practical. This is the number of
threads that are available for concurrent execution of jobs. If you only have a few jobs that fire a few times a day, then 1 thread is
plenty! If you have tens of thousands of jobs, with many firing every minute, then you probably want a thread count more like 50 or 100
(this highly depends on the nature of the work that your jobs perform, and your systems resources!).

Sample configuration of Logging Trigger History Plugin
The logging trigger history plugin catches trigger events (it is also a trigger listener) and logs then with Jakarta Commons-Logging.
See the class's JavaDoc for a list of all the possible parameters.
Sample configuration of Logging Trigger History Plugin
org.quartz.plugin.triggHistory.class = \
 org.quartz.plugins.history.LoggingTriggerHistoryPlugin
org.quartz.plugin.triggHistory.triggerFiredMessage = \
 Trigger \{1\}.\{0\} fired job \{6\}.\{5\} at: \{4, date, HH:mm:ss MM/dd/yyyy}
org.quartz.plugin.triggHistory.triggerCompleteMessage = \
 Trigger \{1\}.\{0\} completed firing job \{6\}.\{5\} at \{4, date, HH:mm:ss MM/dd/yyyy\}.

http://www.quartz-scheduler.org/docs/configuration/ConfigRAMJobStore.html
RAMJobStore is used to store scheduling information (job, triggers and calendars) within memory. RAMJobStore is fast and lightweight,
but all scheduling information is lost when the process terminates.

SimpleTrigger is handy if you need 'one-shot' execution (just single execution of a job at a given moment in time), or if you need to fire a job at
a given time, and have it repeat N times, with a delay of T between executions. CronTrigger is useful if you wish to have triggering based on calendar-like
schedules - such as "every Friday, at noon" or "at 10:15 on the 10th day of every month."

The name of a job or trigger must be unique within its group - or in other words, the true identifier of a job or trigger is its name + group.
If you leave the group of the Job or Trigger 'null', it is equivalent to having specified Scheduler.DEFAULT_GROUP.

If N Triggers are to fire at the same time, but there are only Z worker threads currently available, then the first Z Triggers with
the highest priority will get first dibs.

C#和VC++相互调用

All my technical notes will be written in English.
 It's possible to invoke VC++ DLL in C# by using System.Runtime.InteropServices.However,
it's tedious and error prone when the structs with pointer are
involved and things become even more complicated if some struct
contains other structs. You have to care about StructLayout and
Marshal.Actually, it may be more tedious than invoking DLL in
Java.

One grace
solution is to simplify the invoked method in VC++ side by
introducing managed code in VC++. It's better than introducing
unmanaged code in C# side. One simple example,

//
ManagedTest.cpp : main project file.


#include
"stdafx.h"

using
namespace System;

using
namespace System::Collections::Generic;


List<String^>^
MTest();


void main()
{


double number [] = { 79.31, 47.59, 749.75, 9.07, 9.44 };
Console::WriteLine(L"Value 1:  {0}", number[0]);

List<String^>^ list = MTest();
for(int i=0;i<list->Count;i++){
Console::WriteLine(list[i]);
}

Console::ReadLine();
}

List<String^>^
MTest(){

char tmp[] = "American College of Computer & Information Sciences";
String^ School = gcnew String(tmp);
String^ School2 = "American College of Computer & Information Sciences2";
List<String^>^ list = gcnew List<String^>();
list->Add(School);
list->Add(School2);
return list;
}



The problem for C# is that it has dependency on .NET framework and
a little lower than the native C++ program. Although ngen.exe could
be used to compiles an assembly to native code it still inevitable
to depend on .NET framework and ngen.exe only helps to reduce the
startup time.


When VC++ is using managed functions and aiming to try to export to the managed DLLs, it should be a CLR project as the great article "Walkthrough: Creating and Using a Managed Assembly (C++)" shows.
When C# side invokes the DLL, just add it to the reference and using the namespace to call the functions as if they are c# functions.
And the managed DLL cannot be displayed by dumpbin -exports
http://msdn.microsoft.com/zh-cn/library/ms235638(v=VS.100).aspx

outlook邮件自动转发到Gmail

Private Sub Application_NewMail()
 Dim myItem As Outlook.MailItem
 Set myItem = Application.ActiveExplorer.Selection.Item(1).Forward
 myItem.Recipients.Add "xxxxxxg@gmail.com"
 myItem.Send
 Set myItem = Nothing
End Sub

上面这个的问题是转发选中的邮件而不是新接受的
更新之后的版本:
Public WithEvents myOlItems As Outlook.Items
Public Sub Application_Startup()
' Reference the items in the Inbox. Because myOlItems is declared ' "WithEvents" the ItemAdd event will fire below.
Set myOlItems = Outlook.Session.GetDefaultFolder(olFolderInbox).Items
End Sub
Private Sub myOlItems_ItemAdd(ByVal Item As Object)
If TypeName(Item) = "MailItem" Then
    Set myForward = Item.Forward
    myForward.Recipients.Add "xxxx@gmail.com"
    myForward.Send
End If
End Sub

algorithm introduction

http://mitpress.mit.edu/algorithms/, links to solutions for
a few of the problems and exercises.
Based on many requests, we changed the syntax (as it were) of our pseudocode.
We now use “D” to indicate assignment and “==” to test for equality, just as C,
C++, Java, and Python do. Likewise, we have eliminated the keywords do and
then and adopted “//” as our comment-to-end-of-line symbol. We also now use
dot-notation to indicate object attributes. Our pseudocode remains procedural,
rather than object-oriented. In other words, rather than running methods on
objects, we simply call procedures, passing objects as parameters.
Informally, an algorithm is any well-defined computational procedure that takes
some value, or set of values, as input and produces some value, or set of values, as
output. An algorithm is thus a sequence of computational steps that transform the
input into the output.
The algorithm describes a specific computational procedure
for achieving that input/output relationship.
An algorithm is said to be correct if, for every input instance, it halts with the
correct output.
A data structure is a way to store
and organize data in order to facilitate access and modifications.
The running time of an algorithm on a particular input is the number of primitive
operations or “steps” executed.
When a for or while loop
exits in the usual way (i.e., due to the test in the loop header), the test is executed
one time more than the loop body. We assume that comments are not executable
statements, and so they take no time.
For the remainder of this book, though, we shall usually concentrate on
finding only the worst-case running time, that is, the longest running time for any
input of size n.
We usually consider one algorithm to be more efficient than another if its worstcase
running time has a lower order of growth.
2.3 Designing algorithms

notepad++

notepadd++
1. 在每一行末尾添加一个逗号(参考http://antswallow.blog.sohu.com/40838734.html)
Find what: 
Replace with: \1,
而不像ultraedit用^p


multiline to one line
Find: .\n
Replace: ,
30
60
to
30,60

VC++ DLL

VC++->Win32->Win32 Console Application->DLL Empty project

Unix Shells by Example

The wait System Call. The parent shell is programmed to go to sleep (wait) while the child takes care of
details such as handling redirection, pipes, and background processing. The wait system call causes the parent
process to suspend until one of its children terminates. If wait is successful, it returns the PID of the child that
died and the child's exit status. If the parent does not wait and the child exits, the child is put in a zombie state
(suspended animation) and will stay in that state until either the parent calls wait or the parent dies.[3] If the
parent dies before the child, the init process adopts any orphaned zombie process. The wait system call, then,
is not just used to put a parent to sleep, but also to ensure that the process terminates properly.

The exit System Call. A new program can terminate at any time by executing the exit call. When a child
process terminates, it sends a signal (sigchild) and waits for the parent to accept its exit status. The exit status
is a number between 0 and 255. An exit status of zero indicates that the program executed successfully, and a
nonzero exit status means that the program failed in some way.

Initially, the umask is 000, giving a directory 777 (rwxrwxrwx) permissions and a file 666 (rw–rw–rw–)
permissions as the default. On most systems, the umask is assigned a value of 022 by the /bin/login program
or the /etc/profile initialization file.
The umask value is subtracted from the default settings for both the directory and file permissions as follows:
777 (Directory) 666 (File)
–022 (umask value) –022 (umask value)
−−−−−−− −−−−−−−−−
755 644
Result: drwxr−xr−x −rw−r−−r−−

find / −name file −print 2> errors
Any errors from the find command are redirected to errors. Output goes to the terminal.
(The Bourne and Korn shells redirect errors this way.)