any ideas about how to program an automated signed contract - java

I have a small company and I want all the work to be professional, I was thinking if there is a way to scan the contract (signed) and I fill the name of the customer, phone number, address and day's date in some interface then I print the contract signed with all info I entered (every info has specific location in the contract).
is this possible? what would be the best way to do it.
p.s. I'm a beginner java programmer

Well if you are a beginner java programmer I would avoid scanning an image at all costs, it in and of itself isn't too hard however what you want to do with it is; you would need to branch off first. I would suggest searching for things like IO in java and how to create an Image in java, before considering this large feat.If you feel as though you are ready here is some code which could get you on your way:
try {
Robot robo = new Robot();
}catch(Exception e){}
//Do what you would like to prepare the contract
BufferedImage contract;
contract = robo.getScreenCapture(new Rectangle(screenWidth, screenHeight));
ImageIO.write(contract, "format e.g. png", FilePathandName);
I respect your curiosity and goals though ;)

Related

Interpreting iOS code to get Bluetooth Low Energy data on Android

I was sent iOS C code to get data from a Bluetooth Low Energy scale and I need to find out how to create similar functions into Android Java code.
The scale I am working with aren't using typical UUIDs and formatting.
I already have a scanner set up with the ability to write and listen to notifications.
What I need to do is figure out how to get the weight data.
I know is that 0XFFF0 is the service UUID, 0XFFF1 is the write characteristic and 0XFFF4 is the notify characteristic.
I'm guessing it writes something, then the scale gives you the data. But I'm not sure what.
Plus I think the scale sends the data with NSUTF8StringEncoding if I'm reading it correctly. How would I implement this on Java?
Here is the code sent to me:
http://www.anj.fyi/BTManagerlib.m (I tried to post the code here, but it's registering as spam for some odd reason)
I really appreciate the help guys.
Many thanks.
"The scale I am working with aren't using typical UUIDs and formatting."
Yes, it uses, except it is written in 16-bit format If you want 128-bit UUID use XXXXYYYY-0000-1000-8000-00805F9B34FB base to create it.
From the example that you have posted:
-(void)writeDataToBlue:(NSNotification *)note
{
id obj = [note object];
_senddata = obj;
[self sendBlueToothData:_senddata showAlert:YES];
}
it is clear that data to be written to the device are not bundled into the source code, but they are received via notification center, from some other class. Ask them for device documentation or full source code, otherwise you won't be able to make any conclusions.

How to read the text at image box during creating new google account with WebDriver using java

How to read the text in image box while creating new google account using WebDriver in java. I am creating a new gmail account using WebDriver in java. I am NOT able to read the text present in Image box. Can anybody help me on this issue?
The Code I have used for that is:
driver = new InternetExplorerDriver();
driver.get("http://gmail.com");
Thread.sleep(10000);
driver.findElement(By.id("link-signup")).click();
Thread.sleep(10000);
driver.findElement(By.id("FirstName")).sendKeys("Swamy");
driver.findElement(By.id("LastName")).sendKeys("Kumar");
driver.findElement(By.id("GmailAddress")).sendKeys("Skumar081112");
driver.findElement(By.id("Passwd")).sendKeys("Swamy#123");
driver.findElement(By.id("PasswdAgain")).sendKeys("Swamy#123");
driver.findElement(By.xpath("//label[#id='month-label']/span/div
/div")).sendKeys("November");
driver.findElement(By.id("BirthDay")).sendKeys("16");
driver.findElement(By.id("BirthYear")).sendKeys("1978");
driver.findElement(By.xpath("//div[#id='Gender']/div/div")).sendKeys("Male");
driver.findElement(By.id("RecoveryPhoneNumber")).sendKeys("9000000000");
driver.findElement(By.id("RecoveryEmailAddress")).sendKeys("abc#gmail.com");
driver.findElement(By.id("HomepageSet")).click();
String imgmsg = driver.findElements(By.xpath("//div[#id='recaptcha_image']
/img")).toString();
System.out.println(imgmsg);
Help will be appreciated...
You can't
That text is called a CAPTCHA it is designed to stop automated systems from creating accounts (and is obviously doing a pretty good job).
A CAPTCHA (pron.: /ˈkæp.tʃə/) is a type of challenge-response test
used in computing as an attempt to ensure that the response is
generated by a human being. The process usually involves a computer
asking a user to complete a simple test which the computer is able to
grade. These tests are designed to be easy for a computer to generate
but difficult for a computer to solve, but again easy for a human. If
a correct solution is received, it can be presumed to have been
entered by a human. A common type of CAPTCHA requires the user to type
letters and/or digits from a distorted image that appears on the
screen. Such tests are commonly used to prevent unwanted internet bots
from accessing websites, since a normal human can easily read a
CAPTCHA, while the bot cannot process the image letters and therefore,
cannot answer properly, or at all. Although most CAPTCHAs are letter
pictures randomly generated, many of them have become difficult even
for a human to read , so picture CAPTCHAs were created in which a
human is shown a simple test to show a picture of a certain animal
(given few animal pictures), which is simple for a human being to
process, and therefore easy to pick, while a bot cannot process and
solve the question because although it can analyze the picture, it
cannot easily guess the animal. The term "CAPTCHA" was coined in 2000
by Luis von Ahn, Manuel Blum, Nicholas J. Hopper, and John Langford
(all of Carnegie Mellon University). It is an acronym based on the
word "capture" and standing for "Completely Automated Public Turing
test to tell Computers and Humans Apart". Carnegie Mellon University
attempted to trademark the term on 15 October 2004,1 but the
trademark application was abandoned on 21 April 2008.[2] A CAPTCHA is
sometimes described as a reverse Turing test, because it is
administered by a machine and targeted at a human, in contrast to the
standard Turing test that is typically administered by a human and
targeted at a machine.

What is the best way to create a Unique number for the user that will be constant over multiple restarts

I am building an application(in java) and I would like to provide myself with some mesure of its performance. There are multiple long running processes that I am timing, and I have a web server that I will use to receive the metrics, however I would like to create a number that is unique for a particular user(my program doesn't need to be logged in) on a computer.
So if Joe logged on to computer A and ran my application, It would give him a unique number like 1234. Then if Jane logged on to the same computer it would use a different number, such as 4321. However if Joe logged on to computer B, it would create a separate number entirely, say 5678. Also (just to clarify) If Joe logged back on to computer A, it would still produce the number 1234.
Also, just to make it more challenging, If the same computer was on a different network, then I would preferably want a different ID.
These numbers are arbitrary, and will be longer than this. My code so far generates 8akb7d3n7lp1i1jo6apfhegp593kja5hg38b6o1a5godm38g97omm7bmc3jekc6apopgjhf9g as my UID from:
try {
byte[] mac = NetworkInterface.getByInetAddress(InetAddress.getLocalHost()).getHardwareAddress();
String names = new BigInteger(mac).toString(16) + InetAddress.getLocalHost().getHostAddress() + get("user.name") + get("os.version") + get("java.vendor");
BigInteger uid = new BigInteger(names.getBytes());
thisUsersUid = uid.toString(26);
} catch (SocketException ex) {
Logger.getLogger(TimingLogger.class.getName()).log(Level.SEVERE, null, ex);
} catch (UnknownHostException ex) {
Logger.getLogger(TimingLogger.class.getName()).log(Level.SEVERE, null, ex);
}
I don't want this information to easily read(as you might figure out names="-f4b86eb8ee1192.168.0.20lee10.6.8Apple Inc.") so I will be adding a hash function to that.
So my question, after all this blurb is: Is this a good way of doing it? Is there a library out there that can do a better job than this? Or am I just wanting too much?
Thanks in advance(even for those comments that say: WHY?)
You could use UUIDs.
In Java: UUID id = UUID.randomUUID();
Your question is not entirely clear, so I'm going to state some assumptions.
Your application is installed on the user's PC. (It is not an applet or similar that has access limited by sandboxing.)
The UID is generated by the application running on the user's computer, not the server.
You don't need to be able to recover the user's name and machine identity from the UID; i.e. it is just an opaque identifier.
Your solution doesn't need to be secure. (If the user decides to mess around and generate different UIDs on the same machine, that doesn't really matter.)
If so, here are a couple of options.
First time you run the application, generate a random UUID and store it in the user's home directory or preferences or something. Subsequent times, look for an existing UUID in the place where it would have been stored by your application.
Generate a UID as a MD5 (or similar) hash of the user's account name and the machine's MAC address. This should be stable over restarts ... unless there is something weird about the way the user's PC is implemented.
(If security is a primary concern then the first approach is not on - you have to assume that the user can find and remove the saved UUID. In the second you have the problem that the user can possibly spoof his account name and/or change the PC's MAC address. For ANY scheme, you have a bigger problem in that ANY SOFTWARE that is installed or run on a user's PC could be hacked to replace the UID with something that the user wants. In short, you're fighting a losing battle if your users have hacker skills and motivation.)
Is there a library out there that can do a better job than this? Or am I just wanting too much?
I'm not aware of an existing library that will do this.
This is a fine application for a good cryptographic hash function. The state-of-the-art is SHA-2. As you have done, concatenate all the independent quantities to build a string in some repeatable manner and run this through the hash to get a 256 bit (32 byte) value.
Your choice to include OS and Java vendor seems curious as this means routine upgrades or changes could produce a new ID. MAC, IP, and user name seem the best combination to me based on the criteria you gave.

Recognizing colors/patterns in webpage

I want to try to create a learning chess application as a school project. My first plan was to simply pit this AI against itself, but to really show if it has been succesful it needs to be able to show how well it progresses. In order to do this, i want it to play rated games on sites such as chess.com. However, they do not (yet) have a public API, i believe.
Therefore, i wanted to make a program in java that recognizes colors and images. It keeps an internal 2-dimensional array of all the positions, and recognizes the pieces on the board. I think i have found a way to do this in a window using something like the Java Robot Class.
What i would like it to do, however, is to open this webpage in an internal window and keep doing this in the background. Is there a way to recognize colors within the own window, without needing to be in the foreground?
Edit: I'm planning on using this browser component i just found. I noticed that it is possible to create a full-page snapshot of the page and save it as a BufferedImage(?). Would this make it easier to do this?
Edit 2: I just read that 'Outside assistance from other people, computers/chess engines, or endgame tablebases is entirely prohibited'. I suppose letting a computer do all the playing does certainly include in that. So i might try using another site, so answers that are specific for chess.com won't cut it!
I don't know it it helps but may be you can have a look at the Sikuli project.
http://sikuli.org/
Sikuli is a program (and an API) to handle the interactions with the User Interface. For instance, you can write a script to click on an image or a button in certain conditions.
Especially interesting for you, there is a Java integration: http://sikuli.org/docx/faq/030-java-dev.html
Here is an extract of the website to give you an idea of the code you can write.
EDIT: in this code it is important to notice that you are defining new Patterns with the images. Sikuli will be able to find matching patterns.
import org.sikuli.script.*;
public class TestSikuli {
public static void main(String[] args) {
Screen s = new Screen();
try{
s.click("imgs/spotlight.png", 0);
s.wait("imgs/spotlight-input.png");
s.type(null, "hello world\n", 0);
}
catch(FindFailed e){
e.printStackTrace();
}
}
}
You should consider playing on a chess server where an API is avaible and chess engines are allowed. There is The Internet Chess Club (ICC) where you must pay to have a human account and then you can get a free computer account for your engine. There is also the Free Internet Chess Server (FICS) where you and your engine can get free accounts.
The ICC is usually prefered because the level of players is higher there with lots of international masters and chess masters playing there.
The best way to Interface with theses sites is to implement the xboard protocol. This will allow your engines to play through the Winboard or XBoard interface (among others) and theses interface can be used to connect on FICS or ICC and automatically play there.
I hope this help, even if it does not directly answer the question.
I'm not sure what your input is but you have two options:
You can work an a PNG image. Load the image into a BufferedImage (docs) object and examine it there. You can use a screen shot tool to create those.
It seems chess.com uses HTML with JavaScript. You can download the HTML using HttpComponents and examine it to see where the pieces are. This has the additional benefit that you don't have to guess which piece goes where since the HTML contains the source information.

Using a utility to generate Java code to make my project more concise. Good idea?

The project I'm working on requires me to write lots of repetitive code. For example, if I want to load a image file called "logo.png" in my code, I would write something like this:
Bitmap logoImage;
...
// Init
logoImage = load("logo.png")
...
// Usage
logoImage.draw(0, 0);
..
// Cleanup
logoImage.release();
Having to write this code to use every new image is a pain, including having to specify that logoImage should load the file "logo.png".
As I'm working on a Java Android game and images are used a lot in inner loops, I really want to avoid slow things like making virtual function calls and e.g. accessing arrays/maps/object fields when I can avoid it. Copying an idea from the Android API (the generated R class), I thought I could run a utility before compiling to generate some of this repetitive code for me. For example, the actual code in the project file would be reduced to just this:
logoImage.draw(0, 0);
Using some command-line tools (e.g. grep, sed), I can look for every instance of "Image.draw(..." and then generate the other required code automatically i.e. code to load/release the file .png and declare "Bitmap logoImage" somewhere. This code could either be added to a new class or I could add placeholders in my code that told the code generator where to insert the generated code.
To display a new image, all I would need to do is just copy the image file to the right directory and add one line of code. Nice and simple. This avoid approaches like creating an array of images, defining labelled int constants to references the array and having to specify which filename to load.
Is this a really bad idea? It seems a bit of a hack but I can see no easier way of doing this and it does seem to drastically clean up my code. Are there any standard tools for doing this simple kind of code generation (i.e. the tool doesn't need to understand the meaning of the code)? Does anyone else do things like this to make up for language features?
It would be a bad idea to use code generation for something like this. (IMO, code generation should be reserved for situations where you need to generate vast amounts of code, and this doesn't sound like that situation.)
If the boilerplate code in your current solution concerns you, a better solution (than code generation) is to implement an image registry abstraction; e.g.
public class ImageRegistry {
private Map<String, Image> map = new HashMap<String, Image>();
public synchronized Image getImage(String filename) {
Image image = map.get(filename);
if (image == null) {
image = load(filename);
map.put(filename, image);
}
return image;
}
public synchronized void shutdown() {
for (Image image : map.valueSet()) {
image.release();
}
map.clear(); // probably redundant ...
}
}
Replace logoImage.draw(0, 0) and the like with:
registry.getImage("logo.png").draw(0, 0);
remove all of the load calls, and replace all of the release calls with a single call to registry.shutdown().
EDIT in response to the OP's comments below:
... but I mention that I'm writing a game for a phone. A HashMap lookup every time I'm drawing a sprite will kill performance.
Ah ... I remember you from another thread.
You are (yet again) making assumptions about performance without any basis in actual performance measurements. Specifically, you are assuming that HashMap lookup is going to be too expensive. My gut feeling is that the time taken to do the lookup will be a small percentage ( < 10% ) of the time taken to draw the image. At that point, it is approaching the level at which it is unnoticable to users.
If your measurements (or gut feeling) tells you that a hashmap lookup is too expensive, it is a trivial modification to write this:
Image image = registry.getImage("logo.png");
while (...) {
...
image.draw(0, 0);
}
For example, Google even go as far as to recommend you don't use iterators in inner loops because these cause the GC to fire when the Iterator objects are deallocated.
That is irrelevant and inaccurate.
A HashMap lookup using a String key does not generate garbage. Not ever.
Using an iterator in an inner loop does not "cause the GC to fire when the Iterator objects are deallocated". In Java, you don't deallocate objects. That is C/C++ thinking.
Instantiating an iterator in an inner loop does new an object, but the GC will only fire if the new operation hits the memory threshold. This happens only occasionally.
Also, writing "file_that_does_not_exist.png" will not be picked up as a compile time error with your example.
Neither your original solution, or the code generation approach can give you a compile time error for a missing file either.
Avoid code-generation. It often makes code hard to maintain.
In your case why don't you just make:
public class ImageUtils {
public static void drawAndRelease(String name) {
logoImage = load(name)
logoImage.draw(0, 0);
logoImage.release();
}
}
and then just call:
ImageUtils.drawAndRelease("logo.png");
If there is more code between these methods - well, then they are atomic methods and you won't know where to put them in case you use code-generation.
I second Bozho's answer about avoiding code generation, but if you have to write repeatable snippets of code, any good IDE usually has some built in support for specifying your own snippets with variables and everything. IntelliJ IDEA has this feature, it's called Live Templates. I would guess both Eclipse and NetBeans has similar functionality.
You transfer complexity to code generation, and it (generation) is not trivial and may be buggy.
Code is harder to read and maintain. Some clear rules to design and coding are more helpful here.
Several ways:
Eclipse code2code, you cod in template using template language such as FreeMarker, groovy, etc
eclipse sqLite plugin for Android autogenerates sqlite code
MotoDevStudio4android has code snippets which yo could use

Categories

Resources