# Ruby Version 1.9.2-p180
def reverseTest(inputtext)
@a=""
regextext = /[!,.;"()<>\[\]{}]/
arr = inputtext.split(/\s/)
arr.reverse_each { |item|
len = @a.length
# Dealing with a word surrounding by one or multiple punctuation
if item.partition(regextext).at(1)!=''
# Partition the word by particular punctuation, until partition by the last punctuation
begin
@a .insert(len,item.partition(regextext).at(0))
@a .insert(len,item.partition(regextext).at(1))
item = item.partition(regextext).at(2)
end while item.partition(regextext).at(1)!='' && item.partition(regextext).at(2)!=''
# When punctuation is at the end coming after a word
@a .insert(len,item.partition(regextext).at(0))
@a .insert(len,item.partition(regextext).at(1))
@a << ' '
# Dealing with a word without surrounding any punctuation
else
@a << item
@a << ' '
end
}
#Remove space at the end of the string and swap symmetry punctuation
@a.strip!
@a.gsub!(/[()<>\[\]{}]/, '('=>')', ')'=>'(', '<'=>'>', '>'=>'<', '['=>']',']'=>'[', '{'=>'}', '}'=>'{')
print @a
end
Sunday, March 13, 2011
Reverse*a*Sentence*With*Ruby code
For example , if you want "One, Two, Three, Four." to be converted into “.Four ,Three ,Two ,One”, take a look at my ruby version for your reference, hope it helps in some degree :) I know you may never need this function, but some people may let you write such kind of things...
Thursday, March 03, 2011
Using JNative to load AutoITX.dll
I am working on JNative to load AutoITX.dll, and get my complex UI methods work for WebDriver.
First download JNative.jar from website then add JNative.jar to your build path.
Download your AutoITX from http://www.autoitscript.com/site/autoit/downloads/
2 useful docs which you can refer to:
Function reference
http://www.autoitscript.com/autoit3/docs/functions.htm
and AutoITX Help doc -> DLL interface introduction(Find it after installing AutoITV3)
Then start to create your own method based on AutoITX great Functions which in AutoITX.dll
Here is a sample code to create mouse move methods in Java
I will work on more functions and hope they may help my WebDriver automation tests soon :) Enjoy!
Update: The source code has been uploaded to my github, check it out if you like : https://github.com/joychester/AutoIT-in-Java
First download JNative.jar from website then add JNative.jar to your build path.
Download your AutoITX from http://www.autoitscript.com/site/autoit/downloads/
2 useful docs which you can refer to:
Function reference
http://www.autoitscript.com/autoit3/docs/functions.htm
and AutoITX Help doc -> DLL interface introduction(Find it after installing AutoITV3)
Then start to create your own method based on AutoITX great Functions which in AutoITX.dll
Here is a sample code to create mouse move methods in Java
package org;
import org.xvolks.jnative.JNative;
import org.xvolks.jnative.exceptions.NativeException;
public class LoadDllSample {
public static void main(String[] args) throws IllegalAccessException {
// TODO Auto-generated method stub
try {
GetMyMouseMove(100, 100 ,40);
} catch (NativeException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/*
* AutoItX Interface For AU3_MouseMove() Function
AU3_API long WINAPI AU3_MouseMove(long nX, long nY, long nSpeed);
*/
public static void GetMyMouseMove(int x, int y, int s) throws NativeException, IllegalAccessException{
JNative nGetMyMouseMove = new JNative("C:\\Program Files\\AutoIt3\\AutoItX\\AutoItX3.dll", "AU3_MouseMove"); //load .dll file and specific func
nGetMyMouseMove.setParameter(0,x);//The screen x coordinate to move the mouse to.
nGetMyMouseMove.setParameter(1,y);//The screen y coordinate to move the mouse to.
nGetMyMouseMove.setParameter(2,s);//The speed s to move the mouse (optional)
nGetMyMouseMove.invoke();
return;
}
}
I will work on more functions and hope they may help my WebDriver automation tests soon :) Enjoy!
Update: The source code has been uploaded to my github, check it out if you like : https://github.com/joychester/AutoIT-in-Java
Tuesday, March 01, 2011
Profiling OSGi project with Btrace
I met "java.lang.NoClassDefFoundError" when i did profiling with my OSGi project:
So two things need to be modified from my side:
1. add package to btrace code , for example "package com.sun.btrace.samples;"
2. add OSGI config.properties in felix/conf/ to include org.osgi.framework.bootdelegation=com.sun.btrace,com.sun.btrace.*
Then start your application, enjoy profiling with Btrace:)
Thanks for @yardus great help and also good post from this: http://blogs.sun.com/binublog/entry/glassfish_v3_profiling
Error com.myapp.template.TemplateServlet - TemplateServlet.doGet() exception
java.lang.NoClassDefFoundError: CodeLineTiming at com.myapp.service.proxy.abc.impl.ServiceProxyImpl.$btrace$CodeLineTiming$onCall(ServiceProxyImpl.java) at com.myapp.service.proxy.abc.impl.ServiceProxyImpl.getRfpWithChangeLog(ServiceProxyImpl.java:467) at
...
So two things need to be modified from my side:
1. add package to btrace code , for example "package com.sun.btrace.samples;"
package com.sun.btrace.samples;
import com.sun.btrace.annotations.*;
import static com.sun.btrace.BTraceUtils.*;
import com.sun.btrace.aggregation.*;
@BTrace
public class MethodResponseTime {
...
}
2. add OSGI config.properties in felix/conf/ to include org.osgi.framework.bootdelegation=com.sun.btrace,com.sun.btrace.*
Then start your application, enjoy profiling with Btrace:)
Thanks for @yardus great help and also good post from this: http://blogs.sun.com/binublog/entry/glassfish_v3_profiling
Subscribe to:
Posts (Atom)