make bar chat with different color using AChartEngine
I want to use AChartEngine to make a bar chat. Now I meet a problem, can
you help me? The problem is how to show different color in a bar chart
according to the value of X-axis. If the value of x-axis is larger than
50, the color of the bar is green. Otherwise the color is blue.
Bruyn
Sunday, 1 September 2013
View network activity for browser child window
View network activity for browser child window
I need to reverse-engineer some javascript application which does
authorization using facebook auth.
Facebook auth window pops up, asks for my permissions, and gets closed
instantly, so I am unable to grasp anything from the performed action, as
it's too fast.
The problem is that neither Chrome DevTools, nor Firefox Firebug does
display network activity for child windows like OAuth permission.
Is there a way to enable FULL network log? An extension, whatever? (It
better be free and easy to use)
I need to reverse-engineer some javascript application which does
authorization using facebook auth.
Facebook auth window pops up, asks for my permissions, and gets closed
instantly, so I am unable to grasp anything from the performed action, as
it's too fast.
The problem is that neither Chrome DevTools, nor Firefox Firebug does
display network activity for child windows like OAuth permission.
Is there a way to enable FULL network log? An extension, whatever? (It
better be free and easy to use)
Can't normalize array. Sum is NaN. Weka
Can't normalize array. Sum is NaN. Weka
I got an error "Can't normalize array. Sum is NaN." when I use the trained
model to classify text. I am using stringToWordVector filter.
This is my arff file after I filter using the stringToWordVector
@relation
'emotion_class-weka.filters.unsupervised.attribute.StringToWordVector-R1-W1000-prune-rate-1.0-N0-stemmerweka.core.stemmers.NullStemmer-M1-tokenizerweka.core.tokenizers.WordTokenizer
-delimiters \" \\r\\n\\t.,;:\\\'\\\"()?!\"'\n\n
@attribute class_list {Happy,Fear,Anger,Sad,Neutral}
@attribute #Bopha numeric
@attribute #PlanPhilippines numeric
@attribute Mindanao numeric
@attribute interviewing numeric
@attribute survivors numeric
@attribute team numeric
@data
{0 ?,1 1,2 1,3 1,4 1,5 1,6 1}
this my code:
//Reads arff file
StringBuilder buffer = new StringBuilder(sample);
BufferedReader reader = new BufferedReader(new
java.io.StringReader(buffer.ToString()));
weka.core.converters.ArffLoader.ArffReader arff = new
weka.core.converters.ArffLoader.ArffReader(reader);
Instances dataRaw = arff.getData();
//Use string to word vector
StringToWordVector filter = new StringToWordVector();
filter.setInputFormat(dataRaw);
Instances dataFiltered = Filter.useFilter(dataRaw, filter);
dataRaw.setClassIndex(dataRaw.numAttributes() - 1);
Instances labeled = new Instances(dataFiltered);
Classifier cls = null;
cls =
(Classifier)weka.core.SerializationHelper.read("SampleModel.model");
for (int i = 0; i < dataFiltered.numInstances(); i++)
{
double clsLabel = cls.classifyInstance(dataFiltered.instance(i));
labeled.instance(i).setClassValue(clsLabel);
MessageBox.Show(clsLabel.ToString());
}
The error is in double clsLabel =
cls.classifyInstance(dataFiltered.instance(i));
Do you have other solution? Thanks in advance
I got an error "Can't normalize array. Sum is NaN." when I use the trained
model to classify text. I am using stringToWordVector filter.
This is my arff file after I filter using the stringToWordVector
@relation
'emotion_class-weka.filters.unsupervised.attribute.StringToWordVector-R1-W1000-prune-rate-1.0-N0-stemmerweka.core.stemmers.NullStemmer-M1-tokenizerweka.core.tokenizers.WordTokenizer
-delimiters \" \\r\\n\\t.,;:\\\'\\\"()?!\"'\n\n
@attribute class_list {Happy,Fear,Anger,Sad,Neutral}
@attribute #Bopha numeric
@attribute #PlanPhilippines numeric
@attribute Mindanao numeric
@attribute interviewing numeric
@attribute survivors numeric
@attribute team numeric
@data
{0 ?,1 1,2 1,3 1,4 1,5 1,6 1}
this my code:
//Reads arff file
StringBuilder buffer = new StringBuilder(sample);
BufferedReader reader = new BufferedReader(new
java.io.StringReader(buffer.ToString()));
weka.core.converters.ArffLoader.ArffReader arff = new
weka.core.converters.ArffLoader.ArffReader(reader);
Instances dataRaw = arff.getData();
//Use string to word vector
StringToWordVector filter = new StringToWordVector();
filter.setInputFormat(dataRaw);
Instances dataFiltered = Filter.useFilter(dataRaw, filter);
dataRaw.setClassIndex(dataRaw.numAttributes() - 1);
Instances labeled = new Instances(dataFiltered);
Classifier cls = null;
cls =
(Classifier)weka.core.SerializationHelper.read("SampleModel.model");
for (int i = 0; i < dataFiltered.numInstances(); i++)
{
double clsLabel = cls.classifyInstance(dataFiltered.instance(i));
labeled.instance(i).setClassValue(clsLabel);
MessageBox.Show(clsLabel.ToString());
}
The error is in double clsLabel =
cls.classifyInstance(dataFiltered.instance(i));
Do you have other solution? Thanks in advance
Saturday, 31 August 2013
QtCreator GUI open text file
QtCreator GUI open text file
I made a push button that will browse and get a textfile. But I need to
open it in a new window to check if the content of the textfile is
correct. How do I do this?
Also, I would like to have a line edit right next to the button that shows
which file I'm looking at. In other words, the directory of the file that
is opened through the button.
Currently, this is what I have:
void MainWindow::on_fileButton_clicked()
{
QString fileName1 = QFileDialog::getOpenFileName(this,tr("Open Text
File"), "", tr("Text Files (*.txt)"));
QFile file1(fileName1);
if(!file1.open(QIODevice::ReadOnly | QIODevice::Text))
return;
QTextStream in(&file1);
while(!in.atEnd()){
QString line = in.readLine();
}
}
I made a push button that will browse and get a textfile. But I need to
open it in a new window to check if the content of the textfile is
correct. How do I do this?
Also, I would like to have a line edit right next to the button that shows
which file I'm looking at. In other words, the directory of the file that
is opened through the button.
Currently, this is what I have:
void MainWindow::on_fileButton_clicked()
{
QString fileName1 = QFileDialog::getOpenFileName(this,tr("Open Text
File"), "", tr("Text Files (*.txt)"));
QFile file1(fileName1);
if(!file1.open(QIODevice::ReadOnly | QIODevice::Text))
return;
QTextStream in(&file1);
while(!in.atEnd()){
QString line = in.readLine();
}
}
NSOutlineView drag promises with directories
NSOutlineView drag promises with directories
How does one implement an NSOutlineViewDataSource to allow dragging
directories that do not exist in the file system at the time of dragging
to the Finder? I have searched and searched and read a ton of the
documentation, but have had great difficulty finding anything of value
that works. I use a custom data source that manages a file system-like
tree, and all the items are instances of a class that keeps track of its
path. I would like to be able to drag files and directories out of the
outline view into the Finder.
I have:
- (BOOL)outlineView:(NSOutlineView *)outlineView writeItems:(NSArray
*)items toPasteboard:(NSPasteboard *)pasteboard {
NSMutableArray *types = [NSMutableArray array];
for (JOItemInfo *itemInfo in items) {
NSString *extension = itemInfo.name.pathExtension;
if (extension.length > 0) [types addObject:extension];
}
[pasteboard declareTypes:@[(__bridge_transfer NSString
*)kPasteboardTypeFileURLPromise] owner:self];
[pasteboard setPropertyList:types forType:(__bridge_transfer
NSString *)kPasteboardTypeFileURLPromise];
DDLogInfo(@"Wrote types %@ to pasteboard %@ for key %@", types,
pasteboard, (__bridge_transfer NSString
*)kPasteboardTypeFileURLPromise);
return YES;
}
and an implementation of
-outlineView:namesOfPromisedFilesDroppedAtDestination:forDraggedItems:
that writes the items inside of the given path. This works in that I can
drag items out to the Finder, but when I let go nothing else happens, and
the -...namesOfPromisedFilesDropped... method isn't even called. Also,
[self.outlineView
setDraggingDestinationFeedbackStyle:NSTableViewDraggingDestinationFeedbackStyleRegular];
[self.outlineView setDraggingSourceOperationMask:NSDragOperationNone
forLocal:YES];
[self.outlineView setDraggingSourceOperationMask:NSDragOperationCopy
forLocal:NO];
is in my -awakeFromNib. The if (extension.length > 0) ... was based on an
example I found somewhere, but it was dated, and the documentation says to
return an extension, so I think that is appropriate. Personally, I find
the documentation for this whole area very lacking, especially in regard
to an NSOutlineView. Thanks!
Update: I changed (__bridge_transfer NSString
*)kPasteboardTypeFileURLPromise to NSFilesPromisePboardType, and I can now
drag files (with an extension at least) and they can be dropped
successfully in the Finder. (I had used the former b/c the documentation
for the latter recommended that, but they do not have the same effect.)
Directories and files without an extension still can't be dragged.
How does one implement an NSOutlineViewDataSource to allow dragging
directories that do not exist in the file system at the time of dragging
to the Finder? I have searched and searched and read a ton of the
documentation, but have had great difficulty finding anything of value
that works. I use a custom data source that manages a file system-like
tree, and all the items are instances of a class that keeps track of its
path. I would like to be able to drag files and directories out of the
outline view into the Finder.
I have:
- (BOOL)outlineView:(NSOutlineView *)outlineView writeItems:(NSArray
*)items toPasteboard:(NSPasteboard *)pasteboard {
NSMutableArray *types = [NSMutableArray array];
for (JOItemInfo *itemInfo in items) {
NSString *extension = itemInfo.name.pathExtension;
if (extension.length > 0) [types addObject:extension];
}
[pasteboard declareTypes:@[(__bridge_transfer NSString
*)kPasteboardTypeFileURLPromise] owner:self];
[pasteboard setPropertyList:types forType:(__bridge_transfer
NSString *)kPasteboardTypeFileURLPromise];
DDLogInfo(@"Wrote types %@ to pasteboard %@ for key %@", types,
pasteboard, (__bridge_transfer NSString
*)kPasteboardTypeFileURLPromise);
return YES;
}
and an implementation of
-outlineView:namesOfPromisedFilesDroppedAtDestination:forDraggedItems:
that writes the items inside of the given path. This works in that I can
drag items out to the Finder, but when I let go nothing else happens, and
the -...namesOfPromisedFilesDropped... method isn't even called. Also,
[self.outlineView
setDraggingDestinationFeedbackStyle:NSTableViewDraggingDestinationFeedbackStyleRegular];
[self.outlineView setDraggingSourceOperationMask:NSDragOperationNone
forLocal:YES];
[self.outlineView setDraggingSourceOperationMask:NSDragOperationCopy
forLocal:NO];
is in my -awakeFromNib. The if (extension.length > 0) ... was based on an
example I found somewhere, but it was dated, and the documentation says to
return an extension, so I think that is appropriate. Personally, I find
the documentation for this whole area very lacking, especially in regard
to an NSOutlineView. Thanks!
Update: I changed (__bridge_transfer NSString
*)kPasteboardTypeFileURLPromise to NSFilesPromisePboardType, and I can now
drag files (with an extension at least) and they can be dropped
successfully in the Finder. (I had used the former b/c the documentation
for the latter recommended that, but they do not have the same effect.)
Directories and files without an extension still can't be dragged.
notify controller of changes to a ConcurrentLinkedQueue across threads
notify controller of changes to a ConcurrentLinkedQueue across threads
Along the lines of the Apache WeatherTelnet example, I have the following
classes:
NetBeansProjects/Telnet/src/telnet/
„¥„Ÿ„Ÿ Controller.java
„¥„Ÿ„Ÿ Printer.java
„¥„Ÿ„Ÿ PropertiesReader.java
„¥„Ÿ„Ÿ StreamReader.java
„¥„Ÿ„Ÿ StringReader.java
„¥„Ÿ„Ÿ TelnetConnection.java
„¤„Ÿ„Ÿ Telnet.java
Controller is supposed to manage communication between StreamReader,
StringReader and Printer. This is, I think, the "problem" class:
public class Controller {
private final static Logger LOG =
Logger.getLogger(Controller.class.getName());
private StringReader p = new StringReader();
public Controller() {
}
public void readParse(final InputStream inputStream) throws
SocketException, IOException {
final ConcurrentLinkedQueue<Character> clq = new
ConcurrentLinkedQueue();
final StringBuilder sb = new StringBuilder();
Printer print = new Printer();
print.print(inputStream, clq);
StreamReader sp = new StreamReader();
sp.read(clq);
}
}
because it's not receiving any messages or notifications from the objects
it should be, literally, controlling.
Printer simply prints the InputStream to the console and, most
importantly, populates the ConcurrentlyLinkedQueue. (An array queue might
have advantages, but that's immaterial to the question here.) Printer:
public class Printer {
private final static Logger LOG =
Logger.getLogger(Printer.class.getName());
public Printer() {
}
public void print(final InputStream inputStream, final
ConcurrentLinkedQueue<Character> clq) {
//final ConcurrentLinkedQueue<Character> clq = new
ConcurrentLinkedQueue();
Thread print = new Thread() {
@Override
public void run() {
out.println("print..");
try {
char ch = (char) inputStream.read();
while (255 > ch && ch >= 0) {
clq.add(ch);
out.print(ch);
ch = (char) inputStream.read();
}
} catch (IOException ex) {
out.println("cannot read inputStream:\t" + ex);
}
}
};
print.start();
}
}
StreamReader will remove the data from the ConcurrentLinkedQueue in a
seperate thread, for StringReader:
public class StreamReader {
private final static Logger LOG =
Logger.getLogger(StreamReader.class.getName());
private static final long SLEEP_MILLS = 1000; // not the best way to wait
for more input
private StringReader t = new StringReader();
public StreamReader() {
}
public void read(final ConcurrentLinkedQueue<Character> clq) throws
SocketException, IOException {
final StringBuilder sb = new StringBuilder();
Thread makeString = new Thread() {
@Override
public void run() {
out.println("makeString..");
do {
try {
do {
char ch = clq.remove();
sb.append(ch);
} while (true);
} catch (java.util.NoSuchElementException |
ClassCastException e) {
out.println("cannot remove\t\t" + e);
try {
Thread.sleep(SLEEP_MILLS); //not optimal
} catch (InterruptedException interruptedException) {
out.println("cannot sleep1\t\t" +
interruptedException);
}
} finally {
out.println("finally -- waiting for more data.." +
sb);
String cmd = t.parse(sb.toString());
sb.delete(0, sb.length());
out.println("COMMAND IS\t\t\t"+ cmd);
try {
Thread.sleep(SLEEP_MILLS);
} catch (InterruptedException interruptedException) {
out.println("cannot sleep1\t\t" +
interruptedException);
}
}
} while (true);
}
};
makeString.start();
}
}
StringReader, very basic:
class StringReader {
public String parse(String s) {
String cmd = "not a real command";
out.println("\n\n\nstarting PARSING ..\n\n\n" + s + "\n\n\n");
if (s.contains("Press Return to continue:")) {
cmd = "send newline";
}
return cmd;
}
}
Focusing on the Controller, how can I modify the this class so that, when
notified by StreamReader it sends a message to StringReader and receives
back a String command from StringReader?
I believe this is a poor-mans Netty, towards a MUD client. The difficulty
has so far been in concurrently printing and reading the InputStream over
a live telnet connection.
(Each of these threads, and any additional threads, should never block
each other. Perhaps not the ideal design, but easier for me to deal with.)
Along the lines of the Apache WeatherTelnet example, I have the following
classes:
NetBeansProjects/Telnet/src/telnet/
„¥„Ÿ„Ÿ Controller.java
„¥„Ÿ„Ÿ Printer.java
„¥„Ÿ„Ÿ PropertiesReader.java
„¥„Ÿ„Ÿ StreamReader.java
„¥„Ÿ„Ÿ StringReader.java
„¥„Ÿ„Ÿ TelnetConnection.java
„¤„Ÿ„Ÿ Telnet.java
Controller is supposed to manage communication between StreamReader,
StringReader and Printer. This is, I think, the "problem" class:
public class Controller {
private final static Logger LOG =
Logger.getLogger(Controller.class.getName());
private StringReader p = new StringReader();
public Controller() {
}
public void readParse(final InputStream inputStream) throws
SocketException, IOException {
final ConcurrentLinkedQueue<Character> clq = new
ConcurrentLinkedQueue();
final StringBuilder sb = new StringBuilder();
Printer print = new Printer();
print.print(inputStream, clq);
StreamReader sp = new StreamReader();
sp.read(clq);
}
}
because it's not receiving any messages or notifications from the objects
it should be, literally, controlling.
Printer simply prints the InputStream to the console and, most
importantly, populates the ConcurrentlyLinkedQueue. (An array queue might
have advantages, but that's immaterial to the question here.) Printer:
public class Printer {
private final static Logger LOG =
Logger.getLogger(Printer.class.getName());
public Printer() {
}
public void print(final InputStream inputStream, final
ConcurrentLinkedQueue<Character> clq) {
//final ConcurrentLinkedQueue<Character> clq = new
ConcurrentLinkedQueue();
Thread print = new Thread() {
@Override
public void run() {
out.println("print..");
try {
char ch = (char) inputStream.read();
while (255 > ch && ch >= 0) {
clq.add(ch);
out.print(ch);
ch = (char) inputStream.read();
}
} catch (IOException ex) {
out.println("cannot read inputStream:\t" + ex);
}
}
};
print.start();
}
}
StreamReader will remove the data from the ConcurrentLinkedQueue in a
seperate thread, for StringReader:
public class StreamReader {
private final static Logger LOG =
Logger.getLogger(StreamReader.class.getName());
private static final long SLEEP_MILLS = 1000; // not the best way to wait
for more input
private StringReader t = new StringReader();
public StreamReader() {
}
public void read(final ConcurrentLinkedQueue<Character> clq) throws
SocketException, IOException {
final StringBuilder sb = new StringBuilder();
Thread makeString = new Thread() {
@Override
public void run() {
out.println("makeString..");
do {
try {
do {
char ch = clq.remove();
sb.append(ch);
} while (true);
} catch (java.util.NoSuchElementException |
ClassCastException e) {
out.println("cannot remove\t\t" + e);
try {
Thread.sleep(SLEEP_MILLS); //not optimal
} catch (InterruptedException interruptedException) {
out.println("cannot sleep1\t\t" +
interruptedException);
}
} finally {
out.println("finally -- waiting for more data.." +
sb);
String cmd = t.parse(sb.toString());
sb.delete(0, sb.length());
out.println("COMMAND IS\t\t\t"+ cmd);
try {
Thread.sleep(SLEEP_MILLS);
} catch (InterruptedException interruptedException) {
out.println("cannot sleep1\t\t" +
interruptedException);
}
}
} while (true);
}
};
makeString.start();
}
}
StringReader, very basic:
class StringReader {
public String parse(String s) {
String cmd = "not a real command";
out.println("\n\n\nstarting PARSING ..\n\n\n" + s + "\n\n\n");
if (s.contains("Press Return to continue:")) {
cmd = "send newline";
}
return cmd;
}
}
Focusing on the Controller, how can I modify the this class so that, when
notified by StreamReader it sends a message to StringReader and receives
back a String command from StringReader?
I believe this is a poor-mans Netty, towards a MUD client. The difficulty
has so far been in concurrently printing and reading the InputStream over
a live telnet connection.
(Each of these threads, and any additional threads, should never block
each other. Perhaps not the ideal design, but easier for me to deal with.)
Application name changes on AWS - how to retrieve resources, which URL or method to use?
Application name changes on AWS - how to retrieve resources, which URL or
method to use?
For example:
applicationSuperName - using this local server name requests build like:
applicationSuperName/home
This web app is deployed into cloud and has:
Public DNS: ec2-23-213-211-f222.eu-west-1.compute.amazonaws.com/home
Some_elastic_IP/home - elastic ip address
mysuperdomain.com - My domain name attached to elastic IP
My resources(css, js, images) are under applicationSuperName/resources
(locally) , in cloud this folder will be resolved by using elastic IP
address or domain name, but I do no want to include either of these two
parameters into links in my app. (so it would be context independent)
So I can't use:
<link href="/applicationSuperName/resources/css/bootstrap.min.css
rel="stylesheet">
(because application name becomes purchased domain name or IP)
or I can't use:
<link href=".resources/css/bootstrap.min.css" rel="stylesheet">
(because this is request relevant with this part building on top thus the
location for any other request except for root page becomes
applicationSuperName/home/resources/css/bootstrap.min.css which is totally
incorrect)
How to make url request which would go on second level after any
application name and goes to my resources folder?
I came up solution namely using request .getServerName(), but I strongly
believe this is overkill and may has some negative impact, since I have to
call it for each request and page, or check for this variable(like in
session) if I want to use say spring:url tag(to substitute app name and do
usual style like "spring:url/resources").
Please advice if the latter is acceptable or suggest other way to resolve
resources correctly regardless of the app name.
method to use?
For example:
applicationSuperName - using this local server name requests build like:
applicationSuperName/home
This web app is deployed into cloud and has:
Public DNS: ec2-23-213-211-f222.eu-west-1.compute.amazonaws.com/home
Some_elastic_IP/home - elastic ip address
mysuperdomain.com - My domain name attached to elastic IP
My resources(css, js, images) are under applicationSuperName/resources
(locally) , in cloud this folder will be resolved by using elastic IP
address or domain name, but I do no want to include either of these two
parameters into links in my app. (so it would be context independent)
So I can't use:
<link href="/applicationSuperName/resources/css/bootstrap.min.css
rel="stylesheet">
(because application name becomes purchased domain name or IP)
or I can't use:
<link href=".resources/css/bootstrap.min.css" rel="stylesheet">
(because this is request relevant with this part building on top thus the
location for any other request except for root page becomes
applicationSuperName/home/resources/css/bootstrap.min.css which is totally
incorrect)
How to make url request which would go on second level after any
application name and goes to my resources folder?
I came up solution namely using request .getServerName(), but I strongly
believe this is overkill and may has some negative impact, since I have to
call it for each request and page, or check for this variable(like in
session) if I want to use say spring:url tag(to substitute app name and do
usual style like "spring:url/resources").
Please advice if the latter is acceptable or suggest other way to resolve
resources correctly regardless of the app name.
Subscribe to:
Comments (Atom)