Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
tef
May 30, 2004

-> some l-system crap ->
X.clone() creates a copy of the object, and you can pass it to your destructive methods.

Adbot
ADBOT LOVES YOU

tef
May 30, 2004

-> some l-system crap ->
If you are just rewriting the output of a program from xml to xml, there are other options like xpath+xsl.

Although xsl is pretty useful it can be quite awkward being declarative.

tef
May 30, 2004

-> some l-system crap ->

CRIP EATIN BREAD posted:

I'm not sure, the way this works is fairly obtuse, such as
...
obviously there can be more elements, but it's driving me nuts.

What is it meant to look like in the output? If you can paste them into a paste bin I can either knock up an xsl attempt or tell you it's impossible.

tef
May 30, 2004

-> some l-system crap ->

Treytor posted:

Would anyone know why this bit of code won't worry on a blackberry?

Edit: I'm sorry if this isn't the right thread for this, given my code is JavaScript on a webpage.

Please try the Small web dev questions thread.

tef
May 30, 2004

-> some l-system crap ->

syphon^2 posted:

I hope Javascript questions are welcome here. There's no "Javascript Megathread", and this question is very very simple, so I didn't want to start a new thread just for it.

For future reference - the web dev and the general programming questions thread might be better. JavaScript and Java really only have the name in common.

tef
May 30, 2004

-> some l-system crap ->

dancavallaro posted:

I feel like maybe I'm going about this the wrong way, so what should I be doing?

You can always run a search and replace on the files coming back from the browser,
or if it is html you can add <base href="http://www.cnn.com/"> at the top

tef
May 30, 2004

-> some l-system crap ->

dancavallaro posted:

If you know of a good library for that

If you want to look at other languages there is HTTP::Proxy in perl, and twisted does stuff for python

tef
May 30, 2004

-> some l-system crap ->
Use a flag bit.

tef
May 30, 2004

-> some l-system crap ->

Fruit Smoothies posted:

While we're on the subject of sockets; I've always prefered async non-blocking. Can someone tell me why I should do sync blocking instead? Should I?

I was under the impression that nio was the way to go for performance.

tef
May 30, 2004

-> some l-system crap ->

Kaltag posted:

The other side is an embedded system that runs a very unrobust FTP server. I only know that the last character is getting chopped because when I send "CWD /data" it returns with "Can't open directory /dat". My boss wrote the embedded FTP and perhaps he didn't anticipate the different line separators for linux and windows. I'm going to work on it some more before I walk up to him and tell him that his code is wrong.

You need to send \r\n anyway

From: http://www.faqs.org/rfcs/rfc959.html

Edit: correct citing
code:
   The File Transfer Protocol follows the specifications of the Telnet
   protocol for all communications over the control connection.  Since
   the language used for Telnet communication may be a negotiated
   option, all references in the next two sections will be to the
   "Telnet language" and the corresponding "Telnet end-of-line code".
   Currently, one may take these to mean NVT-ASCII and <CRLF>.  No other
   specifications of the Telnet protocol will be cited.

   FTP commands are "Telnet strings" terminated by the "Telnet end of
   line code".
And it sounds like the dinky ftp server is dropping the last two characters assuming they are \r\n


Edit: His code *should* try to accomodate other line endings, as per postel's law, but your code should be sending the right thing in the first place.

Never use println on a wire protocol: always use the correct line endings for the protocol, not the platforms ones.

tef fucked around with this message at 14:34 on Sep 29, 2009

tef
May 30, 2004

-> some l-system crap ->

Vandorin posted:

I keep getting an array out of bounds error, and I can't figure out why.

X is width, Y is height?

tef
May 30, 2004

-> some l-system crap ->
Any recommended json libraries or such?

tef
May 30, 2004

-> some l-system crap ->
It is called an autocomplete widget, or an autosuggest widget.

tef
May 30, 2004

-> some l-system crap ->
http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/ConcurrentHashMap.html#putIfAbsent(K, V)

if you used this instead of the null check you could avoid the race.

tef
May 30, 2004

-> some l-system crap ->

omlette-a-gogo posted:

A good habit to get into is to close all streams in a finally block:

You can also use helper methods to handle all of the boilerplate:

code:
public static void main(String args[]) {
		readLines(new File("foo.txt"), new SimpleLineReader() {
			public void read(String line) {
				System.out.println("EOF");
			}
		});
	}
Where readlines, and SimpleLineReader are in some class:

code:
	interface LineReader {
		void read(String line);
		void eof();
		void error(IOException e);
	}

	static abstract class SimpleLineReader implements LineReader {
		public abstract void read(String line);
		public void eof() {}
		public void error(IOException e) {
			throw new RuntimeException(e);
		};
	}
	static boolean readLines(File f, LineReader r) {
		BufferedReader input = null;
		try {
			input =  new BufferedReader(new FileReader(f));
			while (true) {
				String line = input.readLine();
				if (line != null) {
					r.read(line);
				} else {
					break;
				}
			}
			r.eof();
			return true;
		} catch (IOException e) {
			r.error(e);
			return false;
		} finally {
			if (input != null) {
				try {
					input.close();
				} catch (IOException ex2) {
					// Log it, or eat it.
				}
			}
		}
	}
I can't be arsed to test it, but hopefully you can see what i'm aiming at.

tef
May 30, 2004

-> some l-system crap ->
Cool, I didn't see those.

tef
May 30, 2004

-> some l-system crap ->

Riff posted:

Hi, was wondering if any of you could help me with a bit of a problem.

I've got an array of 10 ints, lets say 0000000001. I want to take that array, turn it into a normal int and increment it. Then I want to convert that back into an array. My array would then be 0000000002.

Hurp a durp a durp

Is counting really this hard? Seriously?

you call incrementArray(new int[] {0,0,0,1}, 10, 1) to add 1 to this array in base 10.

code:
int[] static incrementArray(int[] array, int base, int increment) {
  int carry = increment;
  int[] out = Arrays.copyOf(array, array.length);
  for (int i = array.length-1; carry != 0 && i >=0; i--) {
      out[i]+=carry
      if (out[i] >= base) {
        int a = out[i]%base;
        carry=(out[i]-a)/base;
        out[i]=a;
     } else {
        carry =0;
        break;
     }
  }
  if (carry > 0 {
     // oh no the array is too small and everything is broken, throw an error or wrap around ?
  } else {
    return out;
}
hurp

this is completely untested but it should work better than adding one to a number by converting it to a string.

durp


if you said 'convert it to a string' you should be ashamed of yourself.

:ugh:


pps it works for any increment >=0

tef fucked around with this message at 05:27 on Nov 5, 2010

tef
May 30, 2004

-> some l-system crap ->

Mr. DNA posted:

Can anyone give me some suggestions for good resources to learn how to program GUI apps with Java using a text editor and command line compiler? I find diving into an IDE overwhelming.

(Java) gui toolkits are a miriad of pain and suffering. I can't recommend SWT to anyone, not even the brain damaged (Another cross platform library that needs to be wrapped to be cross platform, for example: tooltips and sliders work significantly differently).

quote:

Thanks for any help!

Writing Java demands an IDE to deal with the level of complexity in modern frameworks and toolkits. Writing java in a barebones environment will drive you insane. (much, much quicker than working in eclipse will)

You might find it easier to start with something simpler and pedagogical to learn GUI programming, like Tcl/Tk, or writing a web app in one of the myriad frameworks (i'd recommend python+django fwiw).

tef
May 30, 2004

-> some l-system crap ->

Aleksei Vasiliev posted:

use an IDE like Eclipse. i handcode SWT GUIs in it. I treat it like a text editor that can compile, tell me of my errors while I'm making them, and other stuff. You don't really need to know much to use Eclipse. just do File > New > Java Project, then File > New > Class.

Also, File > Restart Eclipse.

Although I never get to use it because it just seizes up and locks.

tef
May 30, 2004

-> some l-system crap ->
Reminds me of my favourite eclipse bug: Only on windows! https://bugs.eclipse.org/bugs/show_bug.cgi?id=319514

tef
May 30, 2004

-> some l-system crap ->

epswing posted:

You probably want something more like...

An enum for difficulty, stored as an attribute somewhere it makes sense.

tef
May 30, 2004

-> some l-system crap ->
Starting with 5 is a good idea. I can't recommend any beginner java books off hand but I will say that 'Effective Java 2nd ed' is an excellent second book.

tef
May 30, 2004

-> some l-system crap ->

Aleksei Vasiliev posted:

Where can I find a good tutorial on concurrency?

I have some code that 1) takes a noticeable amount of time, and 2) should be easy to multithread (lots of tasks that don't depend on any previous computation)

But I don't know anything about concurrency and don't know where to learn it.

I think you mean 'I have a parallel problem'

concurrency is more about multi-agent stuff/actors style problems
and parallelism is more about dataflow/pipeline problems

you might try an algorithmic skeleton library to make your life easier

http://skandium.niclabs.cl/documentation/

tef
May 30, 2004

-> some l-system crap ->

Jam2 posted:

My reason for posting here is to ask, what will I be able to do by the end of this course? Will I be completely proficient in java or are there advanced concepts i still will not have touched by the end of the 8 cred course?

to be frank, there will be intermediate and beginner concepts you won't have touched.


Jam2 posted:

To me, proficiency means being able to use tools available to solve problems and write good code as a valued contributor within an engineering team. It means being able to hold your own in a work environment full of experienced programmers. It means being able to bring something to the table. This is my three to four year goal.

It still takes relatively experienced programmers a month or two, to step up and contribute heavily to a large code base. Three or four years is a relatively modest goal to be able to work as a junior programmer within a larger team.


'and be completely proficient in java, C, and python by next summer'.

this will never happen. you might be able to write hello world in each of them, but that is not a level of reasonable proficiency.


'no one here is really in a position to judge my intent/motivation/capability.'

actually of all the people qualified to judge, you are the least qualified as you are yet to acquire the skills you desire and so know little about the amount of time and dedication it takes.



If you want to be a better programmer you should spend more time *reading code* than writing it.

tef
May 30, 2004

-> some l-system crap ->
I mean how many java programmers actually understand the type of enum :v:

tef
May 30, 2004

-> some l-system crap ->

epswing posted:

To me, a couple of the key attributes of a worthwhile programmer are intelligence and curiosity, and from across the internet it seems you might have both, so keep at it and have fun.

I'd say that the following are more important:

Mastery of ones own native tongue

Being humble. Other people know more, think more and have solved problems you are yet to have. No-one likes to work with a dick, especially one who is right.


Programming is as much explaining things to people as it is explaining things to a computer.

tef
May 30, 2004

-> some l-system crap ->

epswing posted:

Sure, I'll agree that attitude is also a key attribute, but I don't necessarily think it's "more important than" intelligence or curiosity. If any of these three are lacking, you're not going to get very far.

actually no matter how smart you are or curious, if you're a dick to people, and can't write for poo poo, you won't get far. real software is written by groups, collaborating.

tef
May 30, 2004

-> some l-system crap ->

Paolomania posted:

Yeah try telling that to HR.

Here I have a note for you:

I am writing to inform you that I am ending my employment at ButtCo.

tef
May 30, 2004

-> some l-system crap ->

epswing posted:

So I'm not sure why you posted.

'more important than'


really, programming doesn't need that much intelligence or curiosity to write. you are not an artist, and most programming is glorified typing. I mean, seriously we're in the java thread here people.

you are akin to telephone operators of the turn of the century, laboriously plugging poo poo togerher and subsequently replaced when a more effective interface is found.

and as for getting far:

I know many programmers in industry who are not geniuses or curious about programming, and yet they seem happy enough making yet another skin for a database :-)


the reason I posted is that you are wrong and have a childish, romanticised view of programming as a career. hth.

tef fucked around with this message at 17:22 on Apr 10, 2011

tef
May 30, 2004

-> some l-system crap ->

epswing posted:

Sorry but you're probably one of those dicks you were talking about earlier.

Programmers are frequently arrogant jerks. I am sorry I had to spell things out to you but if you read my earlier posts before replying to them I might not have had to be so cruel :-)

Simply put the idea that a career (in java) requires intelligence & curiosity, is quite ironic, because java is designed for the mediocre tasks in programming, a simple way to write business logic without having to understand much in the way of resource management :-)


(you may also want to notice that i am yet to break out an ad-homiem, unlike yourself.)


edit: time to move goalposts

tef fucked around with this message at 17:44 on Apr 10, 2011

tef
May 30, 2004

-> some l-system crap ->

Paolomania posted:

QED

If i'm being a dick it's because I am channeling dijkstra :-)

Adbot
ADBOT LOVES YOU

tef
May 30, 2004

-> some l-system crap ->
welcome to something awful

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply