|
Thread Rules 1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution. 2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20) 3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible. 4. Use [code] tags to format code blocks. |
On May 03 2014 11:13 phar wrote:First off, don't parse what is essentially xml with a regex: http://stackoverflow.com/questions/6751105You could probably use something like JAXP. If you can guarantee that there are no nested tags you could probably do it with regex.
haha I like this post better
e: glorious excerpt: dear lord help us how can anyone survive this scourge using regex to parse HTML has doomed humanity to an eternity of dread torture and security holes using regex as a tool to process HTML establishes a breach between this world and the dread realm of c͒ͪo͛ͫrrupt entities (like SGML entities, but more corrupt) a mere glimpse of the world of regex parsers for HTML will instantly transport a programmer's consciousness into a world of ceaseless screaming, he comes, the pestilent slithy regex-infection will devour your HTML parser, application and existence for all time like Visual Basic
|
Ahhh yea that was the one I was looking for, but couldn't find it right away so I gave up and used another
|
I don't even use regex or HTML ever and I loved that post so much I remembered it forever lol
|
On May 03 2014 09:09 darkness wrote:So I had to format text recently, and give it back with no tags (and also without text/stuff inside tags), but I couldn't come up with something more than just erasing tags. Basically it's like: Text. <script> whatever text </script> More text.
The idea is to just return Text. More text.
But how is this done? Regex/Pattern matching easily comes to mind, but I don't really understand it that well. I use Java, so an example for Java would be better. String#replaceAll("\\<[^>]*>","") only clears tags.
you need to write a HTML (assumed from example) parser if you want to do it right. as others have eluded if its viewed as good enough to use regex because some assumptions are allowed and the problems are know and accepted...do that. if not you could try to use apache tika.
|
|
|
On the topic of Automata and Languages I've only read Introduction to the Theory of Computation by Michael Sipser. I quite liked it. It's the only one I've read so I can't compare it to Hopcroft et al.
|
Sipser is probably better than Hopcroft for learning, much more approachable. There's a reason it's used in much more Unis (MIT, CMU, Stanford, Hopkins, as well as big state schools like Berkely, UW, UW, UM, UM, UT, etc).
|
Hey, I'm having some problems with some Java code and I have no idea what is going on. While trying to set up an TCP/IP connection and opening objectstream, my program blocks. I've tried opening an outstream instead and that worked just fine, but for some reason getInputStream() doesn't seem to return at all. :s
I can't see what could possibly go wrong, the socket seems to be connected, it's working with outstream. Let me know if you need any additional context
This is one of the Nodes trying to setup a connection
private ServerSocket listener; private Socket socket = null; private ObjectInputStream instream;
...
listener = new ServerSocket(PORT); socket = listener.accept(); instream = new ObjectInputStream(socket.getInputStream());
This is an EventBus where I'm connecting to them. I have a List of Nodes and each of them are being contructed with a new socket:
private List<Node> nodes = new ArrayList<Node>();
for (int i = 0; i < ports.length; i++) { nodes.add(new Node(topics[i], new Socket(IPs[i], ports[i]))); }
Any help would be greatly appriciated. I've been stuck on this for a while :s
|
On May 04 2014 19:45 Vorenius wrote:Hey, I'm having some problems with some Java code and I have no idea what is going on. While trying to set up an TCP/IP connection and opening objectstream, my program blocks. I've tried opening an outstream instead and that worked just fine, but for some reason getInputStream() doesn't seem to return at all. :s I can't see what could possibly go wrong, the socket seems to be connected, it's working with outstream. Let me know if you need any additional context This is one of the Nodes trying to setup a connection private ServerSocket listener; private Socket socket = null; private ObjectInputStream instream;
...
listener = new ServerSocket(PORT); socket = listener.accept(); instream = new ObjectInputStream(socket.getInputStream());
This is an EventBus where I'm connecting to them. I have a List of Nodes and each of them are being contructed with a new socket: private List<Node> nodes = new ArrayList<Node>();
for (int i = 0; i < ports.length; i++) { nodes.add(new Node(topics[i], new Socket(IPs[i], ports[i]))); }
Any help would be greatly appriciated. I've been stuck on this for a while :s
Have you added debug to make sure you're actually getting past the accept line?
SocketServer.accept
Is the program single threaded? You haven't really given us a lot to work with to figure out what is going on...
|
On May 04 2014 20:46 berated- wrote:Show nested quote +On May 04 2014 19:45 Vorenius wrote:Hey, I'm having some problems with some Java code and I have no idea what is going on. While trying to set up an TCP/IP connection and opening objectstream, my program blocks. I've tried opening an outstream instead and that worked just fine, but for some reason getInputStream() doesn't seem to return at all. :s I can't see what could possibly go wrong, the socket seems to be connected, it's working with outstream. Let me know if you need any additional context This is one of the Nodes trying to setup a connection private ServerSocket listener; private Socket socket = null; private ObjectInputStream instream;
...
listener = new ServerSocket(PORT); socket = listener.accept(); instream = new ObjectInputStream(socket.getInputStream());
This is an EventBus where I'm connecting to them. I have a List of Nodes and each of them are being contructed with a new socket: private List<Node> nodes = new ArrayList<Node>();
for (int i = 0; i < ports.length; i++) { nodes.add(new Node(topics[i], new Socket(IPs[i], ports[i]))); }
Any help would be greatly appriciated. I've been stuck on this for a while :s Have you added debug to make sure you're actually getting past the accept line? SocketServer.acceptIs the program single threaded? You haven't really given us a lot to work with to figure out what is going on... The socket is returned properly, I tried printing the socket.toString() without problem. It's this line that blocks:
instream = new ObjectInputStream(socket.getInputStream());
The server does extend Thread, as I want to run it from another thread, but I'm testing it with just a single thread.
Here are the two appropriate classes:
TermoServer, the one that blocks: + Show Spoiler + public class TermoServer extends Thread { public static void main(String[] args) { TermoServer ts = new TermoServer(); ts.run(); }
private final int PORT = 12345; private ObjectInputStream instream; private ServerSocket listener; private Socket clientSocket = null; private List<Double> temperatures = new ArrayList<Double>(); private double averageTemperature;
public void run() {
try { getConnection(); while (true) { temperatures.add(readTemperature()); averageTemperature = calculateAverage(temperatures); System.out .println("Average temperature: " + averageTemperature); } } catch (Exception e) { System.out.println(e); } }
private void getConnection() throws IOException { listener = new ServerSocket(PORT); clientSocket = listener.accept(); instream = new ObjectInputStream(clientSocket.getInputStream());
} private double readTemperature() throws IOException, ClassNotFoundException { //something } private double calculateAverage(List<Double> marks) { //something }
}
EventBus, the one connecting to it: + Show Spoiler + public class EventBus { private int[] ports = { 23456, 12345 }; private String[] IPs = { "localhost", "localhost" }; private String[][] topics = { { "TemperatureReading" }, { "TemperatureReading" } }; private List<Node> nodes = new ArrayList<Node>();
public static void main(String[] args) { EventBus eb = new EventBus(); eb.start(); }
public void start() { try { addNodes(); System.out.println("Nodes added"); while (true) { Event e = getEvent(); for (Node n : nodes) { if (n.isSubscribingTo(e.getTopic())) n.sendEvent(e); } } } catch (Exception e) { e.printStackTrace(); }
}
private void addNodes() throws UnknownHostException, IOException { for (int i = 0; i < ports.length; i++) { nodes.add(new Node(topics[i], new Socket(IPs[i], ports[i]))); }
}
private Event getEvent() throws IOException, ClassNotFoundException { // List<ObjectInputStream> instreams = getStreams(); while (true) { for (Node n : nodes) { ObjectInputStream ois = new ObjectInputStream(n.getSocket() .getInputStream()); System.out.println("test"); if (ois.available() > 1) { System.out.println(" stream available"); Object o = ois.readObject(); if (o instanceof Event) { System.out.println("event found"); return (Event) o; } } } } }
Edit: I think I figured it out. The Node-constructor wasn't properly creating the outstreams. It's kinda working now... :/
|
Before I start doing an in depth search for a solution to this problem, does anybody have a fast algorithm for finding/estimating the square root of a number? Or any input at all really... Trying to do some microprocessor programming and it's currently the bottleneck on performance.
|
On May 05 2014 08:26 aksfjh wrote: Before I start doing an in depth search for a solution to this problem, does anybody have a fast algorithm for finding/estimating the square root of a number? Or any input at all really... Trying to do some microprocessor programming and it's currently the bottleneck on performance. My memory might be a bit fuzzy because it's been awhile since I've had to do efficient microcontroller stuff, but I believe there's a super efficient way to do this using newton-raphson. It's an iterative method that converges pretty quickly.
|
On May 05 2014 08:33 phar wrote:Show nested quote +On May 05 2014 08:26 aksfjh wrote: Before I start doing an in depth search for a solution to this problem, does anybody have a fast algorithm for finding/estimating the square root of a number? Or any input at all really... Trying to do some microprocessor programming and it's currently the bottleneck on performance. My memory might be a bit fuzzy because it's been awhile since I've had to do efficient microcontroller stuff, but I believe there's a super efficient way to do this using newton-raphson. It's an iterative method that converges pretty quickly. Definitely a good place to start, thanks!
|
On May 03 2014 23:47 MichaelEU wrote: On the topic of Automata and Languages I've only read Introduction to the Theory of Computation by Michael Sipser. I quite liked it. It's the only one I've read so I can't compare it to Hopcroft et al. I have Hopcroft. It is, shall we say, a little dense and obtuse at times. Some sections of it are quite good while others are incredibly unclear. This was the last year my professor was going to have it even mentioned (it was not a required text, just something we could use to supplement his notes. My prof's doctorate is in Automata and Language theory so he writes most of his own material and it is much better than any textbook or online resources I've found).
I absolutely loved my Automata and Languages class. I didn't get the best mark in it, but I felt like I learned far more from that class than two or three of my other classes combined. It really does help with understanding how certain aspects of Computer Science work.
I definitely will check Sipser out. I really like reading about this stuff.
|
On May 04 2014 21:13 Vorenius wrote:Show nested quote +On May 04 2014 20:46 berated- wrote:On May 04 2014 19:45 Vorenius wrote:Hey, I'm having some problems with some Java code and I have no idea what is going on. While trying to set up an TCP/IP connection and opening objectstream, my program blocks. I've tried opening an outstream instead and that worked just fine, but for some reason getInputStream() doesn't seem to return at all. :s I can't see what could possibly go wrong, the socket seems to be connected, it's working with outstream. Let me know if you need any additional context This is one of the Nodes trying to setup a connection private ServerSocket listener; private Socket socket = null; private ObjectInputStream instream;
...
listener = new ServerSocket(PORT); socket = listener.accept(); instream = new ObjectInputStream(socket.getInputStream());
This is an EventBus where I'm connecting to them. I have a List of Nodes and each of them are being contructed with a new socket: private List<Node> nodes = new ArrayList<Node>();
for (int i = 0; i < ports.length; i++) { nodes.add(new Node(topics[i], new Socket(IPs[i], ports[i]))); }
Any help would be greatly appriciated. I've been stuck on this for a while :s Have you added debug to make sure you're actually getting past the accept line? SocketServer.acceptIs the program single threaded? You haven't really given us a lot to work with to figure out what is going on... The socket is returned properly, I tried printing the socket.toString() without problem. It's this line that blocks: instream = new ObjectInputStream(socket.getInputStream()); The server does extend Thread, as I want to run it from another thread, but I'm testing it with just a single thread. Here are the two appropriate classes: TermoServer, the one that blocks: + Show Spoiler + public class TermoServer extends Thread { public static void main(String[] args) { TermoServer ts = new TermoServer(); ts.run(); }
private final int PORT = 12345; private ObjectInputStream instream; private ServerSocket listener; private Socket clientSocket = null; private List<Double> temperatures = new ArrayList<Double>(); private double averageTemperature;
public void run() {
try { getConnection(); while (true) { temperatures.add(readTemperature()); averageTemperature = calculateAverage(temperatures); System.out .println("Average temperature: " + averageTemperature); } } catch (Exception e) { System.out.println(e); } }
private void getConnection() throws IOException { listener = new ServerSocket(PORT); clientSocket = listener.accept(); instream = new ObjectInputStream(clientSocket.getInputStream());
} private double readTemperature() throws IOException, ClassNotFoundException { //something } private double calculateAverage(List<Double> marks) { //something }
}
EventBus, the one connecting to it: + Show Spoiler + public class EventBus { private int[] ports = { 23456, 12345 }; private String[] IPs = { "localhost", "localhost" }; private String[][] topics = { { "TemperatureReading" }, { "TemperatureReading" } }; private List<Node> nodes = new ArrayList<Node>();
public static void main(String[] args) { EventBus eb = new EventBus(); eb.start(); }
public void start() { try { addNodes(); System.out.println("Nodes added"); while (true) { Event e = getEvent(); for (Node n : nodes) { if (n.isSubscribingTo(e.getTopic())) n.sendEvent(e); } } } catch (Exception e) { e.printStackTrace(); }
}
private void addNodes() throws UnknownHostException, IOException { for (int i = 0; i < ports.length; i++) { nodes.add(new Node(topics[i], new Socket(IPs[i], ports[i] )); }
}
private Event getEvent() throws IOException, ClassNotFoundException { // List<ObjectInputStream> instreams = getStreams(); while (true) { for (Node n : nodes) { ObjectInputStream ois = new ObjectInputStream(n.getSocket() .getInputStream()); System.out.println("test"); if (ois.available() > 1) { System.out.println(" stream available"); Object o = ois.readObject(); if (o instanceof Event) { System.out.println("event found"); return (Event) o; } } } } }
Edit: I think I figured it out. The Node-constructor wasn't properly creating the outstreams. It's kinda working now... :/
It's kinda working?...
I would suggest you read something about how an actual multithreaded server works - that may very well clear up a few problems you have (such as testing with one thread...)
Basically check this thread out and try to play a bit with the examples, then come back with actual questions rather than "why it no work"
http://stackoverflow.com/questions/12588476/multithreading-socket-communication-client-server
|
On May 05 2014 08:26 aksfjh wrote: Before I start doing an in depth search for a solution to this problem, does anybody have a fast algorithm for finding/estimating the square root of a number? Or any input at all really... Trying to do some microprocessor programming and it's currently the bottleneck on performance.
Newton's method probably is the best method, you can iterate until you reach desired accuracy. There was also a really nice hack by Carmack to approximate roots, using bit shifts. Not very accurate, but very fast. Seems to be described well here http://www.codemaestro.com/reviews/9.
|
My eclipse is broken. It doesn't recognize if a class has been imported or not anymore and the hover-popup with methods and help etc shows only a blank window.
![[image loading]](http://i.imgur.com/7Gv0L0b.jpg) Ive already reinstalled Java and redownloaded eclipse. How can i fix this?
|
I don't know a lot about eclipse, but I think a lot of the user settings are stored in the .metadata folder in the workspace (eclipse stores a lot of stuff there at least). Switching to a new workspace may fix it, but you may lose other settings in the process. Another thing worth trying may be to clean/refresh the project if this only happens in one, but the chances of that working is like 2%.
|
On May 08 2014 02:19 DeltaX wrote: I don't know a lot about eclipse, but I think a lot of the user settings are stored in the .metadata folder in the workspace (eclipse stores a lot of stuff there at least). Switching to a new workspace may fix it, but you may lose other settings in the process. Another thing worth trying may be to clean/refresh the project if this only happens in one, but the chances of that working is like 2%.
Deleted the metadata folder and reimported all the projects. Didn't help. It also happens in all of the project. Even if i start a newly downloaded eclipse from a different folder, so im thinking this has to be caused by either windows or java somehow.
|
|
|
|
|
|
|
|